Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/azure-cli/azure/cli/command_modules/acs/_consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING = "userDefinedRouting"
CONST_OUTBOUND_TYPE_MANAGED_NAT_GATEWAY = "managedNATGateway"
CONST_OUTBOUND_TYPE_USER_ASSIGNED_NAT_GATEWAY = "userAssignedNATGateway"
CONST_OUTBOUND_TYPE_NONE = "none"

# load balancer backend pool type
CONST_LOAD_BALANCER_BACKEND_POOL_TYPE_NODE_IP = "nodeIP"
Expand Down Expand Up @@ -206,6 +207,10 @@
CONST_PRIVATE_DNS_ZONE_CONTRIBUTOR_ROLE = "Private DNS Zone Contributor"
CONST_DNS_ZONE_CONTRIBUTOR_ROLE = "DNS Zone Contributor"

# consts for network isolated cluster
CONST_ARTIFACT_SOURCE_DIRECT = "Direct"
CONST_ARTIFACT_SOURCE_CACHE = "Cache"


# consts for decorator pattern
class DecoratorMode(Enum):
Expand Down
20 changes: 18 additions & 2 deletions src/azure-cli/azure/cli/command_modules/acs/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
- name: --outbound-type
type: string
short-summary: How outbound traffic will be configured for a cluster.
long-summary: Select between loadBalancer, userDefinedRouting, managedNATGateway and userAssignedNATGateway. If not set, defaults to type loadBalancer. Requires --vnet-subnet-id to be provided with a preconfigured route table and --load-balancer-sku to be Standard.
long-summary: Select between loadBalancer, userDefinedRouting, managedNATGateway, userAssignedNATGateway and none. If not set, defaults to type loadBalancer. Requires --vnet-subnet-id to be provided with a preconfigured route table and --load-balancer-sku to be Standard.
- name: --auto-upgrade-channel
type: string
short-summary: Specify the upgrade channel for autoupgrade.
Expand Down Expand Up @@ -563,6 +563,14 @@
- name: --if-none-match
type: string
short-summary: Set to '*' to allow a new cluster to be created, but to prevent updating an existing cluster. Other values will be ignored.
- name: --bootstrap-artifact-source
type: string
short-summary: Configure artifact source when bootstraping the cluster.
long-summary: |
The artifacts include the addon image. Use "Direct" to download artifacts from MCR, "Cache" to downalod artifacts from Azure Container Registry.
- name: --bootstrap-container-registry-resource-id
type: string
short-summary: Configure container registry resource ID. Must use "Cache" as bootstrap artifact source.

examples:
- name: Create a Kubernetes cluster with an existing SSH public key.
Expand Down Expand Up @@ -732,7 +740,7 @@
- name: --outbound-type
type: string
short-summary: How outbound traffic will be configured for a cluster.
long-summary: This option will change the way how the outbound connections are managed in the AKS cluster. Available options are loadbalancer, managedNATGateway, userAssignedNATGateway, userDefinedRouting. For custom vnet, loadbalancer, userAssignedNATGateway and userDefinedRouting are supported. For aks managed vnet, loadbalancer, managedNATGateway and userDefinedRouting are supported.
long-summary: This option will change the way how the outbound connections are managed in the AKS cluster. Available options are loadbalancer, managedNATGateway, userAssignedNATGateway, userDefinedRouting and none. For custom vnet, loadbalancer, userAssignedNATGateway and userDefinedRouting are supported. For aks managed vnet, loadbalancer, managedNATGateway and userDefinedRouting are supported.
- name: --auto-upgrade-channel
type: string
short-summary: Specify the upgrade channel for autoupgrade.
Expand Down Expand Up @@ -991,6 +999,14 @@
- name: --if-none-match
type: string
short-summary: Set to '*' to allow a new cluster to be created, but to prevent updating an existing cluster. Other values will be ignored.
- name: --bootstrap-artifact-source
type: string
short-summary: Configure artifact source when bootstraping the cluster.
long-summary: |
The artifacts include the addon image. Use "Direct" to download artifacts from MCR, "Cache" to downalod artifacts from Azure Container Registry.
- name: --bootstrap-container-registry-resource-id
type: string
short-summary: Configure container registry resource ID. Must use "Cache" as bootstrap artifact source.
examples:
- name: Reconcile the cluster back to its current state.
text: az aks update -g MyResourceGroup -n MyManagedCluster
Expand Down
35 changes: 30 additions & 5 deletions src/azure-cli/azure/cli/command_modules/acs/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
CONST_OS_SKU_WINDOWS2019, CONST_OS_SKU_WINDOWS2022,
CONST_OUTBOUND_TYPE_LOAD_BALANCER, CONST_OUTBOUND_TYPE_MANAGED_NAT_GATEWAY,
CONST_OUTBOUND_TYPE_USER_ASSIGNED_NAT_GATEWAY,
CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING, CONST_PATCH_UPGRADE_CHANNEL,
CONST_RAPID_UPGRADE_CHANNEL, CONST_SCALE_DOWN_MODE_DEALLOCATE,
CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING, CONST_OUTBOUND_TYPE_NONE,
CONST_PATCH_UPGRADE_CHANNEL, CONST_RAPID_UPGRADE_CHANNEL, CONST_SCALE_DOWN_MODE_DEALLOCATE,
CONST_SCALE_DOWN_MODE_DELETE, CONST_SCALE_SET_PRIORITY_REGULAR,
CONST_SCALE_SET_PRIORITY_SPOT, CONST_SPOT_EVICTION_POLICY_DEALLOCATE,
CONST_SPOT_EVICTION_POLICY_DELETE, CONST_STABLE_UPGRADE_CHANNEL,
Expand All @@ -48,7 +48,9 @@
CONST_AZURE_SERVICE_MESH_INGRESS_MODE_EXTERNAL,
CONST_AZURE_SERVICE_MESH_INGRESS_MODE_INTERNAL,
CONST_NRG_LOCKDOWN_RESTRICTION_LEVEL_READONLY,
CONST_NRG_LOCKDOWN_RESTRICTION_LEVEL_UNRESTRICTED)
CONST_NRG_LOCKDOWN_RESTRICTION_LEVEL_UNRESTRICTED,
CONST_ARTIFACT_SOURCE_DIRECT,
CONST_ARTIFACT_SOURCE_CACHE)
from azure.cli.command_modules.acs.azurecontainerstorage._consts import (
CONST_ACSTOR_ALL,
CONST_DISK_TYPE_EPHEMERAL_VOLUME_ONLY,
Expand Down Expand Up @@ -100,7 +102,8 @@
validate_disable_windows_outbound_nat,
validate_crg_id,
validate_azure_service_mesh_revision,
validate_message_of_the_day)
validate_message_of_the_day,
validate_bootstrap_container_registry_resource_id)
from azure.cli.core.commands.parameters import (
edge_zone_type, file_type, get_enum_type,
get_resource_name_completion_list, get_three_state_flag, name_type,
Expand Down Expand Up @@ -161,7 +164,7 @@
network_plugin_modes = [CONST_NETWORK_PLUGIN_MODE_OVERLAY]
network_dataplanes = [CONST_NETWORK_DATAPLANE_AZURE, CONST_NETWORK_DATAPLANE_CILIUM]
network_policies = [CONST_NETWORK_POLICY_AZURE, CONST_NETWORK_POLICY_CALICO, CONST_NETWORK_POLICY_CILIUM, CONST_NETWORK_POLICY_NONE]
outbound_types = [CONST_OUTBOUND_TYPE_LOAD_BALANCER, CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING, CONST_OUTBOUND_TYPE_MANAGED_NAT_GATEWAY, CONST_OUTBOUND_TYPE_USER_ASSIGNED_NAT_GATEWAY]
outbound_types = [CONST_OUTBOUND_TYPE_LOAD_BALANCER, CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING, CONST_OUTBOUND_TYPE_MANAGED_NAT_GATEWAY, CONST_OUTBOUND_TYPE_USER_ASSIGNED_NAT_GATEWAY, CONST_OUTBOUND_TYPE_NONE]
auto_upgrade_channels = [
CONST_RAPID_UPGRADE_CHANNEL,
CONST_STABLE_UPGRADE_CHANNEL,
Expand Down Expand Up @@ -267,6 +270,11 @@
CONST_EPHEMERAL_NVME_PERF_TIER_STANDARD,
]

bootstrap_artifact_source_types = [
CONST_ARTIFACT_SOURCE_DIRECT,
CONST_ARTIFACT_SOURCE_CACHE,
]


def load_arguments(self, _):

Expand Down Expand Up @@ -372,6 +380,15 @@ def load_arguments(self, _):
options_list=["--enable-azure-service-mesh", "--enable-asm"],
action='store_true')
c.argument("revision", validator=validate_azure_service_mesh_revision)
c.argument(
"bootstrap_artifact_source",
arg_type=get_enum_type(bootstrap_artifact_source_types),
default=CONST_ARTIFACT_SOURCE_DIRECT,
)
c.argument(
"bootstrap_container_registry_resource_id",
validator=validate_bootstrap_container_registry_resource_id,
)
# addons
c.argument('enable_addons', options_list=['--enable-addons', '-a'])
c.argument('workspace_resource_id')
Expand Down Expand Up @@ -563,6 +580,14 @@ def load_arguments(self, _):
c.argument('enable_force_upgrade', action='store_true')
c.argument('disable_force_upgrade', action='store_true', validator=validate_force_upgrade_disable_and_enable_parameters)
c.argument('upgrade_override_until')
c.argument(
"bootstrap_artifact_source",
arg_type=get_enum_type(bootstrap_artifact_source_types),
)
c.argument(
"bootstrap_container_registry_resource_id",
validator=validate_bootstrap_container_registry_resource_id,
)
# addons
c.argument('enable_secret_rotation', action='store_true')
c.argument('disable_secret_rotation', action='store_true', validator=validate_keyvault_secrets_provider_disable_and_enable_parameters)
Expand Down
9 changes: 9 additions & 0 deletions src/azure-cli/azure/cli/command_modules/acs/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -835,3 +835,12 @@ def validate_message_of_the_day(namespace):
if namespace.os_type is not None and namespace.os_type != "Linux":
raise ArgumentUsageError(
'--message-of-the-day can only be set for linux nodepools')


