
    +                      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ZddlZddl	Z	ddl
mZmZmZmZmZ ddlZddlZddlZddlZddlZdd	lmZ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, G d d e,jZ                  ej\                  e/            Z0 G d de0      Z1 G d de0      Z2 ejf                  d        G d! d"e2             Z4d# Z5d$ Z6 ejf                  d        G d% d&e0             Z7 G d' d(e2      Z8 ejf                  d        G d) d*e1             Z9 ejf                  d        G d+ d,e1             Z: ejf                  d        G d- d.e1             Z; ejf                  dd/0       G d1 d2e7             Z< ejf                  d        G d3 d4e1             Z= ejf                  d        G d5 d6e1             Z> ejf                  d        G d7 d8e2             Z? ejf                  d        G d9 d:e2             Z@ ejf                  d        G d; d<e2             ZA ejf                  d        G d= d>e2             ZB ejf                  d        G d? d@eA             ZC ejf                  d        G dA dBe1             ZD ejf                  d        G dC dDe1             ZE ejf                  d        G dE dFe1             ZF ejf                  d        G dG dHe1             ZG ejf                  d        G dI dJe0             ZH ejf                  d        G dK dLe2             ZI ejf                  d        G dM dNe2             ZJ G dO dPe2      ZK ejf                  d/dQ       G dR dSe4             ZL	 	 	 	 	 	 ddTZM	 	 	 	 	 	 	 	 ddUZNdV ZO ejf                  d        G dW dXe4             ZP ejf                  d        G dY dZe2             ZQ G d[ d\e2      ZR ejf                  d        G d] d^e4             ZS	 	 	 	 	 	 dd_ZT ejf                  d        G d` dae4             ZU ejf                  d        G db dce4             ZV ejf                  d        G dd dee4             ZW ejf                  d        G df dge2             ZX ejf                  d        G dh die2             ZY ejf                  d        G dj dke2             ZZ ejf                  d        G dl dme2             Z[dnZ\ ejf                  d        G do dpe2             Z]dq Z^dr Z_ds Z` ejf                  d        G dt due2             Za G dv dwe2      Zb G dx dye1      Zc ejf                  d        G dz d{e1             Zd ejf                  d        G d| d}e1             Ze ejf                  d/dQ       G d~ de4             Zf ejf                  d/dQ       G d de4             ZgdZhdZi ejf                  d        G d de4             Zj ejf                  d        G d de2             Zk ejf                  d        G d de2             Zl ejf                  d        G d de2             Zm ejf                  d        G d de2             Zn ejf                  d        G d de2             Zo ejf                  d        G d de2             Zp ejf                  d        G d de1             Zq ejf                  d        G d de1             Zr ejf                  d        G d de2             Zs ejf                  d        G d de2             Zt ejf                  d        G d de2             Zu ejf                  d        G d de2             Zv ejf                  d        G d de2             Zw ejf                  d        G d de2             Zx ejf                  d        G d de2             Zy ejf                  d        G d de2             Zz ejf                  d        G d de2             Z{ ejf                  d        G d de2             Z| ejf                  d        G d de4             Z} ejf                  d        G d de4             Z~ ejf                  d        G d de2             Z ejf                  d        G d de2             Z ejf                  d        G d de2             Zy)z:Class for representing various changes to a Configuration.    )absolute_import)annotations)division)print_function)unicode_literalsN)
Collection	ContainerIterableMappingMutableMapping)AnyClassVar)container_resource)job)
k8s_object)revision)service)worker_pool)base)
exceptions)name_generator)	platforms)secrets_mapping)volumes)labels_util)repeated)run_v1_messagesc                  b    e Zd ZdZeej                  d               Zej                  d        Zy)ConfigChangerz5An abstract class representing configuration changes.c                     y)z:Returns True if any template-level changes should be made.N selfs    4lib/googlecloudsdk/command_lib/run/config_changes.pyadjusts_templatezConfigChanger.adjusts_template7           c                     y)zAdjust the given Service configuration.

    Args:
      resource: the k8s_object to adjust.

    Returns:
      A k8s_object that reflects applying the requested update.
      May be resource after a mutation or a different object.
    Nr!   r#   resources     r$   AdjustzConfigChanger.Adjust<   r&   r'   N)	__name__
__module____qualname____doc__propertyabcabstractmethodr%   r+   r!   r'   r$   r   r   4   sA    =E  E 	 	r'   r   c                       e Zd ZdZed        Zy)NonTemplateConfigChangerzBAn abstract class representing non-template configuration changes.c                     y)NFr!   r"   s    r$   r%   z)NonTemplateConfigChanger.adjusts_templateL   s    r'   Nr,   r-   r.   r/   r0   r%   r!   r'   r$   r4   r4   I   s    J r'   r4   c                       e Zd ZdZed        Zy)TemplateConfigChangerz>An abstract class representing template configuration changes.c                     y)NTr!   r"   s    r$   r%   z&TemplateConfigChanger.adjusts_templateT   s    r'   Nr6   r!   r'   r$   r8   r8   Q   s    F r'   r8   T)frozenc                  V    e Zd ZU dZdZded<   ej                  	 	 	 	 dd       ZddZ	y)	ContainerConfigChangerzAn abstract class representing container configuration changes.

  Attributes:
    container_name: Name of the container to modify. If None the primary
      container is modified.
  N
str | Nonecontainer_namec                     y)zMutate the given container.

    This method is called by this class's Adjust method and should apply the
    desired changes directly to container.

    Args:
      container: the container to adjust.
      messages_mod: Run v1 messages module.
    Nr!   r#   	containermessages_mods      r$   AdjustContainerz&ContainerConfigChanger.AdjustContainerd   r&   r'   c                    | j                   $|j                  j                  | j                      }n|j                  j                  }| j	                  ||j                                |S )a(  Returns a modified resource.

    Adjusts resource by applying changes to the container specified by
    self.container_name if present or the primary container otherwise. Calls
    AdjustContainer to apply changes to the selected container.

    Args:
      resource: The resoure to modify.
    )r>   template
containersrA   rC   MessagesModuler#   r*   rA   s      r$   r+   zContainerConfigChanger.Adjustt   s[     &##..t/B/BCi##--iH$;$;$=>Or'   )rA   zcontainer_resource.ContainerrB   types.ModuleType)r*   z$container_resource.ContainerResource)
r,   r-   r.   r/   r>   __annotations__r1   r2   rC   r+   r!   r'   r$   r<   r<   Y   sB      $.*#- % r'   r<   c                6    |D ]  }|j                  |       }  | S )zApply ConfigChangers to resource.

  It's undefined whether the input resource is modified.

  Args:
    resource: KubernetesObject, probably a Service.
    changes: List of ConfigChangers.

  Returns:
    Changed resource.
  )r+   )r*   changesconfig_changes      r$   WithChangesrN      s#     m##H-H 	/r'   c                R    t        | D cg c]  }|j                   c}      S c c}w )z3Returns True if there's any template-level changes.)anyr%   )rL   cs     r$   AdjustsTemplaterR      s%    	'2'Qa  '2	332s   $c                  p    e Zd ZU dZ eej                  g      Zded<   ded<   dZ	ded<   e
d	        Zd
 Zy)LabelChangeszRepresents the user intent to modify metadata labels.

  Attributes:
    diff: Label diff to apply.
    copy_to_revision: A boolean indicating that label changes should be copied
      to the resource's template.
  zClassVar[frozenset[str]]_LABELS_NOT_ALLOWED_IN_REVISIONzlabels_util.DiffdiffTboolcopy_to_revisionc                    | j                   S N)rX   r"   s    r$   r%   zLabelChanges.adjusts_template   s       r'   c                   | j                   j                  t        j                  |j	                               j
                  |j                  j                        }|j                         }|r||j                  _        t        |d      r|j                  n|j                  }| j                  rt        |d      r|j                  j                  t        j                        }t!        j"                  |      |j                  _        | j$                  D ]  }||j                  v s|j                  |=   |r||j                  t        j                  <   |S )Nexecution_templatelabels)rV   Applyr   MetarG   LabelsValuemetadatar]   	GetOrNonehasattrr\   rE   rX   getr   NONCE_LABELcopydeepcopyrU   )r#   r*   update_resultmaybe_new_labelsrE   noncelabel_to_removes          r$   r+   zLabelChanges.Adjust   s    IIOO//12>>  M %..0!1h
 X34 
%
%   
 
		78X#> ##H$8$89#'==1A#B #CCO/0  D 27(//(..
/Or'   N)r,   r-   r.   r/   	frozensetr   ENDPOINT_VISIBILITYrU   rJ   rX   r0   r%   r+   r!   r'   r$   rT   rT      sS     ?H""#?!#;  	D! !r'   rT   c                      e Zd ZdZd Zy)JobNonceChangez@Adds a new nonce to the job template, for forcing an image pull.c                ~    t        j                  dd      |j                  j                  t        j
                  <   |S )N   _)	separator)r   GenerateNamer\   r]   r   re   r)   s     r$   r+   zJobNonceChange.Adjust   s3    ##A5 &&s7 Or'   Nr,   r-   r.   r/   r+   r!   r'   r$   ro   ro      s
    Hr'   ro   c                  "    e Zd ZU dZded<   d Zy)ReplaceJobChangezyRepresents the user intent to replace the job.

  Attributes:
    new_job: New job that will replace the existing job.
  zjob.Jobnew_jobc                    |j                   j                  r/|j                   j                  | j                  j                   _        | j                  S )a  Returns a replacement for resource.

    The returned job is the job provided to the constructor. If
    resource.metadata.resourceVersion is not empty, has metadata.resourceVersion
    of returned job set to this value.

    Args:
      resource: job.Job, The job to adjust.
    )ra   resourceVersionrx   r)   s     r$   r+   zReplaceJobChange.Adjust   s;     ((.6.?.?.O.Odll+<<r'   Nr,   r-   r.   r/   rJ   r+   r!   r'   r$   rw   rw      s     r'   rw   c                  "    e Zd ZU dZded<   d Zy)ReplaceServiceChangezRepresents the user intent to replace the service.

  Attributes:
    new_service: New service that will replace the existing service.
  zservice.Servicenew_servicec                Z   |j                   j                  r|j                   j                  | j                  j                   _        |j                  j	                         D ]>  \  }}|j                  t        j                        s&|| j                  j                  |<   @ | j                  S )a0  Returns a replacement for resource.

    The returned service is the service provided to the constructor. If
    resource.metadata.resourceVersion is not empty, has metadata.resourceVersion
    of returned service set to this value.

    Args:
      resource: service.Service, The service to adjust.
    )ra   rz   r~   r   items
