
    /                        S r SSKrSSKrSSKJr  SSKJr  SSKJr  SSKJ	r
  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJ	r  SSKJr  SSKJr  SSKJr  SSKJr  SSS.rSrSrS r\R<                  " \R>                  R@                  \R>                  RB                  \R>                  RD                  5      \RF                   " S S\RH                  5      5       5       r%g)zCreate a release.    N)client_util)release)base)
exceptions)delivery_pipeline_util)deploy_policy_util)deploy_util)flags)promote_util)release_util)resource_args)log)	resources)files)timesz{description}a       To create a release with source located at storage URL `gs://bucket/object.zip`
    and the first rollout in the first target of the promotion sequence:

       $ {command} my-release --source=`gs://bucket/object.zip` --delivery-pipeline=my-pipeline --region=us-central1

    To create a release with source located at current directory
    and deploy a rollout to target prod :

      $ {command} my-release --delivery-pipeline=my-pipeline --region=us-central1 --to-target=prod

    The following command creates a release without a `skaffold.yaml` as input, and generates one
    for you:

      $ {command} my-release --delivery-pipeline=my-pipeline --region=us-central1 --from-k8s-manifest=path/to/kubernetes/k8.yaml

    The current UTC date and time on the machine running the gcloud command can
    also be included in the release name by adding $DATE and $TIME parameters:

      $ {command} 'my-release-$DATE-$TIME' --delivery-pipeline=my-pipeline --region=us-central1

    If the current UTC date and time is set to 2021-12-21 12:02, then the created release
    will have its name set as my-release-20211221-1202.

    When using these parameters, please be sure to wrap the release name in single quotes
    or else the template parameters will be overridden by environment variables.
    )DESCRIPTIONEXAMPLESr      c                 2   [         R                  " U SSS9  [        R                  " U 5        [        R                  " U 5        [        R
                  " U 5        [        R                  " U 5        [        R                  " U S5        [        R                  " U [        5        [        R                  " U [        5        [        R                  " U 5        [        R                  " U 5        [        R                  " U 5        [        R                  " U 5        [        R                  " U 5        [        R                   " U 5        [        R"                  " U 5        [        R$                  " U 5        [        R&                  " U 5        [        R(                  " U 5        g)zRegister flags for this command.

Args:
  parser: An argparse.ArgumentParser-like object. It is mocked out in order to
    capture some information, but behaves like an ArgumentParser.
T)
positionalrequiredzDescription of the release.N)r   AddReleaseResourceArgr
   AddGcsSourceStagingDirFlagAddImagesGroupAddIgnoreFileFlagAddToTargetFlagAddDescriptionAddAnnotationsFlag_RELEASEAddLabelsFlagAddDockerVersionAddHelmVersionAddKptVersionAddKubectlVersionAddKustomizeVersionAddSkaffoldVersionAddSkaffoldOrNativeSourcesAddInitialRolloutGroupAddDeployParametersFlagAddOverrideDeployPoliciesparsers    %lib/surface/deploy/releases/create.py_CommonArgsr.   I   s    %%fM""6*v&!v<=68,fh' vf&!F#6"""6*v&'!!&)    c                   8    \ rS rSrSr\r\S 5       rS r	S r
Srg)Created   z3Creates a new release, delivery pipeline qualified.c                     [        U 5        g )N)r.   r+   s    r-   ArgsCreate.Argsm   s
    r/   c                    S nUR                   nUc  gUR                  =(       dX    UR                  =(       dE    UR                  =(       d2    UR                  =(       d    UR
                  =(       d    UR                  nU(       d  UR                  c  gU" UR                  R                  5      nUbm  U[        R                  " 5       -
  [        R                  " [        S9::  a;  [        R                  R!                  SR#                  UR%                  S5      S95        g[&        R(                  R*                  UR                  4[&        R(                  R,                  UR                  4[&        R(                  R.                  UR                  4[&        R(                  R0                  UR                  4[&        R(                  R2                  UR
                  4[&        R(                  R4                  UR                  4/n/ nU Hj  u  pU	(       d  M  U" U	R                  5      nUc  M%  U[        R                  " 5       -
  [        R                  " [        S9::  d  MY  UR7                  U5        Ml     U(       aO  SR9                  U Vs/ s H  oR:                  PM     sn5      n
[        R                  R!                  SU
 S	35        ggs  snf )
z>Checks to see if a release is close to the maintenance window.c                     U c  g [         R                  " U 5      $ ! [         R                  [         R                  4 a     gf = f)z8Parses the maintenance dt, returning a datetime or None.N)r   ParseDateTimeDateTimeSyntaxErrorDateTimeValueError)dts    r-   _ParseDt0Create._CheckIfNearMaintenance.<locals>._ParseDtt   sC    	""2&&'')A)AB s    $AAN)daysa!  WARNING: This release's Skaffold version will be in maintenance mode beginning on {date}. After that you won't be able to create releases using this version of Skaffold.
https://cloud.google.com/deploy/docs/using-skaffold/select-skaffold#skaffold_version_deprecation_and_maintenance_policyz%Y-%m-%d)datez, z'WARNING: The versions used for tools: [z] will be in maintenance mode soon. After that you won't be able to create releases using these versions of the tools.
https://cloud.google.com/deploy/docs/select-tool-version)	conditiondockerVersionSupportedConditionhelmVersionSupportedConditionkptVersionSupportedCondition kubectlVersionSupportedCondition"kustomizeVersionSupportedCondition!skaffoldVersionSupportedConditionskaffoldSupportedConditionmaintenanceModeTimer   Nowdatetime	timedelta_MAINTENANCE_WARNING_DAYSr   statusPrintformatstrftimer   ToolsDOCKERHELMKPTKUBECTL	KUSTOMIZESKAFFOLDappendjoinvalue)selfrelease_objr<   release_conditionhas_tool_versionsmaintenance_dt$tools_supported_condition_to_processtools_almost_in_maintenancetoolr@   joineds              r-   _CheckIfNearMaintenanceCreate._CheckIfNearMaintenanceq   s    $--  	99 	?::	?99	? ==	? ??		?
 >>  		5	5	=

6
6
J
Jn 
$uyy{*%>?@ 	

& '-f#,,Z8 '- '
	
 
 %%==	

 ##;;	

 ""::	

 &&>>	

 ((@@	

 ''??	
+,(4 #%?	 = =>n

$uyy{*%>?@ 	$**40 @ #yy1LM1L**1LMNf	jj3F8 <E E #Ms   	K
c                 |
   UR                   (       a(  UR                  (       a  [        R                  " SS5      e[        R
                  " UR                  R                  R                  5      UR                  R                  l        UR                  R                  R                  5       n[        R                  " UR                  5       R                  5       5      nSR                  UR                  5       5      n[        R                  " X45        [        R                   " U5      nUR"                  (       a  [$        R&                  R)                  UR"                  5      (       a  UR*                  S:X  a  SOSn[,        R.                  " XQR"                  5      (       d'  [0        R2                  " SUR"                   SU S	35      e[$        R&                  R5                  [$        R&                  R7                  UR"                  5      [$        R&                  R7                  U5      5      Ul        [        R8                  " U5      n[        R:                  " XWUR"                  UR<                  5      n[        R>                  " 5       n	[        R@                  " S#0 SU_S
URB                  _SURD                  _SURF                  _SURH                  _SURJ                  _SURL                  _SURN                  _SURP                  _SURR                  _SURT                  _SURV                  _SUR"                  _SURY                  5       S   _SURZ                  _SUR\                  _SUR^                  _SU_SUR`                  _SU_6n
[b        Rd                  " U	Rf                  U
[b        Rh                  Rj                  URl                  URn                  5        U	Rq                  X*5      n[r        Rt                  Rw                  URx                  SS9n[z        R|                  " 5       R                  X5        [        R                  R                  S R                  UR                  5       5      5        [        R>                  " 5       R                  UR                  5       5      nU R                  U5        UR                   (       a  U$ UR                  5       n[        R                  " XR                  5      n[        R                  " UUUR                  S!UR                  UR                  UR                  US"9nUU4$ )$zThis is what gets called when the user runs this command.

Args:
  args: All the arguments that were provided to this command invocation.

Returns:
  The release and rollout created.
z--disable-initial-rolloutz--to-targetzCannot create release {}..zcurrent working directorysourcezThe skaffold file z could not be found in the z*. Please enter a valid Skaffold file path.gcs_source_staging_dirignore_fileimagesbuild_artifactsdescriptiondocker_versionhelm_versionkpt_versionkubectl_versionkustomize_versionskaffold_versionskaffold_filelocationlocationsIdpipeline_uuidfrom_k8s_manifestfrom_run_manifestpipeline_objdeploy_parametersnative_config_usedz)clouddeploy.projects.locations.operations)
collectionz Created Cloud Deploy release {}.T)	is_createlabelsannotationsstarting_phase_idoverride_deploy_policies )Ndisable_initial_rollout	to_targetc_exceptionsConflictingArgumentsExceptionr   RenderPatternCONCEPTSparsed_argsr   Parser   GetPipelineParentRelativeNamerO   ThrowIfPipelineSuspendedGetActualSourcert   ospathisabsrh   r   IsDirAncestorOfcore_exceptionsErrorrelpathabspathGetConfigCheckModeFromArgsVerifyConfigsconfig_fileReleaseClientCreateReleaseConfigri   rj   rk   rl   rm   rn   ro   rp   rq   rr   rs   AsDictuidrx   ry   r{   r	   SetMetadatamessagesResourceTypeRELEASEr   r   r1   r   REGISTRYParseRelativeNamenamer   OperationsClientWaitForOperationr   rM   rN   NameGetrd   r   CreateDeployPolicyNamesFromIDsr   r   Promoteinitial_rollout_labelsinitial_rollout_annotationsinitial_rollout_phase_id)r[   argsrelease_refrz   failed_activity_msgactual_sourcesource_descriptionconfig_check_moder|   clientrelease_config	operationoperation_refr\   pipeline_refpoliciesrollout_resources                    r-   Run
Create.Run   s    ##66
%}  )5(B(B!!)))DMM% --''--/K)55))+L 6<<  " 33 !006M bggmmD,>,>??
 *.);
%  ""=2D2DEE## !3!3 4 5"##MO
 	
 77??
''//$,,
-rww}/Md %??E%33$*<*<d>N>N ""$F!55 #:: $$ {{	
 ,, $$ ** && $$ ,, 00 .. (( ##%m4 #&&  00!" 00#$ "%& 00'( .)N.   (( k:I&&88#N 9 M   "33IMJJ*11+2B2B2DE '')--k.F.F.HIK  -## %%'L!@@33H $++**4477!)	 (((r/   r   N)__name__
__module____qualname____firstlineno____doc___DETAILED_HELPdetailed_helpstaticmethodr4   rd   r   __static_attributes__r   r/   r-   r1   r1   d   s+    
 < - _Bq)r/   r1   )&r   rJ   os.pathr   "googlecloudsdk.api_lib.clouddeployr   r   googlecloudsdk.callioper   r   r   !googlecloudsdk.command_lib.deployr   r   r	   r
   r   r   r   googlecloudsdk.corer   r   r   googlecloudsdk.core.utilr   r   r   r   rL   r.   ReleaseTracksReleaseTrackALPHABETAGADefaultUniverseOnlyCreateCommandr1   r   r/   r-   <module>r      s       : 6 ( > D @ 9 3 : : ; = # ) * * #<  *6 T..33T5F5F5I5I [)T [) [)r/   