def validate_bootstrap_container_registry_resource_id(namespace):
container_registry_resource_id = namespace.bootstrap_container_registry_resource_id
if container_registry_resource_id is None or container_registry_resource_id == '':
return
from msrestazure.tools import is_valid_resource_id
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

msrestazure is deprecated. This import is migrated to azure.mgmt.core.tools.is_valid_resource_id by #31603.

if not is_valid_resource_id(container_registry_resource_id):
raise InvalidArgumentValueError("--bootstrap-container-registry-resource-id is not a valid Azure resource ID.")
7 changes: 7 additions & 0 deletions src/azure-cli/azure/cli/command_modules/acs/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
CONST_AZURE_SERVICE_MESH_UPGRADE_COMMAND_ROLLBACK,
CONST_AZURE_SERVICE_MESH_MODE_ISTIO,
CONST_MANAGED_CLUSTER_SKU_TIER_PREMIUM,
CONST_ARTIFACT_SOURCE_DIRECT,
)
from azure.cli.command_modules.acs._polling import RunCommandLocationPolling
from azure.cli.command_modules.acs._helpers import get_snapshot_by_snapshot_id, check_is_private_link_cluster
Expand Down Expand Up @@ -578,6 +579,9 @@ def aks_create(
enable_acns=None,
disable_acns_observability=None,
disable_acns_security=None,
# network isoalted cluster
bootstrap_artifact_source=CONST_ARTIFACT_SOURCE_DIRECT,
bootstrap_container_registry_resource_id=None,
# addons
enable_addons=None,
workspace_resource_id=None,
Expand Down Expand Up @@ -782,6 +786,9 @@ def aks_update(
enable_acns=None,
disable_acns_observability=None,
disable_acns_security=None,
# network isoalted cluster
bootstrap_artifact_source=None,
bootstrap_container_registry_resource_id=None,
# addons
enable_secret_rotation=False,
disable_secret_rotation=False,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ aks create:
nrg_lockdown_restriction_level:
rule_exclusions:
- option_length_too_long
bootstrap_artifact_source:
rule_exclusions:
- option_length_too_long
bootstrap_container_registry_resource_id:
rule_exclusions:
- option_length_too_long

aks enable-addons:
parameters:
Expand Down Expand Up @@ -174,6 +180,12 @@ aks update:
nrg_lockdown_restriction_level:
rule_exclusions:
- option_length_too_long
bootstrap_artifact_source:
rule_exclusions:
- option_length_too_long
bootstrap_container_registry_resource_id:
rule_exclusions:
- option_length_too_long
aks nodepool add:
parameters:
disable_windows_outbound_nat:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
CONST_OUTBOUND_TYPE_MANAGED_NAT_GATEWAY,
CONST_OUTBOUND_TYPE_USER_ASSIGNED_NAT_GATEWAY,
CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING,
CONST_OUTBOUND_TYPE_NONE,
CONST_PRIVATE_DNS_ZONE_NONE,
CONST_PRIVATE_DNS_ZONE_SYSTEM,
CONST_AZURE_KEYVAULT_NETWORK_ACCESS_PRIVATE,
Expand All @@ -39,6 +40,7 @@
CONST_AZURE_SERVICE_MESH_UPGRADE_COMMAND_ROLLBACK,
CONST_PRIVATE_DNS_ZONE_CONTRIBUTOR_ROLE,
CONST_DNS_ZONE_CONTRIBUTOR_ROLE,
CONST_ARTIFACT_SOURCE_CACHE,
)
from azure.cli.command_modules.acs._helpers import (
check_is_managed_aad_cluster,
Expand Down Expand Up @@ -2147,8 +2149,8 @@ def _get_outbound_type(
CONST_OUTBOUND_TYPE_LOAD_BALANCER.

This function supports the option of enable_validation. When enabled, if the value of outbound_type is
CONST_OUTBOUND_TYPE_LOAD_BALANCER,CONST_OUTBOUND_TYPE_MANAGED_NAT_GATEWAY, CONST_OUTBOUND_TYPE_USER_ASSIGNED_NAT_GATEWAY or
CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING, the following checks will be performed. If load_balancer_sku is set
CONST_OUTBOUND_TYPE_LOAD_BALANCER, CONST_OUTBOUND_TYPE_MANAGED_NAT_GATEWAY, CONST_OUTBOUND_TYPE_USER_ASSIGNED_NAT_GATEWAY
CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING or CONST_OUTBOUND_TYPE_NONE, the following checks will be performed. If load_balancer_sku is set
to basic, an InvalidArgumentValueError will be raised. If vnet_subnet_id is not assigned,
a RequiredArgumentMissingError will be raised. If any of load_balancer_managed_outbound_ip_count,
This function supports the option of read_only. When enabled, it will skip dynamic completion and validation.
Expand Down Expand Up @@ -2185,11 +2187,11 @@ def _get_outbound_type(
CONST_OUTBOUND_TYPE_MANAGED_NAT_GATEWAY,
CONST_OUTBOUND_TYPE_USER_ASSIGNED_NAT_GATEWAY,
CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING,
"none"
CONST_OUTBOUND_TYPE_NONE,
]:
raise InvalidArgumentValueError(
"Invalid outbound type, supported values are loadBalancer, managedNATGateway, userAssignedNATGateway and "
"userDefinedRouting. Please refer to "
"Invalid outbound type, supported values are loadBalancer, managedNATGateway, userAssignedNATGateway, "
"userDefinedRouting and none. Please refer to "
"https://learn.microsoft.com/en-us/azure/aks/egress-outboundtype#updating-outboundtype-after-cluster-creation " # pylint:disable=line-too-long
"for more details."
)
Expand Down Expand Up @@ -5248,6 +5250,16 @@ def get_if_none_match(self) -> Union[str, None]:
# this parameter does not need validation
return self.raw_param.get("if_none_match")

def get_bootstrap_artifact_source(self) -> Union[str, None]:
"""Obtain the value of bootstrap_artifact_source.
"""
return self.raw_param.get("bootstrap_artifact_source")

def get_bootstrap_container_registry_resource_id(self) -> Union[str, None]:
"""Obtain the value of bootstrap_container_registry_resource_id.
"""
return self.raw_param.get("bootstrap_container_registry_resource_id")


class AKSManagedClusterCreateDecorator(BaseAKSManagedClusterDecorator):
def __init__(
Expand Down Expand Up @@ -6510,6 +6522,24 @@ def set_up_node_resource_group_profile(self, mc: ManagedCluster) -> ManagedClust
mc.node_resource_group_profile = node_resource_group_profile
return mc

def set_up_bootstrap_profile(self, mc: ManagedCluster) -> ManagedCluster:
self._ensure_mc(mc)

bootstrap_artifact_source = self.context.get_bootstrap_artifact_source()
bootstrap_container_registry_resource_id = self.context.get_bootstrap_container_registry_resource_id()
if hasattr(mc, "bootstrap_profile") and bootstrap_artifact_source is not None:
if bootstrap_artifact_source != CONST_ARTIFACT_SOURCE_CACHE and bootstrap_container_registry_resource_id:
raise MutuallyExclusiveArgumentError(
"Cannot specify --bootstrap-container-registry-resource-id when "
"--bootstrap-artifact-source is not Cache."
)
if mc.bootstrap_profile is None:
mc.bootstrap_profile = self.models.ManagedClusterBootstrapProfile() # pylint: disable=no-member
mc.bootstrap_profile.artifact_source = bootstrap_artifact_source
mc.bootstrap_profile.container_registry_id = bootstrap_container_registry_resource_id

return mc

def construct_mc_profile_default(self, bypass_restore_defaults: bool = False) -> ManagedCluster:
"""The overall controller used to construct the default ManagedCluster profile.

Expand Down Expand Up @@ -6590,6 +6620,8 @@ def construct_mc_profile_default(self, bypass_restore_defaults: bool = False) ->
mc = self.set_up_metrics_profile(mc)
# set up node resource group profile
mc = self.set_up_node_resource_group_profile(mc)
# set up bootstrap profile
mc = self.set_up_bootstrap_profile(mc)

# DO NOT MOVE: keep this at the bottom, restore defaults
if not bypass_restore_defaults:
Expand Down Expand Up @@ -8351,6 +8383,24 @@ def update_metrics_profile(self, mc: ManagedCluster) -> ManagedCluster:

return mc

def update_bootstrap_profile(self, mc: ManagedCluster) -> ManagedCluster:
self._ensure_mc(mc)

bootstrap_artifact_source = self.context.get_bootstrap_artifact_source()
bootstrap_container_registry_resource_id = self.context.get_bootstrap_container_registry_resource_id()
if hasattr(mc, "bootstrap_profile") and bootstrap_artifact_source is not None:
if bootstrap_artifact_source != CONST_ARTIFACT_SOURCE_CACHE and bootstrap_container_registry_resource_id:
raise MutuallyExclusiveArgumentError(
"Cannot specify --bootstrap-container-registry-resource-id when "
"--bootstrap-artifact-source is not Cache."
)
if mc.bootstrap_profile is None:
mc.bootstrap_profile = self.models.ManagedClusterBootstrapProfile() # pylint: disable=no-member
mc.bootstrap_profile.artifact_source = bootstrap_artifact_source
mc.bootstrap_profile.container_registry_id = bootstrap_container_registry_resource_id

return mc

def update_mc_profile_default(self) -> ManagedCluster:
"""The overall controller used to update the default ManagedCluster profile.

Expand Down Expand Up @@ -8430,6 +8480,8 @@ def update_mc_profile_default(self) -> ManagedCluster:
mc = self.update_metrics_profile(mc)
# update node resource group profile
mc = self.update_node_resource_group_profile(mc)
# update bootstrap profile
mc = self.update_bootstrap_profile(mc)
return mc

def check_is_postprocessing_required(self, mc: ManagedCluster) -> bool:
Expand Down
Loading