{-# 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-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- 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 qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.EKS.Types
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
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]
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
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. 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'
    { $sel:clientRequestToken:UpdateClusterVersion' :: Maybe Text
clientRequestToken =
        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 :: Lens' UpdateClusterVersion (Maybe Text)
updateClusterVersion_clientRequestToken = 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 :: Lens' UpdateClusterVersion Text
updateClusterVersion_name = 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 :: Lens' UpdateClusterVersion Text
updateClusterVersion_version = 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 :: (Service -> Service)
-> UpdateClusterVersion -> Request UpdateClusterVersion
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy UpdateClusterVersion
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse UpdateClusterVersion)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Update -> Int -> UpdateClusterVersionResponse
UpdateClusterVersionResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"update")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable UpdateClusterVersion where
  hashWithSalt :: Int -> UpdateClusterVersion -> Int
hashWithSalt Int
_salt 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
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
clientRequestToken
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
version

instance Prelude.NFData UpdateClusterVersion where
  rnf :: UpdateClusterVersion -> ()
rnf 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
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
clientRequestToken
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
name
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
version

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

instance Data.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
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"clientRequestToken" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=)
              forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
clientRequestToken,
            forall a. a -> Maybe a
Prelude.Just (Key
"version" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
version)
          ]
      )

instance Data.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
..} =
    forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ByteString
"/clusters/", forall a. ToByteString a => a -> ByteString
Data.toBS Text
name, ByteString
"/updates"]

instance Data.ToQuery UpdateClusterVersion where
  toQuery :: UpdateClusterVersion -> QueryString
toQuery = forall a b. a -> b -> a
Prelude.const 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
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]
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
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.
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'
    { $sel:update:UpdateClusterVersionResponse' :: Maybe Update
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 :: Lens' UpdateClusterVersionResponse (Maybe Update)
updateClusterVersionResponse_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 :: Lens' UpdateClusterVersionResponse Int
updateClusterVersionResponse_httpStatus = 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 where
  rnf :: UpdateClusterVersionResponse -> ()
rnf UpdateClusterVersionResponse' {Int
Maybe Update
httpStatus :: Int
update :: Maybe Update
$sel:httpStatus:UpdateClusterVersionResponse' :: UpdateClusterVersionResponse -> Int
$sel:update:UpdateClusterVersionResponse' :: UpdateClusterVersionResponse -> Maybe Update
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Update
update
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus