
    +                        S r SSKJr  SSKJr  SSKJr  SSK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  \R2                  " \R4                  R6                  \R4                  R8                  5       " S S\R:                  5      5       r\R2                  " \R4                  R>                  5       " S S\5      5       r g)z)Create GKE-based virtual cluster command.    )absolute_import)division)unicode_literalsN)encoding)dataproc)
exceptions)gke_helpers)arg_parsers)base)clusters)flags)gke_clusters)gke_workload_identity)GkeNodePoolTargetsParser)logc                   j    \ rS rSrSrSS0rSr\S 5       rS r	\
S 5       r\
S	 5       r\
S
 5       rSrg)Create&   z#Create a GKE-based virtual cluster.EXAMPLESau            Create a Dataproc on GKE cluster in us-central1 on a GKE cluster in
          the same project and region with default values:

            $ {command} my-cluster --region=us-central1 --gke-cluster=my-gke-cluster --spark-engine-version=latest --pools='name=dp,roles=default'

          Create a Dataproc on GKE cluster in us-central1 on a GKE cluster in
          the same project and zone us-central1-f with default values:

            $ {command} my-cluster --region=us-central1 --gke-cluster=my-gke-cluster --gke-cluster-location=us-central1-f --spark-engine-version=3.1 --pools='name=dp,roles=default'

          Create a Dataproc on GKE cluster in us-central1 with machine type
          'e2-standard-4', autoscaling 5-15 nodes per zone.

            $ {command} my-cluster --region='us-central1' --gke-cluster='projects/my-project/locations/us-central1/clusters/my-gke-cluster' --spark-engine-version=dataproc-1.5 --pools='name=dp-default,roles=default,machineType=e2-standard-4,min=5,max=15'

          Create a Dataproc on GKE cluster in us-central1 with two distinct
          node pools.

            $ {command} my-cluster --region='us-central1' --gke-cluster='my-gke-cluster' --spark-engine-version='dataproc-2.0' --pools='name=dp-default,roles=default,machineType=e2-standard-4' --pools='name=workers,roles=spark-drivers;spark-executors,machineType=n2-standard-8
          Fc           	         [         R                  " U R                  5       5      n[        R                  R                  U5        [        R                  " USUR                  5        [        R                  " USS9  UR                  SSSS9  UR                  SS	S
9  UR                  S[        R                  " 5       [        R                  0 SSS9  [        R                  " U5        UR                  SSS
9  U R                  (       a  [         R"                  " U5        O[         R$                  " U5        UR                  SSSS9  [        R&                  " U5        [        R(                  " U5        g )Ncreate35m)defaultz--spark-engine-versionTzH        The version of the Spark engine to run on this cluster.
        )requiredhelpz--staging-bucketz        The Cloud Storage bucket to use to stage job dependencies, miscellaneous
        config files, and job driver console output when using this cluster.
        )r   z--propertieszPREFIX:PROPERTY=VALUEz        Specifies configuration properties for installed packages, such as
        Spark. Properties are mapped to configuration files by specifying a
        prefix, such as "core:io.serializations".
        )typeactionr   metavarr   z--namespacez            The name of the Kubernetes namespace to deploy Dataproc system
            components in. This namespace does not need to exist.
            z--setup-workload-identity
store_truea*              Sets up the GKE Workload Identity for your Dataproc on GKE cluster.
            Note that running this requires elevated permissions as it will
            manipulate IAM policies on the Google Service Accounts that will be
            used by your Dataproc on GKE cluster.
            )r   r   )dpDataprocReleaseTrackr   
ASYNC_FLAGAddToParserr   AddClusterResourceArgapi_versionAddTimeoutFlagadd_argumentr
   ArgDictUpdateActionAddGkeClusterResourceArg_support_shuffle_servicer   AddPoolsAlphaArgAddPoolsArgAddMetastoreServiceResourceArg"AddHistoryServerClusterResourceArg)clsparserr   s      +lib/surface/dataproc/clusters/gke/create.pyArgsCreate.ArgsE   sV   {{3++-.HOO'	(2F2FG 
/
         "'''  
 
""6*
   ####F+v&
#   
((0	,,V4    c           
         [         R                  " U R                  5       5      nUR                  R                  R                  5       nUR                  R                  R                  5       nUR                  R                  R                  5       nUR                  R                  R                  5       n[        R                  X$XU5      n[        R                  U5        UR                  (       a  [        R                  XU5        UR                  R                  UUR                   UR"                  S9n[$        R&                  " UUUUR(                  UR*                  SS S9$ )N)virtualClusterConfigclusterName	projectIdF)enable_create_on_gke action_on_failed_primary_workers)r    r!   r"   CONCEPTSclusterParsegke_clustermetastore_servicehistory_server_clusterr   _GetVirtualClusterConfig*_VerifyGkeClusterIsWorkloadIdentityEnabledsetup_workload_identity_SetupWorkloadIdentitymessagesClusterr9   r:   r   CreateClusterasync_timeout)	selfargsr   cluster_refgke_cluster_refmetastore_service_refhistory_server_cluster_refvirtual_cluster_configr>   s	            r3   Run
Create.Run   s   {{4,,./H--''--/Kmm//557O MM;;AAC!%!E!E!K!K!M#<<4"$ 55oF####DG''3++'' ( )G
 !!")-/ /r6   c                    U R                   R                  [        R                  " SUR                  0U R                   R                  R
                  SS9S9nUR                  (       aC  [        R                  " UR                  U R                   R                  R                  SS9Ul        [        R                  " U UR                  5       UR                  5      nU R                   R                  UR                  5       US9nU R                   R                  UR                  UUS9nSn	U(       a'  U R                   R                  UR                  5       S9n	Sn
U(       a'  U R                   R!                  UR                  5       S	9n
SnU	(       d  U
(       a  U R                   R#                  U	U
S
9nU R                   R%                  UR&                  UUS9nU$ )a  Get dataproc virtual cluster configuration for GKE based clusters.

Args:
  dataproc: Dataproc object that contains client, messages, and resources
  gke_cluster_ref: GKE cluster reference.
  args: Arguments parsed from argparse.ArgParser.
  metastore_service_ref: Reference to a Dataproc Metastore Service.
  history_server_cluster_ref: Reference to a Dataproc history cluster.

Returns:
  virtual_cluster_config: Dataproc virtual cluster configuration
SPARKT)
sort_items)componentVersion)gkeClusterTargetnodePoolTarget)kubernetesNamespacegkeClusterConfigkubernetesSoftwareConfigN)dataprocMetastoreService)dataprocCluster)metastoreConfigsparkHistoryServerConfig)stagingBucketkubernetesClusterConfigauxiliaryServicesConfig)rG   KubernetesSoftwareConfigr   DictToAdditionalPropertyMessagespark_engine_versionComponentVersionValue
propertiesPropertiesValuer   r?   RelativeNamepoolsGkeClusterConfigKubernetesClusterConfig	namespaceMetastoreConfigSparkHistoryServerConfigAuxiliaryServicesConfigVirtualClusterConfigstaging_bucket)r   rO   rM   rP   rQ   kubernetes_software_configrl   gke_cluster_configkubernetes_cluster_configmetastore_configspark_history_server_configauxiliary_services_configrR   s                r3   rC   Create._GetVirtualClusterConfig   s   " "*!2!2!K!K!AAd//066LL "L " .6.V.V
//



4
4
D
D/ +
 %**8+:+G+G+I+/::7E "**;;(557 < O !) 1 1 I I NN+!; !J !=
 !**::#8#E#E#G ; I"&!$,$5$5$N$N4AAC %O %E! !%6"*"3"3"K"K*#> #L #@ &..CC)) 9 9 D ;
 "!r6   c                     [         R                  " U R                  U R                  U R                  S9nU(       d  [
        R                  " U 5      eg )N)projectlocationr>   )r	   &GetGkeClusterIsWorkloadIdentityEnabled
projectsIdlocationsId
clustersIdr   &GkeClusterMissingWorkloadIdentityError)rO   workload_identity_enableds     r3   rD   1Create._VerifyGkeClusterIsWorkloadIdentityEnabled   sI     + R R** ,,**!, %==oNN %r6   c                 J   S n[         R                  " 5       nU R                  R                  SU5      nUR	                  U/ 5      R                  S5        U R                  R                  SU5      nUR	                  U/ 5      R                  S5        U R                  R                  SU5      nUR	                  U/ 5      R                  S5        X4;   aW  UR                  U5      n[        R                  R                  UR                  5      n	X;   a  XI   R                  U5        OXU	'   U R                  =(       d    UR                  n
[        R                  " SXJ5        UR!                  5        H/  u  p[        R"                  R%                  UR                  UU
US9  M1     g )	Nz2dataproc:dataproc.gke.agent.google-service-accountagentz9dataproc:dataproc.gke.spark.driver.google-service-accountzspark-driverz;dataproc:dataproc.gke.spark.executor.google-service-accountzspark-executorzTSetting up Workload Identity for the following GSA to KSAs %s in the "%s" namespace.)
project_id	gsa_emailk8s_namespacek8s_service_accounts)collectionsOrderedDictri   get
setdefaultappendpopr   &DefaultDataprocDataPlaneServiceAccountGetr   extendro   r9   r   debugitemsGkeWorkloadIdentityUpdateGsaIamPolicy)rM   rN   rO   default_gsa_sentinelgsa_to_ksas	agent_gsaspark_driver_gsaspark_executor_gsaksasdefault_gsar   gsas               r3   rF   Create._SetupWorkloadIdentity   s   ))+K##<I 9b)009**C +R077G,,E -r299:JK*__12d

F
F
J
J((*  
	# ''-#'K NN=k&=&=MII^$ !&&(	//BB$//%#	 C % )r6    N)__name__
__module____qualname____firstlineno____doc__detailed_helpr,   classmethodr4   rS   staticmethodrC   rD   rF   __static_attributes__r   r6   r3   r   r   &   su    + -2 #85 85t/< <" <"| O O $% $%r6   r   c                   0    \ rS rSrSr\R                  rSrg)CreateAlphai  Tr   N)r   r   r   r   r,   r   r   r   r   r6   r3   r   r     s    !NN'r6   r   )!r   
__future__r   r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.dataprocr   r    r   r	   googlecloudsdk.callioper
   r   #googlecloudsdk.command_lib.dataprocr   r   r   r   0googlecloudsdk.command_lib.dataproc.gke_clustersr   googlecloudsdk.corer   ReleaseTracksr"   GABETACreateCommandr   ALPHAr   r   r6   r3   <module>r      s    0 &  '  % : 6 7 / ( 8 5 < E U # D%%(($*;*;*@*@Ad%T d% Bd%N D%%++,&  -r6   