
                             d Z ddlmZ ddlmZ ddlmZ ddl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  G d de	j&                  ej&                  ej(                        Zy)zCRemoves configuration properties from Policy Controller components.    )absolute_import)division)unicode_literalsN)protos)base)command)deployment_configs)flags)
exceptionsc                   :    e Zd ZdZdZdZed        Zd Zd Z	d Z
y)Removea  Removes configuration properties from Policy Controller components.

  Remove customizations of on-cluster components in Policy Controller. These
  components are managed as individual kubernetes deployments (e.g. 'admission')
  in the gatekeeper-system namespace.

  When removing a 'toleration' property, it must match exactly, including the
  key, value and effect flag (if originally specified).

  ## EXAMPLES

  To remove the replica count for a component:

    $ {command} admission replica-count

  To remove the replica count for a component across all fleet memberships:

    $ {command} admission replica-count --all-memberships

  To remove a toleration with key 'my-key' on a component:

    $ {command} admission toleration my-key

  To remove a toleration with key 'my-key' and 'my-value' on a component:

    $ {command} admission toleration my-key=my-value

  To remove a toleration with key 'my-key' and 'my-value' on a component, along
  with the effect 'NoSchedule':

    $ {command} admission toleration my-key=my-value --effect=NoSchedule

  To remove a memory limit:

    $ {command} audit memory-limit

  To remove a memory request:

    $ {command} mutation memory-request

  To remove a cpu limit:

    $ {command} admission cpu-limit

  To remove a cpu request:

    $ {command} audit cpu-request

  To remove the anti-affinity configuration:

    $ {command} admission pod-affinity
  policycontrollerc                 l   t        j                  |d      }|j                          |j                  dt        j
                  d       |j                  dt        j                  d       |j                  dt        j                  d d	       |j                  d
t        j                  dt               y )Nzremove deployment configuration
deploymentzwThe PolicyController deployment component (i.e, "admission",  "audit" or "mutation" from which to remove configuration.)choiceshelppropertyzProperty to be removed.valuez_This is only required to remove a toleration. It should not be included for any other property.)nargsdefaultr   z--effectzsApplies only to "toleration" property. To be removed, tolerations must match exactly, including the effect setting.)r   r   type)r
   	PocoFlagsadd_membershipsadd_argumentr   G8R_COMPONENTSSUPPORTED_PROPERTIESargparseOPTIONALK8S_SCHEDULING_OPTIONSstr)clsparser	cmd_flagss      Alib/surface/container/fleet/policycontroller/deployment/remove.pyArgszRemove.ArgsX   s    (IJI
))I	   //&  
 0   11A       c           	          | j                  |      }|j                         D ci c]  \  }}|| j                  ||       }}}| j                  |      S c c}}w N)
path_specsitemsremoveupdate_specs)selfargsspecspathspecupdated_specss         r$   Runz
Remove.Run}   s^    OOD!E8=8E*$dkk$%%   ]++s   Ac                    t        j                  |j                  j                  j                        }|j                  |j                  | j                  j                               }| j                  ||j                  |j                  |j                        ||j                  <   t        j                  | j                  j                  j                         |      }||j                  j                  _        |S r(   )r   additional_properties_to_dictr   policyControllerHubConfigdeploymentConfigsgetr   messages0PolicyControllerPolicyControllerDeploymentConfigset_deployment_configr   r   effectset_additional_propertiesPolicyControllerHubConfigDeploymentConfigsValue)r-   r1   r.   cfgsdeployment_cfgdcvs         r$   r+   zRemove.remove   s    //77IID XXFFHN
 !66

	D 
*
*//FFH$C ILD33EKr&   c                 J   |dk(  rt        j                  |||      S |t        j                  d      |t        j                  d      |dk(  r!t        j                  | j
                  |d       S |dk(  r!t        j                  | j
                  |d       S |dk(  r!t        j                  | j
                  |d       S |dk(  r!t        j                  | j
                  |d       S |dk(  rt        j                  |d       S |d	k(  r!t        j                  | j
                  |d       S y )
N
tolerationz:"value" argument only accepted when removing a toleration.z7"effect" flag only accepted when removing a toleration.z	cpu-limitzcpu-requestzmemory-limitzmemory-requestzreplica-countzpod-affinity)r   remove_tolerationr   Errorupdate_cpu_limitr9   update_cpu_requestupdate_mem_limitupdate_mem_requestupdate_replica_countupdate_pod_affinity)r-   rA   propr   r<   s        r$   r;   zRemove.set_deployment_config   s!   |)).%HH
F  
C  {((MM}**4==.$OO~((MM**4==.$OO,,^TBB~++DMM>4PP r&   N)__name__
__module____qualname____doc__feature_namemf_nameclassmethodr%   r3   r+   r;    r&   r$   r   r      s7    3j $,'" "H,.Qr&   r   )rQ   
__future__r   r   r   r   7googlecloudsdk.api_lib.container.fleet.policycontrollerr   3googlecloudsdk.command_lib.container.fleet.featuresr   =googlecloudsdk.command_lib.container.fleet.membershipfeaturesmf_base;googlecloudsdk.command_lib.container.fleet.policycontrollerr   r	   r   r
   googlecloudsdk.corer   UpdateCommandPocoCommandr   rU   r&   r$   <module>r_      sR    J &  '  J D Y O h M *SQT!6!68K8K SQr&   