startswithr   SERVING_GROUP)r#   r*   kvs       r$   r+   zReplaceServiceChange.Adjust   s     ((



+
+ /
 &&,,.$!Q<<
001,-$


&
&q
) / r'   Nr{   r!   r'   r$   r}   r}      s     r'   r}   c                  "    e Zd ZU dZded<   d Zy)ReplaceWorkerPoolChangezRepresents the user intent to replace the worker pool.

  Attributes:
    new_worker_pool: New worker pool that will replace the existing worker pool.
  zworker_pool.WorkerPoolnew_worker_poolc                    |j                   j                  r/|j                   j                  | j                  j                   _        | j                  S )aG  Returns a replacement for resource.

    The returned worker pool is the worker pool provided to the constructor. If
    resource.metadata.resourceVersion is not empty, has metadata.resourceVersion
    of returned worker pool set to this value.

    Args:
      resource: worker_pool.WorkerPool, The worker pool to adjust.
    )ra   rz   r   r)   s     r$   r+   zReplaceWorkerPoolChange.Adjust  sD     ((



+
+ ##3 r'   Nr{   r!   r'   r$   r   r     s     *) r'   r   F)r:   initc                  .     e Zd ZU dZded<    fdZ xZS )EndpointVisibilityChangeziRepresents the user intent to modify the endpoint visibility.

  Only applies to Cloud Run for Anthos.
  zdataclasses.InitVar[bool]endpoint_visibilityc                    |r5t        j                  t        j                  t        j                  i      }n%t        j                  t        j                  g      }t
        |   |d       y)zDetermine label changes for modifying endpoint visibility.

    Args:
      endpoint_visibility: bool, True if Cloud Run on GKE service should only be
        addressable from within the cluster. False if it should be publicly
        addressable.
    )	additions)subtractionsFN)r   Diffr   rm   CLUSTER_LOCALsuper__init__)r#   r   rV   	__class__s      r$   r   z!EndpointVisibilityChange.__init__9  sX     00'2G2GHd G,G,G+HId 
GT5!r'   )r,   r-   r.   r/   rJ   r   __classcell__r   s   @r$   r   r   0  s    
 10" "r'   r   c                  ,    e Zd ZU dZded<   ded<   d Zy)SetAnnotationChangezRepresents the user intent to set an annotation.

  Attributes:
    key: Annotation to set.
    value: Annotation value to set.
  strkeyvaluec                L    | j                   |j                  | j                  <   |S rZ   )r   r   r   r)   s     r$   r+   zSetAnnotationChange.AdjustX  s    %)ZZH"Or'   Nr{   r!   r'   r$   r   r   L       (	*r'   r   c                  "    e Zd ZU dZded<   d Zy)DeleteAnnotationChangezdRepresents the user intent to delete an annotation.

  Attributes:
    key: Annotation to delete.
  r   r   c                T    |j                   }| j                  |v r|| j                  = |S rZ   )r   r   r#   r*   r   s      r$   r+   zDeleteAnnotationChange.Adjustg  s*    &&Kxx;
