{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.EKS.UpdateClusterVersion
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Updates an Amazon EKS cluster to the specified Kubernetes version. Your
-- cluster continues to function during the update. The response output
-- includes an update ID that you can use to track the status of your
-- cluster update with the DescribeUpdate API operation.
--
-- Cluster updates are asynchronous, and they should finish within a few
-- minutes. During an update, the cluster status moves to @UPDATING@ (this
-- status transition is eventually consistent). When the update is complete
-- (either @Failed@ or @Successful@), the cluster status moves to @Active@.
--
-- If your cluster has managed node groups attached to it, all of your node
-- groups’ Kubernetes versions must match the cluster’s Kubernetes version
-- in order to update the cluster to a new Kubernetes version.
module Amazonka.EKS.UpdateClusterVersion
  ( -- * Creating a Request
    UpdateClusterVersion (..),
    newUpdateClusterVersion,

    -- * Request Lenses
    updateClusterVersion_clientRequestToken,
    updateClusterVersion_name,
    updateClusterVersion_version,

    -- * Destructuring the Response
    UpdateClusterVersionResponse (..),
    newUpdateClusterVersionResponse,

    -- * Response Lenses
    updateClusterVersionResponse_update,
    updateClusterVersionResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import Amazonka.EKS.Types
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newUpdateClusterVersion' smart constructor.
data UpdateClusterVersion = UpdateClusterVersion'
  { -- | Unique, case-sensitive identifier that you provide to ensure the
    -- idempotency of the request.
    UpdateClusterVersion -> Maybe Text
clientRequestToken :: Prelude.Maybe Prelude.Text,
    -- | The name of the Amazon EKS cluster to update.
    UpdateClusterVersion -> Text
name :: Prelude.Text,
    -- | The desired Kubernetes version following a successful update.
    UpdateClusterVersion -> Text
version :: Prelude.Text
  }
  deriving (UpdateClusterVersion -> UpdateClusterVersion -> Bool
(UpdateClusterVersion -> UpdateClusterVersion -> Bool)
-> (UpdateClusterVersion -> UpdateClusterVersion -> Bool)
-> Eq UpdateClusterVersion
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateClusterVersion -> UpdateClusterVersion -> Bool
$c/= :: UpdateClusterVersion -> UpdateClusterVersion -> Bool
== :: UpdateClusterVersion -> UpdateClusterVersion -> Bool
$c== :: UpdateClusterVersion -> UpdateClusterVersion -> Bool
Prelude.Eq, ReadPrec [UpdateClusterVersion]
ReadPrec UpdateClusterVersion
Int -> ReadS UpdateClusterVersion
ReadS [UpdateClusterVersion]
(Int -> ReadS UpdateClusterVersion)
-> ReadS [UpdateClusterVersion]
-> ReadPrec UpdateClusterVersion
-> ReadPrec [UpdateClusterVersion]
-> Read UpdateClusterVersion
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateClusterVersion]
$creadListPrec :: ReadPrec [UpdateClusterVersion]
readPrec :: ReadPrec UpdateClusterVersion
$creadPrec :: ReadPrec UpdateClusterVersion
readList :: ReadS [UpdateClusterVersion]
$creadList :: ReadS [UpdateClusterVersion]
readsPrec :: Int -> ReadS UpdateClusterVersion
$creadsPrec :: Int -> ReadS UpdateClusterVersion
Prelude.Read, Int -> UpdateClusterVersion -> ShowS
[UpdateClusterVersion] -> ShowS
UpdateClusterVersion -> String
(Int -> UpdateClusterVersion -> ShowS)
-> (UpdateClusterVersion -> String)
-> ([UpdateClusterVersion] -> ShowS)
-> Show UpdateClusterVersion
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateClusterVersion] -> ShowS
$cshowList :: [UpdateClusterVersion] -> ShowS
show :: UpdateClusterVersion -> String
$cshow :: UpdateClusterVersion -> String
showsPrec :: Int -> UpdateClusterVersion -> ShowS
$cshowsPrec :: Int -> UpdateClusterVersion -> ShowS
Prelude.Show, (forall x. UpdateClusterVersion -> Rep UpdateClusterVersion x)
-> (forall x. Rep UpdateClusterVersion x -> UpdateClusterVersion)
-> Generic UpdateClusterVersion
forall x. Rep UpdateClusterVersion x -> UpdateClusterVersion
forall x. UpdateClusterVersion -> Rep UpdateClusterVersion x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdateClusterVersion x -> UpdateClusterVersion
$cfrom :: forall x. UpdateClusterVersion -> Rep UpdateClusterVersion x
Prelude.Generic)

