
    ~$                        d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ddlm	Z
 ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl m!Z! ddl"Z"dZ# ejH                  ejJ                  jL                  ejJ                  jN                        ejP                   G d dejR                                      Z*y)zCommand to register an Attached cluster with the fleet.

This command performs the full end-to-end steps required to attach a cluster.
    )absolute_import)division)unicode_literalsN)attached)	locations)base)cluster_util)flags)resource_args)	kube_util)command_util)	constants)endpoint_util)errors)
exceptions)pretty_print)
console_io)retryaD  
Register a cluster to a fleet.

To register a cluster with a private OIDC issuer, run:

$ {command} my-cluster --location=us-west1 --platform-version=PLATFORM_VERSION --fleet-project=FLEET_PROJECT_NUM --distribution=DISTRIBUTION --context=CLUSTER_CONTEXT --has-private-issuer

To register a cluster with a public OIDC issuer, run:

$ {command} my-cluster --location=us-west1 --platform-version=PLATFORM_VERSION --fleet-project=FLEET_PROJECT_NUM --distribution=DISTRIBUTION --context=CLUSTER_CONTEXT --issuer-url=https://ISSUER_URL

To specify a kubeconfig file, run:

$ {command} my-cluster --location=us-west1 --platform-version=PLATFORM_VERSION --fleet-project=FLEET_PROJECT_NUM --distribution=DISTRIBUTION --context=CLUSTER_CONTEXT --has-private-issuer --kubeconfig=KUBECONFIG_PATH

To register and set cluster admin users, run:

$ {command} my-cluster --location=us-west1 --platform-version=PLATFORM_VERSION --fleet-project=FLEET_PROJECT_NUM --distribution=DISTRIBUTION --context=CLUSTER_CONTEXT --issuer-url=https://ISSUER_URL --admin-users=USER1,USER2

To specify custom tolerations and labels for system component pods, run:

$ {command} my-cluster --location=us-west1 --platform-version=PLATFORM_VERSION --fleet-project=FLEET_PROJECT_NUM --distribution=DISTRIBUTION --context=CLUSTER_CONTEXT --system-component-tolerations=TOLERATIONS --system-component-labels=LABELS

where TOLERATIONS have the format:
  key=value:Effect:NoSchedule (examples: key1=value1:Equal:NoSchedule,key2:Exists:PreferNoSchedule, :Exists:NoExecute)
and LABELS have the format:
  key=value (examples: key1=value1,key2="")
c                   F    e Zd ZdZdeiZed        Zd Zd Z	d Z
d Zd Zy	)
RegisterzRegister an Attached cluster.EXAMPLESc                    t        j                  | d       t        j                  |        t        j                  |        t        j
                  | d       t        j                  |        t        j                  |        t        j                  |        t        j                  |        t        j                  |        t        j                  |        t        j                  |        t        j                  | d       t        j                  |        t        j                   |        t        j"                  | d       t        j$                  | dd       t        j&                  |        t        j(                  |        t        j*                  |        t        j,                  |        | j.                  j1                  t2        j4                         y)z!Registers flags for this command.zto registerT)requiredzcluster to createN)r   AddAttachedClusterResourceArgattached_flagsAddPlatformVersionAddRegisterOidcConfigAddDistributionAddAdminUsers
AddKubectlAddProxyConfigAddSkipClusterAdminCheckAddSystemComponentTolerationsAddSystemComponentLabelsr
   AddAnnotationsAddValidateOnlyAddFleetProjectAddDescription
AddLoggingAddMonitoringConfigAddBinauthzEvaluationModeAddAdminGroups AddWorkloadVulnerabilityScanningAddTagBindingsdisplay_info	AddFormatr   ATTACHED_CLUSTERS_FORMAT)parsers    3lib/surface/container/attached/clusters/register.pyArgszRegister.ArgsR   sC    //F%%f-((0""6D9  (f%!!&)++F3008++F3	 	&"56	&!	 	VT"	fdD1	##F+	 	**62	 
!!)"D"DE    c           	      b   t        j                  |      j                  }t        j                  |      r-t        j
                  |      dk(  rt        j                  d      t        j                  |       t        j                  |      5  t        j                  |      }| j                  ||      }t        j                  t        j                  |      t        j                  |      d      5 }t        j                   |      s|j#                          t        j                  |      rCt%        j&                  d       | j)                  |      \  }}t+        |d|       t+        |d|       	 t-        j.                  |      s{t%        j&                  d       |j1                  |       t3        j4                  t6        j8                  	      }|j;                  t<        j>                  |ft6        j@                  
       | jC                  ||      }	| jG                  |||       d d d        	cd d d        S # t2        jD                  $ r^}
