
    ?                         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r " S S\R$                  5      rS rS rS rg)zAThe command to deploy or update the Cloud Run for Anthos feature.    )absolute_import)division)unicode_literals)base)	kube_util)util)
exceptions)log)yaml)filesz    To apply the CloudRun YAML file, run:

      $ {command} --kubeconfig=/path/to/kubeconfig  --config=/path/to/cloud-run-cr.yaml
c                   :    \ rS rSrSrS\0rSr\S 5       r	S r
Srg)	Apply&   zDeploy or update the CloudRun feature.

Deploy or update a user-specified config file of the CloudRun custom resource.
The config file should be a YAML file.
EXAMPLESappdevexperiencec                 \    [         R                  " U 5        U R                  S[        SSS9  g )Nz--configz1The path to CloudRun custom resource config file.F)typehelprequired)hub_utilAddClusterConnectionCommonArgsadd_argumentstr)parsers    -lib/surface/container/fleet/cloudrun/apply.pyArgs
Apply.Args1   s/    ++F3
@	      c                    [         R                  " [        USS 5      [        USS 5      [        USS 5      [        USS 5      [        USS 5      [        USS5      S9n[         R                  " X!5        UR                  b   [
        R                  " UR                  5      O	[        5       n[        U5        [        X#5        [        R                  R                  S	5        g )
Ngke_urigke_cluster
kubeconfigcontextpublic_issuer_urlenable_workload_identityF)r    r!   r"   r#   r$   r%   zAdded CloudRun CR)r   KubernetesClientgetattrValidateClusterIdentifierFlagsconfigr   ReadFileContents_default_cr_validate_cr_apply_cr_to_membership_clusterr
   statusPrint)selfargskube_clientyaml_strings       r   Run	Apply.Run;   s    ,,i.D-64t4i.!$(;TB!(/I)."0K ,,[? / ((5@]  #K=JJ()r    N)__name__
__module____qualname____firstlineno____doc__r   detailed_helpfeature_namestaticmethodr   r4   __static_attributes__r6   r   r   r   r   &   s/     x(-#, *r   r   c                     U R                  U5      u  p#U(       a%  [        R                  " SR                  U5      5      eg)zApply the CloudRun custom resource to the cluster.

Args:
  kube_client: A Kubernetes client.
  yaml_string: the CloudRun YAML file.
z'Failed to apply manifest to cluster: {}N)r   r	   Errorformat)r2   r3   _errs       r   r-   r-   Q   s?     [)&!


188=? ? 	r   c                 z    [         R                  " U 5      n[        U[        5      (       d  [        R                  " S5      eSU;  a  [        R                  " S5      eUS   S:w  a  [        R                  " S5      eSU;  a  [        R                  " S	5      eUS   S
:w  a  [        R                  " S5      eSU;  a  UR                  S5      eUS   nSU;  d	  US   S:w  a  [        R                  " S5      eg! [         R                   a+  n[        R                  " SR	                  U 5      U5      eSnAff = f)zVValidate the parsed cloudrun YAML.

Args:
  yaml_string: The YAML string to validate.
zInvalid cloudrun yaml {}NzInvalid CloudRun template.
apiVersionz6The resource is missing a required field "apiVersion".z&operator.run.cloud.google.com/v1alpha1zThe resource "apiVersion" field must be set to: "operator.run.cloud.google.com/v1alpha1". If you believe the apiVersion is correct, you may need to upgrade your gcloud installation.kindz0The resource is missing a required field "kind".CloudRunz5The resource "kind" field must be set to: "CloudRun".metadataz4The resource is missing a required field "metadata".namez	cloud-runz=The resource "metadata.name" field must be set to "cloud-run")r   loadrA   r	   rB   
isinstancedict)r3   cloudrun_crerI   s       r   r,   r,   ^   sV   N))K(K 
K	&	&


7
88$


@B B"JJ


 	@  ;


M
NNJ&


?A A {"


>@ @ $(H 0K ?


GI I !@3 
 N


5<<[I1
MMNs   C; ;D:&D55D:c                      g)Nzi
  apiVersion: operator.run.cloud.google.com/v1alpha1
  kind: CloudRun
  metadata:
    name: cloud-run
  r6   r6   r   r   r+   r+      s    
r   N)r;   
__future__r   r   r   googlecloudsdk.callioper   *googlecloudsdk.command_lib.container.fleetr   r   r   googlecloudsdk.corer	   r
   r   googlecloudsdk.core.utilr   r   CreateCommandr   r-   r,   r+   r6   r   r   <module>rW      sT    H &  ' ( @ G * # $ *(*D (*V
?$INr   