Skip to content

Commit cc4a542

Browse files
FumingZhangCopilot
andauthored
[AKS] Add command options to toggle the run command feature on or off (#31854)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent d60e9d2 commit cc4a542

File tree

7 files changed

+2390
-2
lines changed

7 files changed

+2390
-2
lines changed

src/azure-cli/azure/cli/command_modules/acs/_help.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,9 @@
454454
type: string
455455
short-summary: Path to a file containing up to 10 blank line separated certificates. Only valid for Linux nodes.
456456
long-summary: These certificates are used by Custom CA Trust feature and will be added to trust stores of nodes.
457+
- name: --disable-run-command
458+
type: bool
459+
short-summary: Disable Run command feature for the cluster.
457460
- name: --enable-defender
458461
type: bool
459462
short-summary: Enable Microsoft Defender security profile.
@@ -915,6 +918,12 @@
915918
type: string
916919
short-summary: Path to a file containing up to 10 blank line separated certificates. Only valid for Linux nodes.
917920
long-summary: These certificates are used by Custom CA Trust feature and will be added to trust stores of nodes.
921+
- name: --enable-run-command
922+
type: bool
923+
short-summary: Enable Run command feature for the cluster.
924+
- name: --disable-run-command
925+
type: bool
926+
short-summary: Disable Run command feature for the cluster.
918927
- name: --defender-config
919928
type: string
920929
short-summary: Path to JSON file containing Microsoft Defender profile configurations.

src/azure-cli/azure/cli/command_modules/acs/_params.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ def load_arguments(self, _):
415415
c.argument('image_cleaner_interval_hours', type=int)
416416
c.argument('http_proxy_config')
417417
c.argument('custom_ca_trust_certificates', options_list=["--custom-ca-trust-certificates", "--ca-certs"], help="path to file containing list of new line separated CAs")
418+
c.argument('disable_run_command', action='store_true')
418419
c.argument('enable_keda', action='store_true')
419420
c.argument('enable_vpa', action='store_true', help='enable vertical pod autoscaler for cluster')
420421
c.argument('enable_azure_service_mesh',
@@ -652,6 +653,8 @@ def load_arguments(self, _):
652653
c.argument('image_cleaner_interval_hours', type=int)
653654
c.argument('http_proxy_config')
654655
c.argument('custom_ca_trust_certificates', options_list=["--custom-ca-trust-certificates", "--ca-certs"], validator=validate_custom_ca_trust_certificates, help="path to file containing list of new line separated CAs")
656+
c.argument('enable_run_command', action='store_true')
657+
c.argument('disable_run_command', action='store_true')
655658
c.argument('enable_keda', action='store_true')
656659
c.argument('disable_keda', action='store_true')
657660
c.argument('enable_vpa', action='store_true', help='enable vertical pod autoscaler for cluster')

src/azure-cli/azure/cli/command_modules/acs/custom.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,7 @@ def aks_create(
694694
enable_keda=False,
695695
enable_vpa=False,
696696
custom_ca_trust_certificates=None,
697+
disable_run_command=False,
697698
# advanced networking
698699
enable_acns=None,
699700
disable_acns_observability=None,
@@ -913,6 +914,8 @@ def aks_update(
913914
disable_force_upgrade=False,
914915
upgrade_override_until=None,
915916
custom_ca_trust_certificates=None,
917+
enable_run_command=False,
918+
disable_run_command=False,
916919
# advanced networking
917920
disable_acns=None,
918921
enable_acns=None,

src/azure-cli/azure/cli/command_modules/acs/managed_cluster_decorator.py

Lines changed: 113 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,71 @@ def get_custom_ca_trust_certificates(self) -> Union[List[bytes], None]:
925925
)
926926
return certs
927927

928+
def _get_enable_run_command(self, enable_validation: bool = False) -> bool:
929+
"""Internal function to obtain the value of enable_run_command.
930+
:return: bool
931+
"""
932+
enable_run_command = self.raw_param.get("enable_run_command")
933+
934+
# In create mode, try to read the property value corresponding to the parameter from the `mc` object.
935+
if self.decorator_mode == DecoratorMode.CREATE:
936+
if (
937+
self.mc and
938+
hasattr(self.mc, "api_server_access_profile") and # backward compatibility
939+
self.mc.api_server_access_profile and
940+
self.mc.api_server_access_profile.disable_run_command is not None
941+
):
942+
enable_run_command = not self.mc.api_server_access_profile.disable_run_command
943+
944+
# validation
945+
if enable_validation:
946+
if enable_run_command and self._get_disable_run_command(enable_validation=False):
947+
raise MutuallyExclusiveArgumentError(
948+
"Cannot specify --enable-run-command and --disable-run-command at the same time."
949+
)
950+
951+
return enable_run_command
952+
953+
def get_enable_run_command(self) -> bool:
954+
"""Obtain the value of enable_run_command.
955+
This function will verify the parameter by default. If both enable_run_command and disable_run_command are
956+
specified, raise a MutuallyExclusiveArgumentError.
957+
:return: bool
958+
"""
959+
return self._get_enable_run_command(enable_validation=True)
960+
961+
def _get_disable_run_command(self, enable_validation: bool = False) -> bool:
962+
"""Internal function to obtain the value of disable_run_command.
963+
:return: bool
964+
"""
965+
disable_run_command = self.raw_param.get("disable_run_command")
966+
967+
# In create mode, try to read the property value corresponding to the parameter from the `mc` object.
968+
if self.decorator_mode == DecoratorMode.CREATE:
969+
if (
970+
self.mc and
971+
hasattr(self.mc, "api_server_access_profile") and # backward compatibility
972+
self.mc.api_server_access_profile and
973+
self.mc.api_server_access_profile.disable_run_command is not None
974+
):
975+
disable_run_command = self.mc.api_server_access_profile.disable_run_command
976+
977+
# validation
978+
if enable_validation:
979+
if disable_run_command and self._get_enable_run_command(enable_validation=False):
980+
raise MutuallyExclusiveArgumentError(
981+
"Cannot specify --enable-run-command and --disable-run-command at the same time."
982+
)
983+
return disable_run_command
984+
985+
def get_disable_run_command(self) -> bool:
986+
"""Obtain the value of disable_run_command.
987+
This function will verify the parameter by default. If both enable_run_command and disable_run_command
988+
are specified, raise a MutuallyExclusiveArgumentError.
989+
:return: bool
990+
"""
991+
return self._get_disable_run_command(enable_validation=True)
992+
928993
def get_snapshot_controller(self) -> Optional[ManagedClusterStorageProfileSnapshotController]:
929994
"""Obtain the value of storage_profile.snapshot_controller
930995
@@ -6492,6 +6557,23 @@ def set_up_custom_ca_trust_certificates(self, mc: ManagedCluster) -> ManagedClus
64926557

64936558
return mc
64946559

6560+
def set_up_run_command(self, mc: ManagedCluster) -> ManagedCluster:
6561+
"""Set up run command for the ManagedCluster object.
6562+
:return: the ManagedCluster object
6563+
"""
6564+
self._ensure_mc(mc)
6565+
6566+
disable_run_command = self.context.get_disable_run_command()
6567+
if disable_run_command:
6568+
if mc.api_server_access_profile is None:
6569+
mc.api_server_access_profile = self.models.ManagedClusterAPIServerAccessProfile(
6570+
disable_run_command=True
6571+
)
6572+
else:
6573+
mc.api_server_access_profile.disable_run_command = True
6574+
6575+
return mc
6576+
64956577
def set_up_api_server_access_profile(self, mc: ManagedCluster) -> ManagedCluster:
64966578
"""Set up api server access profile and fqdn subdomain for the ManagedCluster object.
64976579
@@ -7004,7 +7086,8 @@ def construct_mc_profile_default(self, bypass_restore_defaults: bool = False) ->
70047086
mc = self.set_up_ingress_web_app_routing(mc)
70057087
# set up custom ca trust certificates
70067088
mc = self.set_up_custom_ca_trust_certificates(mc)
7007-
7089+
# set up run command
7090+
mc = self.set_up_run_command(mc)
70087091
# setup k8s support plan
70097092
mc = self.set_up_k8s_support_plan(mc)
70107093
# set up azure monitor metrics profile
@@ -8519,6 +8602,33 @@ def update_custom_ca_trust_certificates(self, mc: ManagedCluster) -> ManagedClus
85198602

85208603
return mc
85218604

8605+
def update_run_command(self, mc: ManagedCluster) -> ManagedCluster:
8606+
"""Update run command for the ManagedCluster object.
8607+
8608+
:return: the ManagedCluster object
8609+
"""
8610+
self._ensure_mc(mc)
8611+
8612+
enable_run_command = self.context.get_enable_run_command()
8613+
disable_run_command = self.context.get_disable_run_command()
8614+
if enable_run_command or disable_run_command:
8615+
if mc.api_server_access_profile is None:
8616+
mc.api_server_access_profile = self.models.ManagedClusterAPIServerAccessProfile(
8617+
disable_run_command=(
8618+
not enable_run_command
8619+
if enable_run_command or disable_run_command
8620+
else None
8621+
)
8622+
)
8623+
else:
8624+
mc.api_server_access_profile.disable_run_command = (
8625+
not enable_run_command
8626+
if enable_run_command or disable_run_command
8627+
else None
8628+
)
8629+
8630+
return mc
8631+
85228632
def update_azure_monitor_profile(self, mc: ManagedCluster) -> ManagedCluster:
85238633
"""Update azure monitor profile for the ManagedCluster object.
85248634
:return: the ManagedCluster object
@@ -9019,6 +9129,8 @@ def update_mc_profile_default(self) -> ManagedCluster:
90199129
mc = self.update_auto_upgrade_profile(mc)
90209130
# update custom ca trust certificates
90219131
mc = self.update_custom_ca_trust_certificates(mc)
9132+
# update run command
9133+
mc = self.update_run_command(mc)
90229134
# update identity
90239135
mc = self.update_identity(mc)
90249136
# update addon profiles

0 commit comments

Comments
 (0)