-- |
-- Create a value of 'UpdateClusterVersion' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'clientRequestToken', 'updateClusterVersion_clientRequestToken' - Unique, case-sensitive identifier that you provide to ensure the
-- idempotency of the request.
--
-- 'name', 'updateClusterVersion_name' - The name of the Amazon EKS cluster to update.
--
-- 'version', 'updateClusterVersion_version' - The desired Kubernetes version following a successful update.
newUpdateClusterVersion ::
  -- | 'name'
  Prelude.Text ->
  -- | 'version'
  Prelude.Text ->
  UpdateClusterVersion
newUpdateClusterVersion :: Text -> Text -> UpdateClusterVersion
newUpdateClusterVersion Text
pName_ Text
pVersion_ =
  UpdateClusterVersion' :: Maybe Text -> Text -> Text -> UpdateClusterVersion
UpdateClusterVersion'
    { $sel:clientRequestToken:UpdateClusterVersion' :: Maybe Text
clientRequestToken =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:name:UpdateClusterVersion' :: Text
name = Text
pName_,
      $sel:version:UpdateClusterVersion' :: Text
version = Text
pVersion_
    }

-- | Unique, case-sensitive identifier that you provide to ensure the
-- idempotency of the request.
updateClusterVersion_clientRequestToken :: Lens.Lens' UpdateClusterVersion (Prelude.Maybe Prelude.Text)
updateClusterVersion_clientRequestToken :: (Maybe Text -> f (Maybe Text))
-> UpdateClusterVersion -> f UpdateClusterVersion
updateClusterVersion_clientRequestToken = (UpdateClusterVersion -> Maybe Text)
-> (UpdateClusterVersion -> Maybe Text -> UpdateClusterVersion)
-> Lens
     UpdateClusterVersion UpdateClusterVersion (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateClusterVersion' {Maybe Text
clientRequestToken :: Maybe Text
$sel:clientRequestToken:UpdateClusterVersion' :: UpdateClusterVersion -> Maybe Text
clientRequestToken} -> Maybe Text
clientRequestToken) (\s :: UpdateClusterVersion
s@UpdateClusterVersion' {} Maybe Text
a -> UpdateClusterVersion
s {$sel:clientRequestToken:UpdateClusterVersion' :: Maybe Text
clientRequestToken = Maybe Text
a} :: UpdateClusterVersion)

-- | The name of the Amazon EKS cluster to update.
updateClusterVersion_name :: Lens.Lens' UpdateClusterVersion Prelude.Text
updateClusterVersion_name :: (Text -> f Text) -> UpdateClusterVersion -> f UpdateClusterVersion
updateClusterVersion_name = (UpdateClusterVersion -> Text)
-> (UpdateClusterVersion -> Text -> UpdateClusterVersion)
-> Lens UpdateClusterVersion UpdateClusterVersion Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateClusterVersion' {Text
name :: Text
$sel:name:UpdateClusterVersion' :: UpdateClusterVersion -> Text
name} -> Text
name) (\s :: UpdateClusterVersion
s@UpdateClusterVersion' {} Text
a -> UpdateClusterVersion
s {$sel:name:UpdateClusterVersion' :: Text
name = Text
a} :: UpdateClusterVersion)

-- | The desired Kubernetes version following a successful update.
updateClusterVersion_version :: Lens.Lens' UpdateClusterVersion Prelude.Text
updateClusterVersion_version :: (Text -> f Text) -> UpdateClusterVersion -> f UpdateClusterVersion
updateClusterVersion_version = (UpdateClusterVersion -> Text)
-> (UpdateClusterVersion -> Text -> UpdateClusterVersion)
-> Lens UpdateClusterVersion UpdateClusterVersion Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateClusterVersion' {Text
version :: Text
$sel:version:UpdateClusterVersion' :: UpdateClusterVersion -> Text
version} -> Text
version) (\s :: UpdateClusterVersion
s@UpdateClusterVersion' {} Text
a -> UpdateClusterVersion
s {$sel:version:UpdateClusterVersion' :: Text
version = Text
a} :: UpdateClusterVersion)

instance Core.AWSRequest UpdateClusterVersion where
  type
    AWSResponse UpdateClusterVersion =
      UpdateClusterVersionResponse
  request :: UpdateClusterVersion -> Request UpdateClusterVersion
