
    n                         S r SSKJr  SSKJr  SSKJ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rS
r " S S\5      rS rg)zCLibrary for generating the files for local development environment.    )absolute_import)division)unicode_literalsN)builders)local)yaml_helper)yamlzg
apiVersion: skaffold/v2beta5
kind: Config
build:
  artifacts: []
deploy:
  kubectl:
    manifests: []
c                   *    \ rS rSrSrS rS rS rSrg)LocalRuntimeFiles(   z;Generates the developement environment files for a project.c                     Xl         g)zMInitialize LocalRuntimeFiles.

Args:
  settings: Local development settings.
N	_settings)selfsettingss     2lib/googlecloudsdk/command_lib/code/local_files.py__init__LocalRuntimeFiles.__init__+   s	     N    c           
         U R                   R                  (       a  [        U R                   R                  [        R                  5      (       a[  U R                   R                  R                  S5      (       d  [        S5      e[        U R                   R                  SS 5      S-  nOU R                   R                  n[        SU5      nOSn[        R                  " U R                   R                  U R                   R                  U R                   R                  U R                   R                  U R                   R                  U R                   R                  UU R                   R                   5      [        R"                  " U R                   R                  U R                   R                  U R                   R$                  U R                   R&                  U R                   R(                  5      /nSn[        U R                   R*                  [        R,                  5      (       ai  [        R.                  " [0        R2                  " [        R4                  U R                   R*                  R6                  5      5      nUR9                  U5        Oh[        U R                   R*                  [        R:                  5      (       a5  [        R.                  " [        R<                  5      nUR9                  U5        U R                   R>                  (       a\  U(       d  [        S5      e[        R@                  " U R                   R>                  URC                  5       5      nUR9                  U5        [E        U5      $ )zOCreate a kubernetes config file.

Returns:
  Text of a kubernetes config file.
mz7cpu limit must be defined as an integer or as millicpusNg     @@g?zKA credential generator must be defined when cloudsql instances are defined.)#r   cpu
isinstancesix	text_typeendswith
ValueErrorintminr   AppContainerGeneratorservice_nameimageenv_varsenv_vars_secretsmemoryreadiness_probeSecretsGeneratorvolumes_secrets	namespaceallow_secret_manager
credentialServiceAccountSettingCredentialGenerator	functoolspartialGetServiceAccountSecretnameappend#ApplicationDefaultCredentialSettingGetUserCredentialcloudsql_instancesCloudSqlProxyGeneratorGetInfo_GenerateKubeConfigs)r   user_cpucpu_requestcode_generatorscredential_generatorcloudsql_proxys         r   KubernetesConfig"LocalRuntimeFiles.KubernetesConfig3   sx    ~~	DNN&&	6	6~~!!**3// ' ( (t~~))#2./&8>>%%X&kk 	##NN'')=)=NN##T^^%D%DNN!!4>>#5#5{NN**		,
 	t~~::#~~>>#~~==#~~77#~~BB		DO  $..++U-H-HII"66


E99 NN55::<= 12	DNN--==
? 
?"66u7N7NO12~~((! 2 3 	333
..
+
+-A-I-I-KMn^,00r   c                    [         R                  " [        5      n[        R                  " US[
        S9nUR                  U5        SU R                  R                  0n[        R                  " U R                  R                  R                  S5      5      US'   [        U R                  R                  [        R                   5      (       a  SU R                  R                  R                  0US'   U R                  R                  R"                  (       a  S/US   S	'   S
0 0US'   U R                  R                  R$                  (       a  SUS   S'   OcU R                  R                  R'                  U R                  R                  5      nS[        R                  " UR                  S5      5      0US'   [        R                  " US[
        S9nUR                  U5        U R                  R(                  (       ai  SU R                  R*                  SU R                  R(                  S.nU R                  R,                  (       a  U R                  R,                  US'   U/US'   [         R.                  " U5      $ )zCreate a skaffold yaml file.

Args:
  kubernetes_file_path: Path to the kubernetes config file.

Returns:
  Text of the skaffold yaml file.
)deploykubectl	manifests)constructorr#   unicode_escapecontextbuilder
buildpackszGOOGLE_DEVMODE=1envautosyncTtrustBuilder
dockerfiledocker)build	artifactsservicei  )resourceTyperesourceNameport	localPortr*   portForward)r	   load_SKAFFOLD_TEMPLATEr   GetOrCreatelistr3   r   r#   r   ensure_textrG   encoder   rH   r   BuildpackBuilderdevmodetrustDockerfileRelPath
local_portr"   r*   dump)r   kubernetes_file_pathskaffold_yamlrD   artifactdockerfile_rel_pathrQ   port_forward_configs           r   SkaffoldConfig LocalRuntimeFiles.SkaffoldConfigg   s    II01M''9tMI)*--.H //%%&679HY $..(((*C*CDD
T^^++33 h| 
			'	');(<u%"B<				%	%15~. !NN22DD
..
 
 " oo1889IJKhx
 ''-4AIX~~  #..55~~00	 
	!	!+/>>+C+CK(&9%:mM"99]##r   r   N)	__name__
__module____qualname____firstlineno____doc__r   r?   ri   __static_attributes__ r   r   r   r   (   s    C21h6$r   r   c                    / nU  H"  nUR                  UR                  5       5        M$     U Vs/ s H  o3S   S:X  d  M  UPM     nn[        R                  " UU 5       H  u  pRUR	                  U5        M     U HK  n[
        R                  " US5      n[        R                  " UU 5       H  u  prUR                  U5        M     MM     [        R                  " U5      $ s  snf )zGenerate Kubernetes yaml configs.

Args:
  code_generators: Iterable of KubeConfigGenerator.

Returns:
  Iterable of dictionaries representing kubernetes yaml configs.
kind
Deployment)spectemplateru   
containers)
extendCreateConfigs	itertoolsproductModifyDeploymentr   GetAllModifyContainerr	   dump_all)r<   kube_configscode_generatorconfigdeployments
deploymentrw   	containers           r   r9   r9      s     ,'n4467 ( ('&>\+If<   %.$5$5k6E%G j##J/%G  j##J$NPJ &/%6%6z7F&H!	$$Y/&H	   
|	$$s
   CC)ro   
__future__r   r   r   r/   rz   googlecloudsdk.command_lib.coder   r   r   googlecloudsdk.corer	   r   rY   objectr   r9   rq   r   r   <module>r      sE    J &  '   4 1 7 $ 
 u$ u$p%r   