dhh
Or'   Nr{   r!   r'   r$   r   r   ]       (r'   r   c                  ,    e Zd ZU dZded<   ded<   d Zy)SetTemplateAnnotationChangezRepresents the user intent to set a template annotation.

  Attributes:
    key: Template annotation to set.
    value: Annotation value to set.
  r   r   r   c                `    | j                   |j                  j                  | j                  <   |S rZ   )r   rE   r   r   r)   s     r$   r+   z"SetTemplateAnnotationChange.Adjustz  s%    .2jjH!!$((+Or'   Nr{   r!   r'   r$   r   r   n  r   r'   r   c                  "    e Zd ZU dZded<   d Zy)DeleteTemplateAnnotationChangezuRepresents the user intent to delete a template annotation.

  Attributes:
    key: Template annotation to delete.
  r   r   c                h    |j                   j                  }| j                  |v r|| j                  = |S rZ   )rE   r   r   r   s      r$   r+   z%DeleteTemplateAnnotationChange.Adjust  s0    ##//Kxx;
dhh
Or'   Nr{   r!   r'   r$   r   r     r   r'   r   c                      e Zd ZU dZ ej
                  e      Zded<    ej
                  e	      Z
ded<   	 	 	 	 	 	 	 	 ddZ	 	 	 	 ddZdd	Zy
)BaseImagesAnnotationChangea  Represents the user intent to update the 'base-images' template annotation.

  The value of the annotation is a string representation of a json map of
  container_name -> base_image_url. E.g.: '{"mycontainer":"my_base_image_url"}'.

  Attributes:
    updates: {container:url} map of values that need to be added/updated
    deletes: List of containers whose base image url needs to be deleted.
  default_factorydict[str, str]updates	list[str]deletesc                    |r|D ]
  }||v s||=  |r|j                         D ]
  \  }}|||<    | j                  ||      S rZ   )r   _constructBaseImageUrls)r#   r*   existing_base_image_urlsr   r   rA   urls          r$   _mergeBaseImageUrlsz.BaseImagesAnnotationChange._mergeBaseImageUrls  sZ     )00&y1  #MMO.)S.1 + ,''2JKKr'   c                    t        |j                  j                  j                         D cg c]  }|xs d
 c}      dj	                  fd|j                         D              }|rd|z   dz   S dS c c}w )N z, c              3  @   K   | ]  \  }}|v sd | d| d   yw)"z":"Nr!   ).0r   r   rF   s      r$   	<genexpr>zEBaseImagesAnnotationChange._constructBaseImageUrls.<locals>.<genexpr>  s/       /;esj?P!C5E7!|s   {})rl   rE   rF   keysjoinr   )r#   r*   urlsxbase_images_strrF   s        @r$   r   z2BaseImagesAnnotationChange._constructBaseImageUrls  s     "++66;;=>=Qb=>J ii  /3zz|  O +:3 3&ArA 	?s   A5c                   |j                   j                  } |j                  t        j                  d      }|r>t        j                  |      }| j                  ||| j                  | j                        }n| j                  || j                        }|rR||j                   j                  t        j                  <   t        j                  |j                   j                  _        |S t        j                  |v rq|j                   j                  t        j                  = |j                   j                  j                  t        j                  k(  rd|j                   j                  _        |S z9Updates the revision to use automatic base image updates.r   )rE   r   rd   r   BASE_IMAGES_ANNOTATIONjsonloadsr   r   r   r   $BASE_IMAGE_UPDATE_RUNTIME_CLASS_NAMEspecruntimeClassName)r#   r*   r   existing_valuer   	new_values         r$   r+   z!BaseImagesAnnotationChange.Adjust  s$    ##//K$[__X%D%DbIN!%N!;**
,dllDLLi ..xFiGPh##H$C$CD

7
7 - O 
	(	(K	7



'
'(G(G
H



 
 
1
1::; 35/Or'   N)r*   revision.Revisionr   r   r   r   r   r   r*   r   r   r   r*   r   )r,   r-   r.   r/   dataclassesfielddictr   rJ   listr   r   r   r+   r!   r'   r$   r   r     s     .K--dC'>C({((>'9>L!L !/L 	L
 L"	B'	B/=	Br'   r   c                      e Zd ZU dZ ej
                  e      Zded<    ej
                  e	      Z
ded<   	 	 	 	 	 	 	 	 ddZ	 	 	 	 ddZdd	Zy
)SourcesAnnotationChangea|  Represents the user intent to update the 'sources' template annotation.

  The value of the annotation is a string representation of a json map of
  container_name -> GCS objects. E.g.: '{"foo":"gs://my-bucket/my-object"}'.

  Attributes:
    updates: {container:url} map of values that need to be added/updated
    deletes: List of containers whose source needs to be deleted.
  r   r   r   r   r   c                    |r|D ]
  }||v s||=  |r|j                         D ]
  \  }}|||<    | j                  ||      S rZ   )r   _constructSources)r#   r*   existing_sourcesr   r   rA   r   s          r$   _mergeSourcesz%SourcesAnnotationChange._mergeSources  sZ     )((y)  #MMO.)S&)# ,!!(,<==r'   c                   t        |j                  j                  j                         D cg c]  }|xs d
 c}      }t	        j
                  |j                         D ci c]  \  }}||v s|| c}}d      S c c}w c c}}w )Nr   ),:)
separators)rl   rE   rF   r   r   dumpsr   )r#   r*   r   r   rF   ys         r$   r   z)SourcesAnnotationChange._constructSources  s     "++66;;=>=Qb=>J ::**,:,$!Q!z/A,:  	? 	;s   A>"B
/B
c                   |j                   j                  } |j                  t        j                  d      }|r>t        j                  |      }| j                  ||| j                  | j                        }n| j                  || j                        }|r.|dk7  r)||j                   j                  t        j                  <   |S t        j                  |v r%|j                   j                  t        j                  = |S )z(Updates the revision to use zip deploys.r   z{})rE   r   rd   r   SOURCES_ANNOTATIONr   r   r   r   r   r   )r#   r*   r   r   r   r   s         r$   r+   zSourcesAnnotationChange.Adjust  s     ##//K$[__X%@%@"ENN3$$
$dllDLLi ((4<<@iY$&CLh##H$?$?@ O 
	$	$	3



'
'(C(C
DOr'   N)r*   r   r   r   r   r   r   r   r   r   )r,   r-   r.   r/   r   r   r   r   rJ   r   r   r   r   r+   r!   r'   r$   r   r     s|     .K--dC'>C({((>'9>>!> '> 	>
 > 	'	/=	r'   r   c                  4     e Zd ZU dZdZded<   d fdZ xZS )*IngressContainerBaseImagesAnnotationChangea  Represents the user intent to update the 'base-images' template annotation.

  The value of the annotation is a string representation of a json map of
  container_name -> base_image_url. E.g.: '{"mycontainer":"my_base_image_url"}'.

  This class changes the base image annotation for the default container, which
  is either the container in a service with one container or the one with a port
  set in a service with multiple containers.

  Attributes:
    base_image: url of the base image for the default container or None
  Nr=   
base_imagec                ,   | j                   r<| j                   | j                  |j                  j                  j                  xs d<   n=| j
                  j                  |j                  j                  j                  xs d       t        | !  |      S r   )	r   r   rE   rA   namer   appendr   r+   )r#   r*   r   s     r$   r+   z1IngressContainerBaseImagesAnnotationChange.Adjust(  sm     =A__dll8$$..339r:
ll(++55::@bA7>(##r'   r   )r,   r-   r.   r/   r   rJ   r+   r   r   s   @r$   r   r     s      *j$ $r'   r   c                  "    e Zd ZU dZded<   d Zy)SetLaunchStageAnnotationChangezhSets launch stage annotation on a resource.

  Attributes:
    launch_stage: The launch stage to set.
  base.ReleaseTracklaunch_stagec                    | j                   t        j                  j                  k(  r|S | j                   j                  |j
                  t        j                  <   |S rZ   )r   r   ReleaseTrackGAidr   r   LAUNCH_STAGE_ANNOTATIONr)   s     r$   r+   z%SetLaunchStageAnnotationChange.Adjust=  sO    D--000o 



 :==> or'   Nr{   r!   r'   r$   r   r   3  s     "!r'   r   c                  "    e Zd ZU dZded<   d Zy)SetRegionsAnnotationChangezhSets regions annotation on a resource.

  Attributes:
    regions: A comma-separated list of regions.
  r   regionsc                T    | j                   |j                  t        j                  <   |S rZ   )r   r   r   MULTI_REGION_REGIONS_ANNOTATIONr)   s     r$   r+   z!SetRegionsAnnotationChange.AdjustQ  s&     CCD Or'   Nr{   r!   r'   r$   r   r   G       ,r'   r   c                  2    e Zd ZU dZded<   ded<   d Zd Zy)RegionsChangeAnnotationChangezAdds or removes regions annotation on an existing service.

  Attributes:
    existing: the existing Service.
    to_add: A comma-separated list of regions to add to existing.
    to_remove: A comma-separated list of regions to remove from existing.
  r   to_add	to_removec                    | j                  |      }dj                  |      |j                  t        j                  <   |S Nr   )GetFinalListr   r   r   r   )r#   r*   
final_lists      r$   r+   z$RegionsChangeAnnotationChange.Adjuste  s<    ""8,JGJxxHHCCD Or'   c                   |j                   j                  t        j                        xs d}|r|j	                  d      ng }| j
                  r| j
                  j	                  d      ng }| j                  r| j                  j	                  d      ng }|D cg c]	  }||vs| }}|j                  |D cg c]	  }||vs| c}       |S c c}w c c}w )z=Returns the final list of regions after applying the changes.Nr   )r   rd   r   r   splitr   r   extend)r#   r*   
annotationexistingr   r   r   r   s           r$   r   z*RegionsChangeAnnotationChange.GetFinalListl  s     	  !K!KL 	  )3z$H'+{{T[[s#F-1^^$$S)I%<X));!XJ<&>&QAX,=q&>? =>s   	C#C8	CCN)r,   r-   r.   r/   rJ   r+   r   r!   r'   r$   r   r   X  s     +.r'   r   c                  "    e Zd ZU dZded<   d Zy)MultiRegionDomainNameChangezSets a multi-region domain name annotation on the service.

  Attributes:
    domain_name: The sandbox annotation value to set.
  r   domain_namec                T    | j                   |j                  t        j                  <   |S rZ   )r  r   r   GCLB_DOMAIN_NAME_ANNOTATIONr)   s     r$   r+   z"MultiRegionDomainNameChange.Adjust  s(     ??@ Or'   Nr{   r!   r'   r$   r  r  z  s     r'   r  c                  J    e Zd ZU dZded<   ded<   dZded<   ed        Zd	 Zy
)'SetClientNameAndVersionAnnotationChangea  Sets the client name and version annotations.

  Attributes:
    client_name: Client name to set.
    client_version: Client version to set.
    set_on_template: A boolean indicating whether the client name and version
      annotations should be set on the resource template as well.
  r   client_nameclient_versionTrW   set_on_templatec                    | j                   S rZ   )r  r"   s    r$   r%   z8SetClientNameAndVersionAnnotationChange.adjusts_template  s    r'   c                   | j                   z| j                   |j                  t        j                  <   | j                  rGt        |j                  d      r1| j                   |j                  j                  t        j                  <   | j                  z| j                  |j                  t        j                  <   | j                  rGt        |j                  d      r1| j                  |j                  j                  t        j                  <   |S )Nr   )	r  r   r   CLIENT_NAME_ANNOTATIONr  rc   rE   r  CLIENT_VERSION_ANNOTATIONr)   s     r$   r+   z.SetClientNameAndVersionAnnotationChange.Adjust  s    #@D@P@Ph:<<=			'(*;*;]"K 	%%j&G&GH &


 :??@ 
		'(*;*;]"K 	%%j&J&JK Or'   N)	r,   r-   r.   r/   rJ   r  r0   r%   r+   r!   r'   r$   r
  r
    s6     /4   r'   r
  c                  "    e Zd ZU dZded<   d Zy)SandboxChangezmSets a sandbox annotation on the service.

  Attributes:
    sandbox: The sandbox annotation value to set.
  r   sandboxc                h    | j                   |j                  j                  t        j                  <   |S rZ   )r  rE   r   r   SANDBOX_ANNOTATIONr)   s     r$   r+   zSandboxChange.Adjust  s-     !!"4"G"GH Or'   Nr{   r!   r'   r$   r  r    r   r'   r  c                  "    e Zd ZU dZded<   d Zy)VpcConnectorChangezSets a VPC connector annotation on the service.

  Attributes:
    connector_name: The VPC connector name to set in the annotation.
  r   connector_namec                h    | j                   |j                  j                  t        j                  <   |S rZ   )r  rE   r   r   VPC_ACCESS_ANNOTATIONr)   s     r$   r+   zVpcConnectorChange.Adjust  s/     !!"4"J"JK Or'   Nr{   r!   r'   r$   r  r    s     r'   r  c                      e Zd ZdZd Zy)ClearVpcConnectorChangez1Clears a VPC connector annotation on the service.c                    |j                   j                  }t        j                  |v r|t        j                  = t        j                  |v r|t        j                  = |S rZ   )rE   r   r   r  EGRESS_SETTINGS_ANNOTATIONr   s      r$   r+   zClearVpcConnectorChange.Adjust  sR    ##//K//;>
(>>
?44C
(CC
DOr'   Nru   r!   r'   r$   r  r    s
    9r'   r  )r   r:   c                  4     e Zd ZU dZded<    fdZd Z xZS )ImageChangezjA Cloud Run container deployment.

  Attributes:
    image: The image to set in the adjusted container.
  r   imagec                R    t        |   di | t        j                  | d|       y )Nr"  r!   r   r   object__setattr__)r#   r"  kwargsr   s      r$   r   zImageChange.__init__  s%    	Gv
tWe,r'   c                &    | j                   |_         y rZ   )r"  r@   s      r$   rC   zImageChange.AdjustContainer  s    jjIOr'   r,   r-   r.   r/   rJ   r   rC   r   r   s   @r$   r!  r!    s     
*-!r'   r!  c                H    |r| j                          y |D ]
  }|| v s| |=  y rZ   )clear)mappingkeys_to_removeclear_othersvar_or_paths       r$   _PruneMappingr0    s*    
 MMO%		K  &r'   c           
     X   |r|j                          y|D ]  }|j                  dd      \  }}||v s||   }	|	|v r&t        | |	|t        j                  ||	         ||      }	g }
||	   j
                  D ]#  }||j                  k7  s|
j                  |       % |
s||= |
||	   _         y)z5Remove the specified volume mappings from the config./   N)r+  rsplit_CopyToNewVolumerf   rg   r   pathr   )r*   res_volumesvolume_mountsremovesr.  external_mountsremovemountr6  volume_name	new_pathskey_to_paths               r$   _PruneManagedVolumeMappingr@    s     MM#q)keT	-	#E*/)(mmK45+ 	&{399K[%%%[) : E"+4+k
"
(+ r'   c                   t        |j                  | j                  j                        }	 |||<   |j                  D ch c]  }|j                   }}||   }	|	j                  D ],  }|j                  |vs|j                  j                  |       . |||<   |S # t        $ r% t        j                  dj                  |            w xY wc c}w )z1Copies existing volume to volume with a new name.RCannot update mount [{}] because its mounted volume is of a different source type.)_UniqueVolumeName
secretNamerE   r   KeyErrorr   ConfigurationErrorformatr   r6  r   )
r*   r=  mount_pointvolume_sourcer7  r8  new_volume_nameitemr>  
old_volumes
             r$   r5  r5  !  s     & 1 1 9 9/!0M+ &3%8%89%8Ttyy%8)9;'*dyy	!  &  "/+o	 
 

'
'	))/)<  :s   B C.C	c                      e Zd ZU dZ ej
                  e      Zded<    ej
                  e	      Z
ded<   dZded	<   d
 Zy)EnvVarLiteralChangeszRepresents the user intent to modify environment variables string literals.

  Attributes:
    updates: Updated env var names and values to set.
    removes: Env vars to remove.
    clear_others: If true clear all non-updated env vars.
  r   Mapping[str, str]r   Collection[str]r9  FrW   r.  c                R   t        |j                  j                  | j                  | j                         	 |j                  j                  j                  | j                         y# t        $ r6}t        j                  dj                  |j                  d               d}~ww xY w)a  Mutates the given config's env vars to match the desired changes.

    Args:
      container: container to adjust
      messages_mod: messages module

    Returns:
      The adjusted container

    Raises:
      ConfigurationError if there's an attempt to replace the source of an
        existing environment variable whose source is of a different type
        (e.g. env var's secret source can't be replaced with a config map
        source).
    zpCannot update environment variable [{}] to string literal because it has already been set with a different type.r   N)r0  env_varsliteralsr9  r.  updater   rE  r   rF  rG  args)r#   rA   rB   es       r$   rC   z$EnvVarLiteralChanges.AdjustContainerL  s      )$$--t||T=N=NO!!((6 ))CCI6ffQiD s   /A' '	B&01B!!B&N)r,   r-   r.   r/   r   r   r   r   rJ   r   r9  r.  rC   r!   r'   r$   rN  rN  >  sG      1{00F'F.[..tD'?D,r'   rN  c                  D    e Zd ZU dZded<   ded<   ded<   dZd	ed
<   d Zy)SecretEnvVarChangesaX  Represents the user intent to modify environment variable secrets.

  Attributes:
    updates: Env var names and values to update.
    removes: List of env vars to remove.
    clear_others: If true clear all non-updated env vars.
    container_name: Name of the container to update. If None, the resource's
      primary container is update.
  -Mapping[str, secrets_mapping.ReachableSecret]r   rP  r9  rW   r.  Nr=   r>   c                
   | j                   r8|j                  j                  | j                      j                  j                  }n |j                  j                  j                  }t        || j                  | j                         | j                  j                         D ]  \  }}	 |j                  |      ||<    t        j                   |       |S # t        $ r% t        j                  dj                  |            w xY wa  Mutates the given config's env vars to match the desired changes.

    Args:
      resource: k8s_object to adjust

    Returns:
      The adjusted resource

    Raises:
      ConfigurationError if there's an attempt to replace the source of an
        existing environment variable whose source is of a different type
        (e.g. env var's secret source can't be replaced with a config map
        source).
    zpCannot update environment variable [{}] to the given type because it has already been set with a different type.)r>   rE   rF   rR  secretsr0  r9  r.  r   r   AsEnvVarSourcerE  r   rF  rG  r   PruneAnnotation)r#   r*   rR  r   reachable_secrets        r$   r+   zSecretEnvVarChanges.Adjustz  s     ""--


  ""++33h(DLL$*;*;<"&,,"4"4"6
)88B #7 ##H-O  
++EEKVF
 	

s   'C.D)r,   r-   r.   r/   rJ   r>   r+   r!   r'   r$   rX  rX  i  s*     98#.*#"r'   rX  c                  4     e Zd ZdZ fdZd Zd Zd Z xZS )ConfigMapEnvVarChangeszFRepresents the user intent to modify environment variable config maps.c                   t         |           i | _        |j                         D ]T  \  }}|j	                  dd      }t        |      dk  r |j                  | j                  |             || j                  |<   V || _        || _	        y)aB  Initialize a new ConfigMapEnvVarChanges object.

    Args:
      updates: {str, str}, Update env var names and values.
      removes: [str], List of env vars to remove.
      clear_others: bool, If true, clear all non-updated env vars.

    Raises:
      ConfigurationError if a key hasn't been provided for a source.
    r   r3     N)
r   r   _updatesr   r   lenr   _OmittedSecretKeyDefault_removes_clear_others)r#   r   r9  r.  r   r   r   r   s          r$   r   zConfigMapEnvVarChanges.__init__  s}     
GDM==?a ggc1oe	UaT22489!dmmD # DM%Dr'   c                t    t        j                         ryt        j                  dj	                  |            )Nlatestz8Missing required item key for environment variable [{}].)r   	IsManagedr   rF  rG  )r#   r   s     r$   rf  z/ConfigMapEnvVarChanges._OmittedSecretKeyDefault  s2    

'
'BII$O r'   c                ~   |j                   j                  j                  }t        || j                  | j
                         | j                  j                         D ]-  \  }\  }}	 | j                  |j                         ||      ||<   / |S # t        $ r% t        j                  dj                  |            w xY wr[  )rE   rR  config_mapsr0  rg  rh  rd  r   _MakeEnvVarSourcerG   rE  r   rF  rG  )r#   r*   rR  r   source_name
source_keys         r$   r+   zConfigMapEnvVarChanges.Adjust  s       ))55H(DMM4+=+=>+/==+>+>+@''{J

//##%{J
 ,A O  
++EEKVF
 	

s   &$B.B<c                H    |j                  |j                  ||            S )N)r   r   )configMapKeyRef)EnvVarSourceConfigMapKeySelector)r#   messagesr   r   s       r$   rn  z(ConfigMapEnvVarChanges._MakeEnvVarSource  s-       554S5I !  r'   )	r,   r-   r.   r/   r   rf  r+   rn  r   r   s   @r$   ra  ra    s    N&.@r'   ra  c                  B    e Zd ZU dZdZded<   dZded<   dZded<   d Zy)ResourceChangesa\  Represents the user intent to update resource limits.

  Attributes:
    memory: Updated memory limit to set in the container. Specified as string
      ending in 'Mi' or 'Gi'. If None the memory limit is not changed.
    cpu: Updated cpu limit to set in the container if not None.
    gpu: Updated gpu limit to set in the container if not None.
  Nr=   memorycpugpuc                <   | j                   | j                   |j                  d<   | j                  | j                  |j                  d<   | j                  F| j                  dk(  r|j                  j	                  dd       y| j                  |j                  d<   yy)CMutates the given config's resource limits to match what's desired.Nrx  ry  0znvidia.com/gpu)rx  resource_limitsry  rz  popr@   s      r$   rC   zResourceChanges.AdjustContainer  s    {{,0KKi)xx)-i&xx	S!!%%&6=6:hh	!!"23	 r'   )	r,   r-   r.   r/   rx  rJ   ry  rz  rC   r!   r'   r$   rw  rw    s,     &*#z#z
?r'   rw  c           	     T   d }| j                         }|D ]  }|j                  d      r| j                         |_        *|j                  d      r| j	                         |_        Q|j                  d      r| j                         |_        xt        || |||              d|v r ||d      |j                  _	        d|v r ||d      |j
                  _	        d|v r|d   |j
                  _
        d|v r ||d      |j                  _	        d	|v r|d	   |j                  _        |S )
zCreates a probe from the given settings.

  Args:
    messages: Run v1 messages module.
    settings: a dict of settings for the probe.

  Returns:
    A new Run v1 probe.
  c                    | |   sy 	 t        | |         S # t        $ r% t        j                  dj	                  |            w xY w)Nz&Value for key [{}] must be an integer.)int
ValueErrorr   ArgumentErrorrG  )settingsr   s     r$   	_ParseIntz_MakeProbe.<locals>._ParseInt  sP    C=# $$
2
9
9#
> s	    .A	tcpSockethttpGetgrpcztcpSocket.portzhttpGet.portzhttpGet.pathz	grpc.portzgrpc.service)Prober   TCPSocketActionr  HTTPGetActionr  
GRPCActionr  setattrportr6  r   )ru  r  r  prober   s        r$   
_MakeProber    s    ..
%c
~~k" 002eo			",,.em		&&(ej eS)Hc23  !$X/?@EOOx"8^<EMMx!.1EMMH+6EJJOx!.1EJJ	,r'   c                  V    e Zd ZU dZ ej
                  e      Zded<   dZ	ded<   d Z
y	)
StartupProbeChangeszRepresents the user intent to update startup probe settings.

  Attributes:
    settings: Values to set in the probe.
    clear: If true, clear the startup probe.
  r   r   r  FrW   r+  c                b    | j                   rd |_        y t        || j                        |_        y rZ   )r+  startupProber  r  r@   s      r$   rC   z#StartupProbeChanges.AdjustContainer@  s'    zz#i'dmmDIr'   Nr,   r-   r.   r/   r   r   r   r  rJ   r+  rC   r!   r'   r$   r  r  4  s0     /[..tD(ND%Er'   r  c                  V    e Zd ZU dZ ej
                  e      Zded<   dZ	ded<   d Z
y	)
LivenessProbeChangeszRepresents the user intent to update liveness probe settings.

  Attributes:
    settings: values to set in the probe.
    clear: If true, clear the liveness probe.
  r   r   r  FrW   r+  c                b    | j                   rd |_        y t        || j                        |_        y rZ   )r+  livenessProber  r  r@   s      r$   rC   z$LivenessProbeChanges.AdjustContainerS  s'    zz $i(t}}EIr'   Nr  r!   r'   r$   r  r  G  s0     /[..tD(ND%Fr'   r  c                  V    e Zd ZU dZ ej
                  e      Zded<   dZ	ded<   d Z
y	)
ReadinessProbeChangeszRepresents the user intent to update readiness probe settings.

  Attributes:
    settings: values to set in the probe.
    clear: If true, clear the readiness probe.
  r   r   r  FrW   r+  c                b    | j                   rd |_        y t        || j                        |_        y rZ   )r+  readinessProber  r  r@   s      r$   rC   z%ReadinessProbeChanges.AdjustContainerf  s'    zz!%i),FIr'   Nr  r!   r'   r$   r  r  Z  s0     /[..tD(ND%Gr'   r  c                  f    e Zd ZU dZded<   ded<   ded<   dZded<   e	 	 d	 	 	 	 	 dd	       Zd
 Zy)CloudSQLChangeszRepresents the intent to update the Cloug SQL instances.

  Attributes:
    project: Project to use as the default project for Cloud SQL instances.
    region: Region to use as the default region for Cloud SQL instances
    args: Args to the command.
  r   add_cloudsql_instancesremove_cloudsql_instancesset_cloudsql_instancesNbool | Noneclear_cloudsql_instancesc          
     t    fd}fd |  |d       |d       |d      t        dd            S )	aP  Returns a CloudSQLChanges object from the given args.

    Args:
      project: Optional project. If absent project must be specified in each
        Cloud SQL instance.
      region: Optional region. If absent region must be specified in each Cloud
        SQL instance.
      args: Command line args to parse CloudSQL flags from.
    c                Z    t        | d       }|y |D cg c]
  } |       c}S c c}w rZ   getattr)arg_namevaliAugmentrU  s      r$   AugmentArgsz-CloudSQLChanges.FromArgs.<locals>.AugmentArgs  s5    D(D)c	"%&#Qgaj#&&&s   (c                r   | j                  d      }t        |      dk(  rdj                  |      S t        |      dk(  rUst        j                  d      st        j                  d      dj                  t        j                  g|            S t        j                  dj                  |             )Nr   rq   r3  zJTo specify a Cloud SQL instance by plain name, you must specify a project.zcTo specify a Cloud SQL instance by plain name, you must be deploying to a managed Cloud Run region.z&Malformed CloudSQL instance string: {})r   re  r   r   CloudSQLError	itertoolschainrG  )instance_strinstanceprojectregions     r$   r  z)CloudSQLChanges.FromArgs.<locals>.Augment  s    ##C(h	X!	xx!!x=A((  ((9  xx	&(98DEE&&4;;LI
 	
r'   r  r  r  r  N)r  r  r  r  r  )clsr  r  rU  r  r  s    ``` @r$   FromArgszCloudSQLChanges.FromArgs|  sG    $'
, *+CD"-.I"J*+CD!(,d"
	 r'   c                    fd}t        j                  | d|      }|6dj                  |      j                  j                  t
        j                  <   S )Nc                     j                   j                  j                  t        j                        } | r| j                  d      S g S r   )rE   r   rd   r   CLOUDSQL_ANNOTATIONr   annotation_valr*   s    r$   GetCurrentInstancesz3CloudSQLChanges.Adjust.<locals>.GetCurrentInstances  sC    ((4488

0
0n 
##C((ir'   zcloudsql-instancesr   )r   ParsePrimitiveArgsr   rE   r   r   r  )r#   r*   r  	instancess    `  r$   r+   zCloudSQLChanges.Adjust  s[     ++"$7I 
((9
 ##$6$J$JK Or'   )NN)r  r=   r  r=   rU  zargparse.Namespace)	r,   r-   r.   r/   rJ   r  classmethodr  r+   r!   r'   r$   r  r  m  sb     $#&&##*.K. !44 4
 4 4lr'   r  c                  6    e Zd ZU dZdZded<   ed        Zd Zy)ConcurrencyChangeszRepresents the user intent to update concurrency preference.

  Attributes:
    concurrency: The concurrency value to set in the resource template. If None
      concurrency is cleared.
  Nz
int | Noneconcurrencyc                :     | |dk(  rd      S t        |            S )zReturns a ConcurrencyChanges object from the --concurrency flag value.

    Args:
      concurrency: The concurrency flag value. If 'default' concurrency is
        cleared, otherwise should be an integer concurrency value to set.
    defaultN)r  )r  r  s     r$   FromFlagzConcurrencyChanges.FromFlag  s#     {i/tFFS5EFFr'   c                <    | j                   |j                  _         |S )r|  )r  rE   r)   s     r$   r+   zConcurrencyChanges.Adjust  s    $($4$4H!Or'   )	r,   r-   r.   r/   r  rJ   r  r  r+   r!   r'   r$   r  r    s,     !+z G Gr'   r  c                  "    e Zd ZU dZded<   d Zy)TimeoutChangeszRepresents the user intent to update request duration.

  Attributes:
    timeout: The timeout to set in the resource template.
  r   timeoutc                <    | j                   |j                  _         |S )z;Mutates the given config's timeout to match what's desired.)r  rE   r)   s     r$   r+   zTimeoutChanges.Adjust  s     $HOr'   Nr{   r!   r'   r$   r  r    s     ,r'   r  c                  "    e Zd ZU dZded<   d Zy)ServiceAccountChangeszRepresents the user intent to change service account for the revision.

  Attributes:
    service_account: The service account to set.
  r   service_accountc                <    | j                   |j                  _         |S )zCMutates the given config's service account to match what's desired.)r  rE   r)   s     r$   r+   zServiceAccountChanges.Adjust  s    (,(<(<H%Or'   Nr{   r!   r'   r$   r  r    s     r'   r  ?   c                  "    e Zd ZU dZded<   d Zy)RevisionNameChangeszRepresents the user intent to change revision name.

  Attributes:
    revision_suffix: Suffix to append to the revision name.
  r   revision_suffixc                    | j                   sd|j                  _        |S t        t	        | j                         z
  dz
  }dj                  |j                  d| | j                         |j                  _        |S )zAMutates the given config's revision name to match what's desired.r   r3  z{}-{}N)r  rE   r   _MAX_RESOURCE_NAME_LENGTHre  rG  )r#   r*   max_prefix_lengths      r$   r+   zRevisionNameChanges.Adjust  su    !ho 	"C(<(<$==A  %^^(()4+?+?H Or'   Nr{   r!   r'   r$   r  r    s     r'   r  c                2    t        j                  dd|       S )z.Randomly generated name with the given prefix.rq   -)sectionsrs   prefix)r   rt   )r  s    r$   _GenerateVolumeNamer    s    		$	$a3v	NNr'   c                <    d}|||v rt        |       }|||v r|S )zGenerate unique volume name.

  The names that connect volumes and mounts must be unique even if their
  source volume names match.

  Args:
    source_name: (Potentially clashing) name.
    existing_volumes: Names in use.

  Returns:
    Unique name.
  N)r  )ro  existing_volumesr=  s      r$   rC  rC  "  s7     +{.>>%k2K 	{.>>	r'   c                4    t        |      D ]
  }|| vs||=  y)zDelete all volumes no longer being mounted.

  Args:
    mounted_volumes: set of volumes mounted in any container
    res_volumes: resource.template.volumes
  N)r   )mounted_volumesr7  volumes      r$   _PruneVolumesr  5  s#     [!f_$