request = Service -> UpdateClusterVersion -> Request UpdateClusterVersion
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy UpdateClusterVersion
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse UpdateClusterVersion)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse UpdateClusterVersion))
-> Logger
-> Service
-> Proxy UpdateClusterVersion
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse UpdateClusterVersion)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Update -> Int -> UpdateClusterVersionResponse
UpdateClusterVersionResponse'
            (Maybe Update -> Int -> UpdateClusterVersionResponse)
-> Either String (Maybe Update)
-> Either String (Int -> UpdateClusterVersionResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Update)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"update")
            Either String (Int -> UpdateClusterVersionResponse)
-> Either String Int -> Either String UpdateClusterVersionResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable UpdateClusterVersion

instance Prelude.NFData UpdateClusterVersion

instance Core.ToHeaders UpdateClusterVersion where
  toHeaders :: UpdateClusterVersion -> ResponseHeaders
toHeaders =
    ResponseHeaders -> UpdateClusterVersion -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON UpdateClusterVersion where
  toJSON :: UpdateClusterVersion -> Value
toJSON UpdateClusterVersion' {Maybe Text
Text
version :: Text
name :: Text
clientRequestToken :: Maybe Text
$sel:version:UpdateClusterVersion' :: UpdateClusterVersion -> Text
$sel:name:UpdateClusterVersion' :: UpdateClusterVersion -> Text
$sel:clientRequestToken:UpdateClusterVersion' :: UpdateClusterVersion -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"clientRequestToken" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
clientRequestToken,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"version" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
version)
          ]
      )

instance Core.ToPath UpdateClusterVersion where
  toPath :: UpdateClusterVersion -> ByteString
toPath UpdateClusterVersion' {Maybe Text
Text
version :: Text
name :: Text
clientRequestToken :: Maybe Text
$sel:version:UpdateClusterVersion' :: UpdateClusterVersion -> Text
$sel:name:UpdateClusterVersion' :: UpdateClusterVersion -> Text
$sel:clientRequestToken:UpdateClusterVersion' :: UpdateClusterVersion -> Maybe Text
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/clusters/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
name, ByteString
"/updates"]

instance Core.ToQuery UpdateClusterVersion where
  toQuery :: UpdateClusterVersion -> QueryString
toQuery = QueryString -> UpdateClusterVersion -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newUpdateClusterVersionResponse' smart constructor.
data UpdateClusterVersionResponse = UpdateClusterVersionResponse'
  { -- | The full description of the specified update
    UpdateClusterVersionResponse -> Maybe Update
update :: Prelude.Maybe Update,
    -- | The response's http status code.
    UpdateClusterVersionResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (UpdateClusterVersionResponse
-> UpdateClusterVersionResponse -> Bool
(UpdateClusterVersionResponse
 -> UpdateClusterVersionResponse -> Bool)
-> (UpdateClusterVersionResponse
    -> UpdateClusterVersionResponse -> Bool)
-> Eq UpdateClusterVersionResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdateClusterVersionResponse
-> UpdateClusterVersionResponse -> Bool
$c/= :: UpdateClusterVersionResponse
-> UpdateClusterVersionResponse -> Bool
== :: UpdateClusterVersionResponse
-> UpdateClusterVersionResponse -> Bool
$c== :: UpdateClusterVersionResponse
-> UpdateClusterVersionResponse -> Bool
Prelude.Eq, ReadPrec [UpdateClusterVersionResponse]
ReadPrec UpdateClusterVersionResponse
Int -> ReadS UpdateClusterVersionResponse
ReadS [UpdateClusterVersionResponse]
(Int -> ReadS UpdateClusterVersionResponse)
-> ReadS [UpdateClusterVersionResponse]
-> ReadPrec UpdateClusterVersionResponse
-> ReadPrec [UpdateClusterVersionResponse]
-> Read UpdateClusterVersionResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [UpdateClusterVersionResponse]
$creadListPrec :: ReadPrec [UpdateClusterVersionResponse]
readPrec :: ReadPrec UpdateClusterVersionResponse
$creadPrec :: ReadPrec UpdateClusterVersionResponse
readList :: ReadS [UpdateClusterVersionResponse]
$creadList :: ReadS [UpdateClusterVersionResponse]
readsPrec :: Int -> ReadS UpdateClusterVersionResponse
$creadsPrec :: Int -> ReadS UpdateClusterVersionResponse
Prelude.Read, Int -> UpdateClusterVersionResponse -> ShowS
[UpdateClusterVersionResponse] -> ShowS
UpdateClusterVersionResponse -> String
(Int -> UpdateClusterVersionResponse -> ShowS)
-> (UpdateClusterVersionResponse -> String)
-> ([UpdateClusterVersionResponse] -> ShowS)
-> Show UpdateClusterVersionResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdateClusterVersionResponse] -> ShowS
$cshowList :: [UpdateClusterVersionResponse] -> ShowS
show :: UpdateClusterVersionResponse -> String
$cshow :: UpdateClusterVersionResponse -> String
showsPrec :: Int -> UpdateClusterVersionResponse -> ShowS
$cshowsPrec :: Int -> UpdateClusterVersionResponse -> ShowS
Prelude.Show, (forall x.
 UpdateClusterVersionResponse -> Rep UpdateClusterVersionResponse x)
-> (forall x.
    Rep UpdateClusterVersionResponse x -> UpdateClusterVersionResponse)
-> Generic UpdateClusterVersionResponse
forall x.
Rep UpdateClusterVersionResponse x -> UpdateClusterVersionResponse
forall x.
UpdateClusterVersionResponse -> Rep UpdateClusterVersionResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep UpdateClusterVersionResponse x -> UpdateClusterVersionResponse
$cfrom :: forall x.
UpdateClusterVersionResponse -> Rep UpdateClusterVersionResponse x
Prelude.Generic)

