Skip to content

Commit

Permalink
[AKS] Add a new command to enable bootstrap artifact source when upda…
Browse files Browse the repository at this point in the history
…ting cluster (#7519)
  • Loading branch information
bingosummer authored Apr 18, 2024
1 parent b189e0c commit 79d64e0
Show file tree
Hide file tree
Showing 9 changed files with 3,346 additions and 610 deletions.
4 changes: 4 additions & 0 deletions src/aks-preview/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ To release a new version, please select a new version number (usually plus 1 to
Pending
+++++++

3.0.0b5
+++++++
* Add `--bootstrap-artifact-source` and `--bootstrap-container-registry-resource-id` to `az aks update`.

3.0.0b4
+++++++
* Fix the issue that option `--uptime-sla` is ignored in command `az aks create`.
Expand Down
8 changes: 8 additions & 0 deletions src/aks-preview/azext_aks_preview/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -1193,6 +1193,14 @@
- name: --node-init-taints --nodepool-initialization-taints
type: string
short-summary: The node initialization taints for all node pools in cluster.
- 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
10 changes: 10 additions & 0 deletions src/aks-preview/azext_aks_preview/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,16 @@ def load_arguments(self, _):
validator=validate_azure_keyvault_kms_key_vault_resource_id,
)
c.argument("http_proxy_config")
c.argument(
"bootstrap_artifact_source",
arg_type=get_enum_type(bootstrap_artifact_source_types),
is_preview=True,
)
c.argument(
"bootstrap_container_registry_resource_id",
validator=validate_bootstrap_container_registry_resource_id,
is_preview=True,
)
# addons
c.argument("enable_secret_rotation", action="store_true")
c.argument("disable_secret_rotation", action="store_true")
Expand Down
2 changes: 2 additions & 0 deletions src/aks-preview/azext_aks_preview/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,8 @@ def aks_update(
azure_keyvault_kms_key_vault_network_access=None,
azure_keyvault_kms_key_vault_resource_id=None,
http_proxy_config=None,
bootstrap_artifact_source=None,
bootstrap_container_registry_resource_id=None,
# addons
enable_secret_rotation=False,
disable_secret_rotation=False,
Expand Down
20 changes: 20 additions & 0 deletions src/aks-preview/azext_aks_preview/managed_cluster_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4831,6 +4831,24 @@ def update_agentpool_profile_ssh_access(self, mc: ManagedCluster) -> ManagedClus
agent_pool_profile.security_profile.ssh_access = ssh_access
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 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_preview(self) -> ManagedCluster:
"""The overall controller used to update the preview ManagedCluster profile.
Expand Down Expand Up @@ -4904,6 +4922,8 @@ def update_mc_profile_preview(self) -> ManagedCluster:
mc = self.update_node_provisioning_profile(mc)
# update agentpool profile ssh access
mc = self.update_agentpool_profile_ssh_access(mc)
# update bootstrap profile
mc = self.update_bootstrap_profile(mc)

return mc

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -13717,18 +13717,20 @@ def test_aks_create_cluster_with_taints(self, resource_group, resource_group_loc
location="westcentralus",
)
def test_aks_artifact_source(self, resource_group, resource_group_location):
aks_name = self.create_random_name('cliakstest', 16)
vnet_name = self.create_random_name("clitest", 16)
aks_subnet_name = "aks-subnet"
acr_subnet_name = "acr-subnet"
cluster_identity_name = self.create_random_name("clitest", 16)
kubelet_identity_name = self.create_random_name("clitest", 16)
acr_name = self.create_random_name("clitest", 16)
aks_name_1 = self.create_random_name('cliakstest', 16)
aks_name_2 = self.create_random_name('cliakstest', 16)
self.kwargs.update(
{
"resource_group": resource_group,
'location': resource_group_location,
"aks_name": aks_name,
"aks_name_1": aks_name_1,
"aks_name_2": aks_name_2,
"vnet_name": vnet_name,
"aks_subnet_name": aks_subnet_name,
"acr_subnet_name": acr_subnet_name,
Expand Down Expand Up @@ -13899,21 +13901,47 @@ def test_aks_artifact_source(self, resource_group, resource_group_location):
)
self.cmd(create_role_assignment_cmd)

# create AKS cluster
create_cmd = (
"aks create --resource-group {resource_group} --name {aks_name} -c 1 --ssh-key-value={ssh_key_value} "
# create AKS cluster to use Cache as artifact source
create_cmd_1 = (
"aks create --resource-group {resource_group} --name {aks_name_1} -c 1 --ssh-key-value={ssh_key_value} "
"--network-plugin kubenet --vnet-subnet-id {vnet_id}/subnets/{aks_subnet_name} "
"--assign-identity {cluster_identity_id} "
"--assign-kubelet-identity {kubelet_identity_id} "
"--bootstrap-artifact-source Cache --bootstrap-container-registry-resource-id {acr_id} "
"--aks-custom-headers AKSHTTPCustomFeatures=Microsoft.ContainerService/BootstrapProfilePreview "
"-o json"
)
self.cmd(create_cmd, checks=[
self.cmd(create_cmd_1, checks=[
self.check("provisioningState", "Succeeded"),
self.check("bootstrapProfile.artifactSource", "Cache"),
self.check("bootstrapProfile.containerRegistryId", acr_id),
])

# create AKS cluster to use Direct as artifact source
create_cmd_2 = (
"aks create --resource-group {resource_group} --name {aks_name_2} -c 1 --ssh-key-value={ssh_key_value} "
"--network-plugin kubenet --vnet-subnet-id {vnet_id}/subnets/{aks_subnet_name} "
"--assign-identity {cluster_identity_id} "
"--assign-kubelet-identity {kubelet_identity_id} "
"-o json"
)
self.cmd(create_cmd_2, checks=[
self.check("provisioningState", "Succeeded"),
])

# update AKS cluster to use Cache as artifact source
update_cmd = (
"aks update --resource-group {resource_group} --name {aks_name_2} "
"--bootstrap-artifact-source Cache --bootstrap-container-registry-resource-id {acr_id} "
"--aks-custom-headers AKSHTTPCustomFeatures=Microsoft.ContainerService/BootstrapProfilePreview "
"-o json"
)
self.cmd(update_cmd, checks=[
self.check("provisioningState", "Succeeded"),
self.check("bootstrapProfile.artifactSource", "Cache"),
self.check("bootstrapProfile.containerRegistryId", acr_id),
])

# delete
self.cmd("aks delete -g {resource_group} -n {aks_name} --yes --no-wait", checks=[self.is_empty()])
self.cmd("aks delete -g {resource_group} -n {aks_name_1} --yes --no-wait", checks=[self.is_empty()])
self.cmd("aks delete -g {resource_group} -n {aks_name_2} --yes --no-wait", checks=[self.is_empty()])
6 changes: 6 additions & 0 deletions src/aks-preview/linter_exclusions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ aks update:
disable_ai_toolchain_operator:
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 delete:
parameters:
ignore_pod_disruption_budget:
Expand Down
2 changes: 1 addition & 1 deletion src/aks-preview/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from setuptools import setup, find_packages

VERSION = "3.0.0b4"
VERSION = "3.0.0b5"

CLASSIFIERS = [
"Development Status :: 4 - Beta",
Expand Down

0 comments on commit 79d64e0

Please sign in to comment.