f
 "r'   c                  J    e Zd ZU dZded<   ded<   ded<   dZd	ed
<   d Zd Zy)SecretVolumeChangesaT  Represents the user intent to change volumes with secret source types.

  Attributes:
    updates: Updates to mount path and volume fields.
    removes: List of mount paths to remove.
    clear_others: If true clear all non-updated volumes and mounts of the given
      [volume_type].
    container_name: Name of the container to update.
  rY  r   rP  r9  rW   r.  Nr=   r>   c           	        i }t        j                  t              }|j                         D ]  \  }}||   j	                  |        | j
                  j                         D ]  \  }	}
|	j                  dd      d   }||v rV||   j                  |
j                  k7  r$t        j                  dj                  |	            |
j                  |||          u|
j                  |      ||<    |j                         D ]  \  }}||v rK||   }t        ||         dkD  s||v r9||   j                  |       t!        ||||||      }||   j	                  |       _||   }|j                  |j                  k7  r{|j                  D ch c]  }|j"                   }}|j                  D ch c]  }|j"                   }}|j%                  |      st        j                  dj                  |            |j                  D ch c]  }|j"                   }}|j                  D ],  }|j"                  |vs|j                  j	                  |       . n0t'        |j                  |j(                  j*                        }	 |||<   |||<    yc c}w c c}w c c}w # t,        $ r% t        j                  dj                  |            w xY w)zCUpdate volumes for Cloud Run. Ensure only one secret per directory.r2  r3  r   zaCannot update secret at [{}] because a different secret is already mounted in the same directory.zcMultiple secrets are specified for directory [{}]. Cloud Run only supports one secret per directoryrB  N)collectionsdefaultdictr   r   r   r   r4  rD  secret_namer   rF  rG  AppendToSecretVolumeSourceAsSecretVolumeSourcere  r;  r5  r6  issubsetrC  rE   r   rE  )r#   r*   r8  r7  r:  new_volumesvolumes_to_mountsr6  vol	file_pathr_  rH  rI  r=  new_namer  rK  existing_pathsr>  s                      r$   _UpdateManagedVolumesz)SecretVolumeChanges._UpdateManagedVolumesR  s    K#//5"((*	c##D) + (,||'9'9';#	#$$S!,Q/k		#{#..2B2N2NN --77=vi7H  	33k+.	
 $4#H#H$