-- |
-- Create a value of 'UpdateClusterVersionResponse' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'update', 'updateClusterVersionResponse_update' - The full description of the specified update
--
-- 'httpStatus', 'updateClusterVersionResponse_httpStatus' - The response's http status code.
newUpdateClusterVersionResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  UpdateClusterVersionResponse
newUpdateClusterVersionResponse :: Int -> UpdateClusterVersionResponse
newUpdateClusterVersionResponse Int
pHttpStatus_ =
  UpdateClusterVersionResponse' :: Maybe Update -> Int -> UpdateClusterVersionResponse
UpdateClusterVersionResponse'
    { $sel:update:UpdateClusterVersionResponse' :: Maybe Update
update =
        Maybe Update
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:UpdateClusterVersionResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The full description of the specified update
updateClusterVersionResponse_update :: Lens.Lens' UpdateClusterVersionResponse (Prelude.Maybe Update)
updateClusterVersionResponse_update :: (Maybe Update -> f (Maybe Update))
-> UpdateClusterVersionResponse -> f UpdateClusterVersionResponse
updateClusterVersionResponse_update = (UpdateClusterVersionResponse -> Maybe Update)
-> (UpdateClusterVersionResponse
    -> Maybe Update -> UpdateClusterVersionResponse)
-> Lens
     UpdateClusterVersionResponse
     UpdateClusterVersionResponse
     (Maybe Update)
     (Maybe Update)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateClusterVersionResponse' {Maybe Update
update :: Maybe Update
$sel:update:UpdateClusterVersionResponse' :: UpdateClusterVersionResponse -> Maybe Update
update} -> Maybe Update
update) (\s :: UpdateClusterVersionResponse
s@UpdateClusterVersionResponse' {} Maybe Update
a -> UpdateClusterVersionResponse
s {$sel:update:UpdateClusterVersionResponse' :: Maybe Update
update = Maybe Update
a} :: UpdateClusterVersionResponse)

-- | The response's http status code.
updateClusterVersionResponse_httpStatus :: Lens.Lens' UpdateClusterVersionResponse Prelude.Int
updateClusterVersionResponse_httpStatus :: (Int -> f Int)
-> UpdateClusterVersionResponse -> f UpdateClusterVersionResponse
updateClusterVersionResponse_httpStatus = (UpdateClusterVersionResponse -> Int)
-> (UpdateClusterVersionResponse
    -> Int -> UpdateClusterVersionResponse)
-> Lens
     UpdateClusterVersionResponse UpdateClusterVersionResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\UpdateClusterVersionResponse' {Int
httpStatus :: Int
$sel:httpStatus:UpdateClusterVersionResponse' :: UpdateClusterVersionResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: UpdateClusterVersionResponse
s@UpdateClusterVersionResponse' {} Int
a -> UpdateClusterVersionResponse
s {$sel:httpStatus:UpdateClusterVersionResponse' :: Int
httpStatus = Int
a} :: UpdateClusterVersionResponse)

instance Prelude.NFData UpdateClusterVersionResponse