
    ?                         d 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Z G d dej$                        Zd Zd Zd Zy)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                   2    e Zd ZdZdeiZdZed        Zd Z	y)ApplyzDeploy 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                 `    t        j                  |        | j                  dt        dd       y )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Argsz
Apply.Args1   s/    ++F3
@	      c                    t        j                  t        |dd       t        |dd       t        |dd       t        |dd       t        |dd       t        |dd            }t        j                  ||       |j                  t        j                  |j                        n	t               }t        |       t        ||       t        j                  j                  d	       y )
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   Runz	Apply.Run;   s    ,,i.D-64t4i.!$(;TB!(/I)."0K ,,[$? / ((5@]  #K=JJ()r   N)
__name__
__module____qualname____doc__r   detailed_helpfeature_namestaticmethodr   r2    r   r   r   r   &   s/     x(-#, *r   r   c                 x    | j                  |      \  }}|r$t        j                  dj                  |            y)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)r0   r1   _errs       r   r+   r+   Q   sA     [)&!S


188=? ? 	r   c                 H   	 t        j                  |       }t        |t              st        j                  d      d|vrt        j                  d      |d   dk7  rt        j                  d      d|vrt        j                  d	      |d   d
k7  rt        j                  d      d|vr|j                  d      |d   }d|vs|d   dk7  rt        j                  d      y# t         j                  $ r*}t        j                  dj	                  |       |      d}~ww xY w)z\Validate 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   loadr<   r	   r=   
isinstancedict)r1   cloudrun_crerD   s       r   r*   r*   ^   sS   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!7%DD!c                       y)Nzi
  apiVersion: operator.run.cloud.google.com/v1alpha1
  kind: CloudRun
  metadata:
    name: cloud-run
  r:   r:   r   r   r)   r)      s    
r   N)r6   
__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)   r:   r   r   <module>rR      sT    H &  ' ( @ G * # $ *(*D (*V
?$INr   