K  (<$ '2&7&7&9"]		%#K0!+./!3o- K
(
/
/
<%( H
%
,
,[
9
{+&-":"::4:LLALDdiiLNA/</B/BC/Bt/BIC!**9511<<BF;<O  0=/B/BC/Bt/BIC)+##**40 %
 ($$h&7&7&?&?
	'2-
$ "/k+e ':0 BC D  	--//5vk/B 	s   J+JJ?J.K
c                ^  
 | j                   r$|j                  j                  | j                      
n|j                  j                  

j                  j
                  }|j                  j                  j
                  }t        t        j                  j                  
fd|j                  j                  j                         D                    }t        j                         r%t        |||| j                  | j                   |       n#| j                  }t#        ||| j                          t        j                         r| j%                  ||||       nh| j&                  j                         D ]K  \  }}t)        |j*                  |j                  j                        }	 |}	|||	<   |j5                  |      ||<   M t7        |j9                  |j;                               |       t=        j>                  |       |S # t,        $ r% t/        j0                  dj3                  |            w xY w)  Mutates the given config's volumes to match the desired changes.

    Args:
      resource: k8s_object to adjust

    Returns:
      The adjusted resource

    Raises:
      ConfigurationError if there's an attempt to replace the volume a mount
        points to whose existing volume has a source of a different type than
        the new volume (e.g. mount that points to a volume with a secret source
        can't be replaced with a volume that has a config map source).
    c              3     K   | ]:  \  }}|j                   k7  r&|j                  j                  j                          < y wrZ   )r   r8  r\  values)r   r   external_containerrA   s      r$   r   z-SecretVolumeChanges.Adjust.<locals>.<genexpr>  s@      &
