
    +                     l   S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r
  SSK	Jr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr   " S S\5      r " S S\5      rS rS rS r\R:                  \R<                  " \R>                  R@                  5       " S S\RB                  5      5       5       r"SSS.\"l#        \R<                  " \R>                  RH                  5       " S S\"5      5       r%\R<                  " \R>                  RL                  5       " S S\"5      5       r'g) zUpgrade cluster command.    )
exceptions)api_adapter)util)base)container_command_util)flags)log)
properties)console_attr)
console_io)iso_duration)times)SemVerc                   (    \ rS rSrSrSrSrSrSrSr	g)	UpgradeHelpText#   z%Upgrade available help text messages.z8
* - There is an upgrade available for your cluster(s).
zZ
** - The current version of your cluster(s) will soon be out of support, please upgrade.
zN
*** - The current version of your cluster(s) is unsupported, please upgrade.
zc
To upgrade nodes to the latest available version, run
  $ gcloud container clusters upgrade {name} N)
__name__
__module____qualname____firstlineno____doc__UPGRADE_AVAILABLESUPPORT_ENDINGUNSUPPORTEDUPGRADE_COMMAND__static_attributes__r       )lib/surface/container/clusters/upgrade.pyr   r   #   s"    -.+0/r   r   c                   .    \ rS rSrSrSrSrSrSrS r	Sr
g	)
VersionVerifier6   zACompares the cluster and master versions for upgrade availablity.r            c                     X:X  a  U R                   $ [        U5      n[        U5      nUR                  U5      u  pVnUS:w  d  US:  a  U R                  $ US:  a  U R                  $ U R
                  $ )z=Compares the cluster and master versions and returns an enum.r   r$   r#   )
UP_TO_DATEr   Distancer   r   r   )selfcurrent_master_versioncurrent_cluster_versionmaster_versioncluster_versionmajorminor_s           r   CompareVersionVerifier.Compare=   st    8__23N45O$--o>OE!zUQY	   ###r   r   N)r   r   r   r   r   r'   r   r   r   r1   r   r   r   r   r!   r!   6   s    I*.+$r   r!   c           
      `   [         R                  " U R                  U R                  U R                  (       + U R                  U R
                  U R                  U R                  S9nU R                  (       a7  [        R                  " [        R                  " U R                  S95      Ul        U$ )z;Parses the flags provided with the cluster upgrade command.)versionupdate_masterupdate_nodes	node_pool
image_typeimageimage_project)seconds)r   UpdateClusterOptionsr-   masterr7   r8   r9   r:   control_plane_soak_durationr   FormatDurationForJsonr   Duration)argsoptss     r   ParseUpgradeOptionsBaserC   L   s    		)	)""KKOJJ&&
$ 
%%','B'Bd&F&FG(D$ 
+r   c                 n   U R                  SSSS9  [        R                  " U SS9  U R                  SSS9  U R                  S	S
SS9  U R                  S[        SSSS9  [        R                  " U 5        [        R
                  " U S5        [        R                  " U SS9  [        R                  " U SS9  g)zRegister flags for this command.

Args:
  parser: An argparse.ArgumentParser-like object. It is mocked out in order to
    capture some information, but behaves like an ArgumentParser.
nameNAMEz#The name of the cluster to upgrade.)metavarhelpa  The GKE release version to which to upgrade the cluster's node pools or master.

If desired cluster version is omitted, *node pool* upgrades default to the current
*master* version and *master* upgrades default to the default cluster version,
which can be found in the server config.

You can find the list of allowed versions for upgrades by running:

  $ gcloud container get-server-config
)rH   z--node-poolzThe node pool to upgrade.z--masterz\Upgrade the cluster's master. Node pools cannot be upgraded at the  same time as the master.
store_true)rH   actionz	--timeouti  Tz;Timeout (seconds) for waiting on the operation to complete.)typedefaulthiddenrH   zcluster/node poolrM   N)add_argumentr   AddClusterVersionFlagintAddAsyncFlagAddImageTypeFlagAddImageFlagAddImageProjectFlagparsers    r   _ArgsrX   ^   s     	f#H  J
 	m*EF&    	H  J V!45VD)F40r   c                     U b%  [        U R                  5      nU[        S5      :  a  g[        R                  R	                  S5        g)z0Logs deprecation warning for GKE v1.22 upgrades.Nz1.22.0-gke.0aB  Upcoming breaking change: Starting with v1.22, Kubernetes has removed several v1beta1 APIs for more stable v1 APIs. Read more about this change - https://cloud.google.com/kubernetes-engine/docs/deprecations/apis-1-22. Please ensure that your cluster is not using any deprecated v1beta1 APIs prior to upgrading to GKE 1.22.)r   currentMasterVersionr	   statusPrint)clustercmvs     r   MaybeLog122UpgradeWarningr_      s?    
--
.C
f^$$**-.r   c                   4    \ rS rSrSr\S 5       rS rS rSr	g)Upgrade   @Upgrade the Kubernetes version of an existing container cluster.c                 D    [        U 5        [        R                  " U SS9  g )NTrN   rX   r   AddControlPlaneSoakDurationFlagrV   s    r   ArgsUpgrade.Args   s    	&M	))&>r   c                     [        U5      $ N)rC   )r)   rA   s     r   ParseUpgradeOptionsUpgrade.ParseUpgradeOptions   s    "4((r   c                    U R                   S   nU R                   S   nU" U5      nUR                  UR                  U5      n[        R                  R
                  R                  R                  SS9n UR                  U5      n UR)                  Xd5      n	UR*                  (       a(  UR,                  (       d  [        R.                  " SS	5      e[0        R2                  " UR                  U	UUR,                  UR*                  UR4                  UR6                  UR8                  S
9n
UR,                  (       a  [;        U5        [<        R>                  " U
SSS9  U RA                  U5      n URC                  X[5      nURH                  (       d  URK                  USR#                  URL                  5      URN                  S9   UR                  U5      nURP                   H  n[        RR                  " U5        M     [        RV                  " U5        gg! [        R                  [        R                  [        R                  4 aF  n[        R                   " SR#                  [$        R&                  " U5      5      5        Sn SnAGNSnAff = f! [        R                  [        R                  [        R                  4 aF  n[        R                   " SR#                  [$        R&                  " U5      5      5        Sn	 SnAGNmSnAff = f! [        RD                   a*  n[        R                  " U[        RF                  5      eSnAff = f! [        R                  [        R                  [        R                  4 aR  n[        R                   " [        RT                  R#                  [$        R&                  " U5      5      5         SnAGNSnAff = f)zThis is what gets called when the user runs this command.

Args:
  args: an argparse namespace. All the arguments that were provided to this
    command invocation.

Returns:
  Some value that we want to have printed later.
r   location_getT)requiredzbProblem loading details of cluster to upgrade:

{}

You can still attempt to upgrade the cluster.
NzRProblem loading server config:

{}

You can still attempt to upgrade the cluster.
z--control-plane-soak-durationzA--control-plane-soak-duration can only be specified with --master)rE   server_confr]   r=   r>   node_pool_namenew_versionnew_image_type)messagethrow_if_unattendedcancel_on_nozUpgrading {0})	timeout_s),contextParseClusterrE   r
   VALUEScoreprojectGet
GetClusterr   HttpExceptionapitools_exceptionsHttpForbiddenErrorr   Errorr	   warningformatr   SafeTextGetServerConfigr>   r=   InvalidArgumentExceptionr   ClusterUpgradeMessager7   r-   r8   r_   r   PromptContinuerk   UpdateCluster	HttpErrorHTTP_ERROR_FORMATasync_WaitForOperation	clusterIdtimeout	nodePoolsCheckForCgroupModeV1CGROUPV1_CHECKING_FAILURE_MSGUpdatedResource)r)   rA   adapterrn   locationcluster_ref
project_idr]   errorrp   upgrade_messageoptionsop_refr7   s                 r   RunUpgrade.Run   s"    ll=)G<</LD!H&&tyy(;K""''//33T3BJ"";/g++JAk ''//
)
MO O -BBYY{{$($D$D~~(((O {{(TN &&t,GD$$[:f ;;


 
 !6!6
7LL  "


$$[1 **I

#
#I
. + 
+&# Y $$&9&L&LJJ 	kk EFLf#,,U3G56 g $$&9&L&LJJ 	kk EFLf#,,U3G56 k@ (( D$$UD,B,BCCD &&(;(N(Njj 
..55%%e,	
 	

sa   5H J ,L :M 3J;J		J3L
;LL
M!%MM3OAOOr   N)
r   r   r   r   r   staticmethodrg   rk   r   r   r   r   r   ra   ra      s%     I? ?)O'r   ra   a        Upgrades the Kubernetes version of an existing container cluster.

      This command upgrades the Kubernetes version of the *node pools* or *master* of
      a cluster. Note that the Kubernetes version of the cluster's *master* is
      also periodically upgraded automatically as new releases are available.

      If desired cluster version is omitted, *node pool* upgrades default to the
      current *master* version and *master* upgrades default to the default
      cluster version, which can be found in the server config.

      *During node pool upgrades, nodes will be deleted and recreated.* While
      persistent Kubernetes resources, such as
      Pods backed by replication controllers, will be rescheduled onto new
      nodes, a small cluster may experience a few minutes where there are
      insufficient nodes available to run all of the scheduled Kubernetes
      resources.

      *Please ensure that any data you wish to keep is stored on a persistent*
      *disk before upgrading the cluster.* Ephemeral Kubernetes resources--in
      particular, Pods without replication controllers--will be lost, while
      persistent Kubernetes resources will get rescheduled.
    a        Upgrade the node pool `pool-1` of `sample-cluster` to the Kubernetes
      version of the cluster's master.

        $ {command} sample-cluster --node-pool=pool-1

      Upgrade the node pool `pool-1` of `sample-cluster` to Kubernetes version
      1.14.7-gke.14:

        $ {command} sample-cluster --node-pool=pool-1 --cluster-version="1.14.7-gke.14"

      Upgrade the master of `sample-cluster` to the default cluster version:

        $ {command} sample-cluster --master
)DESCRIPTIONEXAMPLESc                   (    \ rS rSrSr\S 5       rSrg)UpgradeBetai%  rc   c                 D    [        U 5        [        R                  " U SS9  g NFrN   re   rV   s    r   rg   UpgradeBeta.Args)  s    	&M	))&?r   r   N)r   r   r   r   r   r   rg   r   r   r   r   r   r   %  s    H@ @r   r   c                   .    \ rS rSrSr\S 5       rS rSrg)UpgradeAlphai/  rc   c                 p    [        U 5        [        R                  " U SS9  [        R                  " U 5        g r   )rX   r   rf   !AddSecurityProfileForUpgradeFlagsrV   s    r   rg   UpgradeAlpha.Args3  s'    	&M	))&?	++F3r   c                 `    [        U5      nUR                  Ul        UR                  Ul        U$ rj   )rC   security_profilesecurity_profile_runtime_rules)r)   rA   opss      r   rk    UpgradeAlpha.ParseUpgradeOptions9  s-    
!$
'C00C)-)L)LC&Jr   r   N)	r   r   r   r   r   r   rg   rk   r   r   r   r   r   r   /  s    H4 4
r   r   N)(r   apitools.base.pyr   r    googlecloudsdk.api_lib.containerr   r   googlecloudsdk.callioper   $googlecloudsdk.command_lib.containerr   r   googlecloudsdk.corer	   r
   googlecloudsdk.core.consoler   r   googlecloudsdk.core.utilr   r   googlecloudsdk.core.util.semverr   objectr   r!   rC   rX   r_   DefaultUniverseOnlyReleaseTracksReleaseTrackGACommandra   detailed_helpBETAr   ALPHAr   r   r   r   <module>r      s"    ? 8 1 ( . G 6 # * 4 2 1 * 20f 0&$f $,$)1X.  D%%(()Z'dll Z' * Z'~	0	5) X D%%**+@' @ ,@ D%%++,7  -r   