| jG                  |||       |
jH                  d   r6tK        jL                  |
jH                  d   d   |
jH                  d   d           d }
~
wtN        jP                  $ rG djS                  |t        jT                  |      |jV                        }t%        j&                  |         | jG                  |||        xY w# 1 sw Y   xY w# 1 sw Y   y xY w)NekszEDistributions of type "eks" cannot use the `has-private-issuer` flag.T)
kubeconfigcontextenable_workload_identityz!Fetching cluster OIDC information
issuer_url	oidc_jwksz!Creating in-cluster install agent)max_retrials)argssleep_ms      zTo manually clean up the in-cluster install agent, run:

$ gcloud container attached clusters generate-install-manifest --location={} --platform-version={} --format="value(manifest)"  {}  | kubectl delete -f -

AFTER the attach operation completes.
),r   ParseAttachedClusterResourceArglocationsIdr   GetHasPrivateIssuerGetDistributionrun_exceptionsArgumentErrorGetSystemComponentTolerationsr   GkemulticloudEndpointOverride_get_manifestr   KubernetesClientGetKubeconfig
GetContextGetSkipClusterAdminCheckCheckClusterAdminPermissionsr   Info_get_authoritysetattrr
   GetValidateOnlyApplyr   Retryerr   %ATTACHED_INSTALL_AGENT_VERIFY_RETRIESRetryOnExceptionr	   verify_install_agent_deployed%ATTACHED_INSTALL_AGENT_VERIFY_WAIT_MS_create_attached_clusterRetryException_remove_manifestlast_resultr   reraiser   OperationCancelledErrorformatGetPlatformVersionattachedClustersId)selfr>   locationcluster_refmanifestkube_clientr;   jwksretryercreate_respemsgs               r3   RunzRegister.Runn   s   <<TBNNH**40**40E9(( 
 006		4	4X	>!AA$Gk##D+6h%%#11$7 ++D1#' 66t<

2
2
4--d3


?
@!00=
*d
$j
1
$T
*&	&&t,ABh'mm&LLG $$::!^"HH %  55dKH+6 	dK:mp y 
?	>@ ## 	


k8
<
 ]]1q}}Q/2AMM!4DQ4GH
11 	
 F//5,,  

C
 
	


k8
<
i 	 
?	>sM   A&L%2A>L1B"H9L&	L%9LAJ%%A1LLL"	L%%L.c                 h    t        j                         }|j                  ||      }|j                  S )N)r>   )loc_utilLocationsClientGenerateInstallManifestrf   )rc   r>   re   location_clientresps        r3   rJ   zRegister._get_manifest   s/    ..0O22;T2JD==r5   c                 |    t        j                  |      s't        j                  d       |j	                  |       y y )Nz!Deleting in-cluster install agent)r
   rS   r   rP   Delete)rc   r>   rg   rf   s       r3   r\   zRegister._remove_manifest   s2      &;<" 'r5   c                     t        j                  |j                         d      }t        j                  |      j                  d      }|st        j                  |      |j                         }||fS )Nzutf-8)encodingissuer)	six
ensure_strGetOpenIDConfigurationjsonloadsgetr   MissingOIDCIssuerURLGetOpenIDKeyset)rc   rg   openid_config_jsonr;   rh   s        r3   rQ   zRegister._get_authority   si    **,w ./33H=J''(:;;&&(Dtr5   c                     t        j                         }t        j                  |j                  dt
        j                        }t        j                  ||||t
        j                        S )NCreating)actionkind)resource_refresource_clientr>   messager   )	api_utilClustersClientr   ClusterMessagerb   r   ATTACHEDCreateATTACHED_CLUSTER_KIND)rc   r>   re   cluster_clientr   s        r3   rZ   z!Register._create_attached_cluster   s_    ,,.N))&&G
  &,, r5   N)__name__
__module____qualname____doc__	_EXAMPLESdetailed_helpstaticmethodr4   rm   rJ   r\   rQ   rZ    r5   r3   r   r   K   s@     &y)-F F6HT
#
r5   r   )+r   
__future__r   r   r   r|   .googlecloudsdk.api_lib.container.gkemulticloudr   r   r   ro   googlecloudsdk.callioper   -googlecloudsdk.command_lib.container.attachedr	   r
   r   r   *googlecloudsdk.command_lib.container.fleetr   2googlecloudsdk.command_lib.container.gkemulticloudr   r   r   r   googlecloudsdk.command_lib.runr   rF   r   googlecloudsdk.coregooglecloudsdk.core.consoler   googlecloudsdk.core.utilr   ry   r   ReleaseTracksReleaseTrackALPHAGADefaultUniverseOnlyCreateCommandr   r   r5   r3   <module>r      s    '  '  O P ( F Q G @ K H L E D G 7 * 2 * 
	< D%%++T->->-A-ABLt!! L  CLr5   