,P((y~~% ,,44;;=,Ps   A ArB  ) r>   rE   rF   rA   r8  r\  r   rl   r  r  from_iterabler   r   rk  r@  r9  r.  r0  r  r   rC  r  rE  r   rF  rG  r  r  unionr  r   r^  )r#   r*   r8  r7  r:  r9  r  r_  r=  rH  rA   s             @r$   r+   zSecretVolumeChanges.Adjust  s    ##..t/B/BCi##--i++33M##++33K%% &
,4,=,=,H,H,N,N,P&
 	
O  



,,



 gM7D,=,=>
  
M; *.););)=
%)%'(((*;*;*C*C
	!+'2-
$ $4#H#H$
K  *>& /''(<(<(>?M##H-O  	--//5vi/@ 	s   !G>>.H,)r,   r-   r.   r/   rJ   r>   r  r+   r!   r'   r$   r  r  A  s2     98#.*#M/^Dr'   r  c                  0     e Zd ZdZ fdZd ZddZ xZS )ConfigMapVolumeChangeszJRepresents the user intent to change volumes with config map source types.c                    t         |           i | _        |j                         D ]E  \  }}|j	                  dd      }t        |      dk  r|j                  d       || j                  |<   G || _        || _        y)a+  Initialize a new ConfigMapVolumeChanges object.

    Args:
      updates: {str, [str, str]}, Update mount path and volume fields.
      removes: [str], List of mount paths to remove.
      clear_others: bool, If true, clear all non-updated volumes and mounts of
        the given [volume_type].
    r   r3  rc  N)	r   r   rd  r   r   re  r   rg  rh  )r#   r   r9  r.  r   r   update_valuer   s          r$   r   zConfigMapVolumeChanges.__init__  sv     
GDM1 WWS!_l	\	Q	D!%dmmA   DM%Dr'   c                   |j                   j                  j                  j                  }|j                   j                  j                  }t        || j                  | j                         | j                  j                         D ]R  \  }\  }}t        ||j                   j                        }	 |||<   | j                  |j!                         ||      ||<   T t#        t$        j&                  j)                  d |j                   j*                  j-                         D                    }t/        ||       |S # t        $ r% t        j                  dj                  |            w xY w)r  rB  c              3  d   K   | ](  }|j                   j                  j                          * y wrZ   )r8  rm  r  )r   rA   s     r$   r   z0ConfigMapVolumeChanges.Adjust.<locals>.<genexpr>&  s-      &
B	 ##//668Bs   .0)rE   rA   r8  rm  r   r0  rg  rh  rd  r   rC  rE  r   rF  rG  _MakeVolumeSourcerG   rl   r  r  r  rF   r  r  )	r#   r*   r8  r7  r6  ro  rp  r=  r  s	            r$   r+   zConfigMapVolumeChanges.Adjust  sA    %%//==IIM##++77K-0B0BC+/==+>+>+@''{J%k83D3D3L3LMk
)d "&!7!7

!
!
#[*"k+ ,A   %% &
%..99@@B&
 	
O /;/O#  
++--3VD\
 	

s   0D::.E(c                    |j                  |      }|,|j                  j                  |j                  ||             |S )N)r   )r   r6  )ConfigMapVolumeSourcer   r   	KeyToPath)r#   ru  r   r   sources        r$   r   z(ConfigMapVolumeChanges._MakeVolumeSource/  sA    +++6F
ll(,,3,?@Mr'   rZ   )r,   r-   r.   r/   r   r+   r   r   r   s   @r$   r  r    s    R&,,\r'   r  c                      e Zd ZdZd Zy)NoTrafficChangez?Represents the user intent to block traffic for a new revision.c                    |j                   st        j                  d      |j                  j	                  |j
                  j                         |S )z5Removes LATEST from the services traffic assignments.z7--no-traffic not supported when creating a new service.)
generationr   rF  spec_trafficZeroLatestTrafficstatuslatestReadyRevisionNamer)   s     r$   r+   zNoTrafficChange.Adjust9  sK    ))
C  ++// Or'   Nru   r!   r'   r$   r  r  6  s
    G
r'   r  c                      e Zd ZU dZded<   dZded<    ej                  e      Z	ded	<    ej                  e
      Zd
ed<   dZded<   d Zy)TrafficChangesa  Represents the user intent to change a service's traffic assignments.

  Attributes:
    new_percentages: New traffic percentages to set.
    by_tag: Boolean indicating that new traffic percentages are specified by
      tag.
    tags_to_update: Traffic tag values to update.
    tags_to_remove: Traffic tags to remove.
    clear_other_tags: Whether nonupdated tags should be cleared.
  zMapping[str, int]new_percentagesFrW   by_tagr   rO  tags_to_updateContainer[str]tags_to_removeclear_other_tagsc                B   | j                   s| j                  s| j                  r;|j                  j	                  | j                   | j                  | j                         | j
                  rw| j                  rD|j                  j                         }i }| j
                  D ]  }	 | j
                  |   |||   <    n| j
                  }|j                  j                  |       |S # t        $ r0 t        j                  dj                  ||j                              w xY w)z0Mutates the given service's traffic assignments.zIThere is no revision tagged with [{}] in the traffic allocation for [{}].)r  r  r  r	  
UpdateTagsr  r  TagToKeyrE  r   rF  rG  r   UpdateTraffic)r#   r*   
tag_to_keypercentagestags        r$   r+   zTrafficChanges.AdjustY  s   d11T5J5J&&









 	**335
''C+/+?+?+DK
3( ( **))+6O  //((.sHMM(B s   $C%%9DN)r,   r-   r.   r/   rJ   r  r   r   r   r  r   r  r  r+   r!   r'   r$   r  r  F  sX    	 %$&$&7k&7&7&M.#M#4;#4#4T#J..J D r'   r  c                  "    e Zd ZU dZded<   d Zy)TagOnDeployChangezThe intent to provide a tag for the revision you're currently deploying.

  Attributes:
    tag: The tag to apply to the new revision.
  r   r  c                    | j                   |j                  j                  i}|j                  j	                  |g d       |S )z6Gives the revision that's being created the given tag.F)r  rE   r   r	  r  )r#   r*   r  s      r$   r+   zTagOnDeployChange.Adjust}  s9    hh 1 1 6 67N$$^R?Or'   Nr{   r!   r'   r$   r  r  s  r   r'   r  c                  4     e Zd ZU dZded<    fdZd Z xZS )ContainerCommandChangezRepresents the user intent to change the 'command' for the container.

  Attributes:
    command: The command to set in the adjusted container.
  r   commandc                R    t        |   di | t        j                  | d|       y )Nr!  r!   r$  )r#   r!  r'  r   s      r$   r   zContainerCommandChange.__init__  s%    	Gv
tY0r'   c                &    | j                   |_         y rZ   )r!  r@   s      r$   rC   z&ContainerCommandChange.AdjustContainer  s    Ir'   r)  r   s   @r$   r   r     s     ,1%r'   r   c                  4     e Zd ZU dZded<    fdZd Z xZS )ContainerArgsChangezRepresents the user intent to change the 'args' for the container.

  Attributes:
    args: The args to set in the adjusted container.
  r   rU  c                R    t        |   di | t        j                  | d|       y )NrU  r!   r$  )r#   rU  r'  r   s      r$   r   zContainerArgsChange.__init__  s%    	Gv
tVT*r'   c                &    | j                   |_         y rZ   )rU  r@   s      r$   rC   z#ContainerArgsChange.AdjustContainer  s    YYINr'   r)  r   s   @r$   r%  r%    s     	/+r'   r%  h2c  c                  4    e Zd ZU dZdZded<   dZded<   d Zy)ContainerPortChangeae  Represents the user intent to change the port name and/or number.

  Attributes:
    port: The port to set, "default" to unset the containerPort field, or None
      to not modify the port number.
    use_http2: True to set the port name for http/2, False to unset it, or None
      to not modify the port name.
    **kwargs: ContainerConfigChanger args.
  Nr=   r  r  	use_http2c                B   |j                   r|j                   d   n|j                         }|j                  xs d}| j                  dk(  r|j	                  d       n&| j                  t        | j                        |_        | j                  rt        |_        n| j                  |j	                  d       |j                  r|j                  st        |_        |j                  r	|g|_         n|j	                  d       |j                  r|j                  j                  r||j                  j                  j                  |k(  rX|j                  r&|j                  |j                  j                  _        y|j                  j                  j	                  d       yyyy)	z5Modify an existing ContainerPort or create a new one.r   r)  r  containerPortNr   portsr  )r/  ContainerPortr.  r  resetr  r,  _HTTP2_NAMEr   _DEFAULT_PORTr  r  )r#   rA   rB   port_msgold_ports        r$   rC   z#ContainerPortChange.AdjustContainer  sC    (oo	<3M3M3O  %%-HyyInn_%		"499~h~~!hm		#nnV}}X33,h !
iooog )"8"8"B"B				)	)	.	.(	:!!2:2H2H)
 
 
*
*
/

 
 
*
*
0
0
8	 
; #Cr'   )r,   r-   r.   r/   r  rJ   r,  rC   r!   r'   r$   r+  r+    s"     $
)[ 9r'   r+  c                  ,    e Zd ZU dZded<   ded<   d Zy)ExecutionTemplateSpecChangezRepresents the intent to update field in an execution template's spec.

  Attributes:
    field: The field to update in the execution template spec.
    value: The value to set in the updated field.
  r   r   r   r   c                p    t        |j                  j                  | j                  | j                         |S rZ   )r  r\   r   r   r   r)   s     r$   r+   z"ExecutionTemplateSpecChange.Adjust  s'    H'',,djj$**EOr'   Nr{   r!   r'   r$   r7  r7    s     
*	*r'   r7  c                  "    e Zd ZU dZded<   d Zy)JobMaxRetriesChangezRepresents the user intent to update a job's restart policy.

  Attributes:
    max_retries: The max retry number to set in the job's restart policy.
  r  max_retriesc                P    | j                   |j                  j                  _        |S rZ   )r;  task_templater   
maxRetriesr)   s     r$   r+   zJobMaxRetriesChange.Adjust  s!    -1-=-=H*Or'   Nr{   r!   r'   r$   r:  r:    s     r'   r:  c                  "    e Zd ZU dZded<   d Zy)JobTaskTimeoutChangezRepresents the user intent to update a job's instance deadline.

  Attributes:
    timeout_seconds: The timeout in seconds to set in the job's instance
      deadline.
  r  timeout_secondsc                P    | j                   |j                  j                  _        |S rZ   )rA  r=  r   timeoutSecondsr)   s     r$   r+   zJobTaskTimeoutChange.Adjust	  s!    151E1EH.Or'   Nr{   r!   r'   r$   r@  r@    s     r'   r@  c                  "    e Zd ZU dZded<   d Zy)CpuThrottlingChangezSets the cpu-throttling annotation on the service template.

  Attributes:
    throttling: The throttling annotation value to set.
  rW   
throttlingc                z    t        | j                        |j                  j                  t        j
                  <   |S rZ   )r   rF  rE   r   r   CPU_THROTTLE_ANNOTATIONr)   s     r$   r+   zCpuThrottlingChange.Adjust  s6     	DOO !!22 Or'   Nr{   r!   r'   r$   rE  rE    s     r'   rE  c                  "    e Zd ZU dZded<   d Zy)StartupCpuBoostChangezSets the startup-cpu-boost annotation on the service template.

  Attributes:
    cpu_boost: Boolean indicating whether CPU boost should be enabled.
  rW   	cpu_boostc                z    t        | j                        |j                  j                  t        j
                  <   |S rZ   )r   rK  rE   r   r   COLD_START_BOOST_ANNOTATIONr)   s     r$   r+   zStartupCpuBoostChange.Adjust)  s6     	DNN !!66 Or'   Nr{   r!   r'   r$   rJ  rJ    s     /r'   rJ  c                  "    e Zd ZU dZded<   d Zy)HealthCheckChangezSets the health-check-disabled annotation on the revision template.

  Attributes:
    health_check: Boolean indicating whether the health check should be enabled.
  rW   health_checkc                |    t        | j                         |j                  j                  t        j
                  <   |S rZ   )r   rP  rE   r   r   DISABLE_HEALTH_CHECK_ANNOTATIONr)   s     r$   r+   zHealthCheckChange.Adjust:  s;     	!!!" !!:: Or'   Nr{   r!   r'   r$   rO  rO  0  s     r'   rO  c                  "    e Zd ZU dZded<   d Zy)DefaultUrlChangezSets the default-url-disabled annotation on the service.

  Attributes:
    default_url: Boolean indicating whether the default URL should be enabled.
  rW   default_urlc                h    t        | j                         |j                  t        j                  <   |S rZ   )r   rU  r   r   DISABLE_URL_ANNOTATIONr)   s     r$   r+   zDefaultUrlChange.AdjustK  s2    FIGH+BBC Or'   Nr{   r!   r'   r$   rT  rT  A  s     r'   rT  c                  "    e Zd ZU dZded<   d Zy)InvokerIamChangezSets the invoker-iam-disabled annotation on the service.

  Attributes:
    invoker_iam_check: Boolean indicating whether invoker iam should be enabled
  rW   invoker_iam_checkc                h    t        | j                         |j                  t        j                  <   |S rZ   )r   rZ  r   r   DISABLE_IAM_ANNOTATIONr)   s     r$   r+   zInvokerIamChange.Adjust\  s2    FI"""GH+BBC Or'   Nr{   r!   r'   r$   rY  rY  R  s     r'   rY  c                  Z    e Zd ZU dZded<   ded<   ded<   ded<   ded<   d	ed
<   d Zd Zy)NetworkInterfacesChangea  Sets or updates the network interfaces annotation on the template.

  Attributes:
    network_is_set: Boolean indicating whether network was explicitly set by the
      user.
    network: The network to set.
    subnet_is_set: Boolean indicating whether subnet was explicitly set by the
      user.
    subnet: The subnet to set.
    network_tags_is_set: Boolean indicating whether network_tags was explicitly
      set by the user.
    network_tags: The network tags to set.
  rW   network_is_setr   networksubnet_is_setsubnetnetwork_tags_is_setr   network_tagsc                $    |r|||<   y ||v r||= y y rZ   r!   )r#   mr   r   s       r$   _SetOrClearz#NetworkInterfacesChange._SetOrClearz  s!    af	
C& 
r'   c                   |j                   j                  }i }t        j                  |v r)t	        j
                  |t        j                           d   }| j                  r| j                  |d| j                         | j                  r| j                  |d| j                         | j                  r| j                  |d| j                         d}|r'dj                  t	        j                  |d      	      }| j                  |t        j                  |       |s#t        j                   |v r|t        j                   = |S )
Nr   r`  
subnetworktagsr   z[{interfaces}]T)	sort_keys)
interfaces)rE   r   r   NETWORK_INTERFACES_ANNOTATIONr   r   r_  rg  r`  ra  rb  rc  rd  rG  r   r   r  )r#   r*   r   network_interfacer   s        r$   r+   zNetworkInterfacesChange.Adjust  s    ##//K//;>**
j>>
?	 
()T\\B
(,D
(&$2C2CDE%%ZZ 1TB & e 	Z==u
 99[H
(CC
DOr'   N)r,   r-   r.   r/   rJ   rg  r+   r!   r'   r$   r^  r^  c  s5     ,
+r'   r^  c                      e Zd ZdZd Zy)ClearNetworkInterfacesChangez7Clears a network interfaces annotation on the resource.c                    |j                   j                  }t        j                  |v r|t        j                  = t        j
                  |v r|t        j
                  = |S rZ   )rE   r   r   rm  r   r  r   s      r$   r+   z#ClearNetworkInterfacesChange.Adjust  sQ    ##//K//;>
j>>
?44C
(CC
DOr'   Nru   r!   r'   r$   rp  rp    s
    ?r'   rp  c                  b    e Zd ZU dZded<   ed        Zed        Zed        Zed        Z	d Z
y	)
CustomAudiencesChangeszfRepresents the intent to update the custom audiences.

  Attributes:
    args: Args to the command.
  r%  rU  c                0    t        | j                  dd       S )Nadd_custom_audiencesr  rU  r"   s    r$   ru  z+CustomAudiencesChanges.add_custom_audiences      4994d;;r'   c                0    t        | j                  dd       S )Nremove_custom_audiencesrv  r"   s    r$   ry  z.CustomAudiencesChanges.remove_custom_audiences  s    4997>>r'   c                0    t        | j                  dd       S )Nset_custom_audiencesrv  r"   s    r$   r{  z+CustomAudiencesChanges.set_custom_audiences  rw  r'   c                0    t        | j                  dd       S )Nclear_custom_audiencesrv  r"   s    r$   r}  z-CustomAudiencesChanges.clear_custom_audiences  s    4996==r'   c                   fd}t        j                  | d|      }|k|r2t        j                  |      j                  t
        j                  <   S t
        j                  j                  v rj                  t
        j                  = S )Nc                     j                   j                  t        j                        } | rt	        j
                  |       S g S rZ   )r   rd   r   CUSTOM_AUDIENCES_ANNOTATIONr   r   r  s    r$   GetCurrentCustomAudiencesz@CustomAudiencesChanges.Adjust.<locals>.GetCurrentCustomAudiences  s;    ++//

0
0n 
zz.))ir'   zcustom-audiences)r   r  r   r   r   r   r  )r#   r*   r  	audiencess    `  r$   r+   zCustomAudiencesChanges.Adjust  s     ++ ";I 	JJy! 	ZCCD
 O 11X5I5II  !G!GHOr'   N)r,   r-   r.   r/   rJ   r0   ru  ry  r{  r}  r+   r!   r'   r$   rs  rs    sa     	,< < ? ? < < > >r'   rs  c                  "    e Zd ZU dZded<   d Zy)RuntimeChangezxSets the runtime annotation on the service template.

  Attributes:
    runtime: The runtime annotation value to set.
  r   runtimec                P    | j                   |j                  j                  _        |S rZ   )r  rE   r   r   r)   s     r$   r+   zRuntimeChange.Adjust  s    .2llH+Or'   Nr{   r!   r'   r$   r  r    s     ,r'   r  c                  "    e Zd ZU dZded<   d Zy)GpuTypeChangez{Sets the gpu-type annotation on the service template.

  Attributes:
    gpu_type: The gpu_type annotation value to set.
  r   gpu_typec                    | j                   r3| j                   |j                  j                  t        j                  <   |S |j                  j                  j                  t        j                  d        |S rZ   )r  rE   node_selectorr   GPU_TYPE_NODE_SELECTORr  r)   s     r$   r+   zGpuTypeChange.Adjust  sa    }}
-- %%j&G&GH O %%))

+
+T Or'   Nr{   r!   r'   r$   r  r    s     -	r'   r  c                  "    e Zd ZU dZded<   d Zy)GpuZonalRedundancyChangezSets the gpu zonal redundancy annotation on the revision annotations.

  Attributes:
    gpu_zonal_redundancy: The gpu_zonal_redundancy annotation value to set.
  rW   gpu_zonal_redundancyc                |    t        | j                         |j                  j                  t        j
                  <   |S rZ   )r   r  rE   r   r   (GPU_ZONAL_REDUNDANCY_DISABLED_ANNOTATIONr)   s     r$   r+   zGpuZonalRedundancyChange.Adjust  s;     	)))* !!99 Or'   Nr{   r!   r'   r$   r  r    s     r'   r  c                  >    e Zd ZU dZded<   edd       Z	 	 	 	 ddZy)	RemoveContainersChangezYRemoves the specified containers.

  Attributes:
    containers: Containers to remove.
  zfrozenset[str]rF   c                $     | t        |            S )zReturns a RemoveContainersChange that removes the specified containers.

    Args:
      containers: The names of containers to remove. Duplicate container names
        are ignored.
    )rl   )r  rF   s     r$   FromContainerNamesz)RemoveContainersChange.FromContainerNames  s     y$%%r'   c                v    | j                   D ]  }	 |j                  j                   |=  |S # t        $ r Y *w xY wrZ   )rF   rE   rE  rH   s      r$   r+   zRemoveContainersChange.Adjust'  sF     __	((3 %
 O  s   ,	88N)rF   Iterable[str]r*   k8s_object.KubernetesObjectreturnr  )r,   r-   r.   r/   rJ   r  r  r+   r!   r'   r$   r  r    s6     & &1"r'   r  c                  R    e Zd ZU dZ ej
                  e      Zded<   	 	 	 	 ddZ	y)ContainerDependenciesChangeaC  Sets container dependencies.

  Updates container dependencies to add the dependencies in new_depencies.
  Additionally, dependencies to or from a container which does not exist will be
  removed.

  Attributes:
      new_dependencies: A map of containers to their updated dependencies.
        Defaults to an empty map.
  r   zMapping[str, Iterable[str]]new_dependenciesc                z   t        |j                  j                  j                               }|j                  j                  }|j                         D ci c]  \  }}||v r||D cg c]	  }||v s| c}! }}}}| j                  j                         D ]  \  }}|s |j                  j                  j                  }t        |      }||z
  }|r4t        j                  dj                  |dj                  |                  |rt        |      ||<   ||=  ||j                  _        |S c c}w c c}}}w )NzD--depends_on for container {} references nonexistent containers: {}.r   )rl   rE   rF   r   dependenciesr   r  rA   r   r   rF  rG  r   sorted)	r#   r*   rF   r  r>   
depends_onrQ   rA   missings	            r$   r+   z"ContainerDependenciesChange.AdjustC  s@    8,,77<<>?J$$11L +7*<*<*>*>&NJZ' 	JBJq!z/JBB*>   "&!6!6!<!<!>	:%%//44	Z(jZ'g	++%vi'1BC
 	

 
"("4Y# "?  &2H"O- Cs   D6)	D13D17D61D6Nr  )
r,   r-   r.   r/   r   r   r   r  rJ   r+   r!   r'   r$   r  r  2  s=    	 3D+2C2C3/ 1"r'   r  c                  ,    e Zd ZU dZded<   ded<   d Zy)RemoveVolumeChangezoRemoves volumes from the service or job template.

  Attributes:
    removed_volumes: The volumes to remove.
  r  removed_volumesrW   clear_volumesc                   | j                   r?t        |j                  j                        }|D ]  }|j                  j                  |=  |S | j                  D ]2  }||j                  j                  v s|j                  j                  |= 4 |S rZ   )r  r   rE   r   r  )r#   r*   volsr  r   s        r$   r+   zRemoveVolumeChange.Adjustn  s    (##++,d#%%c*  O ++)))111''	2 , Or'   Nr{   r!   r'   r$   r  r  c  s     ! 
r'   r  c                  ,    e Zd ZU dZded<   ded<   d Zy)AddVolumeChangezUpdates Volumes set on the service or job template.

  Attributes:
    new_volumes: The volumes to add.
    release_track: The resource's release track. Used to verify volume types are
      supported in that release track.
  Collection[Mapping[str, str]]r  r   release_trackc                    | j                   D ]F  }t        j                  ||j                  j                  |j	                         | j
                         H |S rZ   )r  r   
add_volumerE   rG   r  )r#   r*   r   s      r$   r+   zAddVolumeChange.Adjust  sN    ""




#
#

!
!
#


	 # Or'   Nr{   r!   r'   r$   r  r  {  s     -,""r'   r  c                  V    e Zd ZU dZ ej
                  e      Zded<   dZ	ded<   d Z
y	)
RemoveVolumeMountChangezRemoves Volume Mounts from the container.

  Attributes:
    removed_mounts: Volume mounts to remove from the adjusted container.
  r   rP  removed_mountsFrW   clear_mountsc                    | j                   r+t        |j                        }|D ]  }|j                  |=  |S | j                  D ]  }||j                  v s|j                  |=   |S rZ   )r  r   r8  r  )r#   rA   rB   r   r<  r   s         r$   rC   z'RemoveVolumeMountChange.AdjustContainer  ss     )))*d%##E*   **)	///%%i0 + r'   N)r,   r-   r.   r/   r   r   r   r  rJ   r  rC   r!   r'   r$   r  r    s/     %6K$5$5d$K./K,r'   r  c                  H    e Zd ZU dZ ej
                  e      Zded<   d Z	y)AddVolumeMountChangezvUpdates Volume Mounts set on the container.

  Attributes:
    new_mounts: Mounts to add to the adjusted container.
  r   r  
new_mountsc                    | j                   D ]4  }d|vsd|vrt        j                  d      |d   |j                  |d   <   6 |S )Nr  z
mount-pathz<Added Volume mounts must have a `volume` and a `mount-path`.)r  r   rF  r8  )r#   rA   rB   r<  s       r$   rC   z$AddVolumeMountChange.AdjustContainer  sX    		,e";++J
 	
 6;8_ieL12 ! r'   N)
r,   r-   r.   r/   r   r   r   r  rJ   rC   r!   r'   r$   r  r    s,     /@k.?.?/*+ r'   r  c                  ,    e Zd ZU dZded<   ded<   d Zy)SetServiceMeshChangea  Sets the service mesh annotation on the service template.

  Attributes:
    project: The project to use for the mesh when not specified in mesh_name.
    mesh: Mesh resource name in the format of MESH_NAME or
      projects/PROJECT/locations/global/meshes/MESH_NAME.
  r   r  	mesh_namec                    d| j                   v r| j                   nd| j                   d| j                    |j                  j                  t        j
                  <   |S )Nr2  z	projects/z/locations/global/meshes/)r  r  rE   r   r   MESH_ANNOTATIONr)   s     r$   r+   zSetServiceMeshChange.Adjust  sV     $..  	&??OP !!(":":;
 Or'   Nr{   r!   r'   r$   r  r    s     ,.r'   r  c                  `    e Zd ZU dZded<    ej                  e      Zded<   dZ	ded	<   d
 Z
y)PresetChangezSets the preset annotation on the service template.

  Attributes:
    type: The type of preset to use.
    config: The config to use for the preset.
    flatten: Whether to flatten the preset values into the service template.
  r   typer   rO  configTrW   flattenc                   g }t         j                  |j                  v r0t        j                  |j                  t         j                           }|rI|d   d   | j
                  k7  r4|j                  | j
                  | j                  | j                  d       n%| j
                  | j                  | j                  dg}t        j                  |      |j                  t         j                  <   |S )Nr   r  )r  r  r  )
r   PRESETS_ANNOTATIONr   r   r   r  r   r  r  r   r#   r*   presetss      r$   r+   zPresetChange.Adjust  s     G!!X%9%99

8//0J0JKLg71:f%2nn))KK\\ 	 ))KK\\ 	g
 8<zz'7JH334Or'   N)r,   r-   r.   r/   rJ   r   r   r   r  r  r+   r!   r'   r$   r  r    s5     	)/k//E&
E'4r'   r  c                  "    e Zd ZU dZded<   d Zy)RemovePresetsChangezRemoves one or more presets from annotation from the service metadata.

  Attributes:
    clear_presets: Whether to clear all presets.
  rW   clear_presetsc                    t        j                  |j                  j                  t        j
                  d            }|r*| j                  r|j                  t        j
                  = |S y y )Nz[])r   r   r   rd   r   r  r  r  s      r$   r+   zRemovePresetsChange.Adjust	  sY    jj  !;!;TBG 4%%


w99
:o &wr'   Nr{   r!   r'   r$   r  r    s     r'   r  )r,  MutableMapping[str, str]r-  rP  r.  rW   )r8  r  r9  rP  r.  rW   r:  r  )ru  rI   r  r   r  zrun_v1_messages.Probe)r/   
__future__r   r   r   r   r   r1   argparser  collections.abcr   r	   r
   r   r   rf   r   r  r   typestypingr   r   googlecloudsdk.api_lib.runr   r   r   r   r   r   googlecloudsdk.callioper   googlecloudsdk.command_lib.runr   r   r   r   r   $googlecloudsdk.command_lib.util.argsr   r   ,googlecloudsdk.generated_clients.apis.run.v1r   sixwith_metaclassABCMetar%  r   r4   r8   	dataclassr<   rN   rR   rT   ro   rw   r}   r   r   r   r   r   r   r   r   r   r   r   r   r  r
  r  r  r  r!  r0  r@  r5  rN  rX  ra  rw  r  r  r  r  r  r  r  r  r  r  r  rC  r  r  r  r  r  r  r   r%  r2  r3  r+  r7  r:  r@  rE  rJ  rO  rT  rY  r^  rp  rs  r  r  r  r  r  r  r  r  r  r  r  r  r!   r'   r$   <module>r     st   A & "  % ' 
   T T        9 * 1 / . 2 ( 5 9 4 : 2 < 9 H 
&C&&s{{F; *} M  d#*2 * $*Z"4
 d#0= 0 $0f*  d#/  $0 d#3  $> d# 6   $ 4 d/"| " 0"6 d#2  $  d#5  $  d#"7  $  d#%:  $  d#D!6 D $DN d#;3 ; $;| d#$1K $ $$6 d#%=  $& d#!9  $  d#$<  $B d#":  $  d#!m ! $!H d#)  $  d#.  $ 	3 	 E$/!( ! 0!"
!%
!#
! 
!!5 ,!5 	!5
 !5 $!5H: d#'1 ' $'T d#2/ 2 $2jD2 DN d#?, ? $?6//*8//d d#E0 E $E$ d#F1 F $F$ d#G2 G $G$ d#U+ U $Up d#.  $4 d#*  $ d#1  $   d#/  $0O
&	 d#c/ c $cLK2 K\.   d#)- ) $)X d#0  $  E$/%3 % 0%" E$/0  0"  d#.90 .9 $.9b d#"7  $  d#/  $ d#0  $ d#/  $  d#1  $  d#-  $  d#/  $  d#/  $  d#93 9 $9x d#	#8 	 $	 d#,2 , $,^ d#)  $ d#)  $* d#4  $  d#2  $< d#-"7 - $-` d#.  $. d#+  $. d#4  $0 d#1  $* d#0  $* d#!( ! $!H d#/  $r'   