Skip to content

Commit e4b6e96

Browse files
authored
[AKS] az aks update: Support VMAS to VMS agent pool migration in AKS commands (#31831)
1 parent 0c09c9a commit e4b6e96

File tree

7 files changed

+2625
-2
lines changed

7 files changed

+2625
-2
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,9 @@
10571057
- name: --disable-static-egress-gateway
10581058
type: bool
10591059
short-summary: Disable Static Egress Gateway addon to the cluster.
1060+
- name: --migrate-vmas-to-vms
1061+
type: bool
1062+
short-summary: Migrate cluster with VMAS node pool to VMS node pool.
10601063
examples:
10611064
- name: Reconcile the cluster back to its current state.
10621065
text: az aks update -g MyResourceGroup -n MyManagedCluster

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,8 @@ def load_arguments(self, _):
649649
c.argument('nodepool_labels', nargs='*', validator=validate_nodepool_labels,
650650
help='space-separated labels: key[=value] [key[=value] ...]. See https://aka.ms/node-labels for syntax of labels.')
651651
c.argument('nodepool_taints', validator=validate_nodepool_taints)
652+
c.argument('migrate_vmas_to_vms', action='store_true')
653+
652654
# azure monitor profile
653655
c.argument('enable_azure_monitor_metrics', action='store_true')
654656
c.argument('azure_monitor_workspace_resource_id', validator=validate_azuremonitorworkspaceresourceid)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,7 @@ def aks_update(
814814
max_count=None,
815815
nodepool_labels=None,
816816
nodepool_taints=None,
817+
migrate_vmas_to_vms=False,
817818
# azure monitor profile
818819
enable_azure_monitor_metrics=False,
819820
azure_monitor_workspace_resource_id=None,

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

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
CONST_DNS_ZONE_CONTRIBUTOR_ROLE,
4343
CONST_ARTIFACT_SOURCE_CACHE,
4444
CONST_NONE_UPGRADE_CHANNEL,
45+
CONST_AVAILABILITY_SET,
46+
CONST_VIRTUAL_MACHINES,
4547
)
4648
from azure.cli.command_modules.acs._helpers import (
4749
check_is_managed_aad_cluster,
@@ -2250,7 +2252,7 @@ def _get_outbound_type(
22502252
"for more details."
22512253
)
22522254
if isBasicSKULb:
2253-
if outbound_type is not None:
2255+
if not read_from_mc and outbound_type is not None: # outbound type was default to loadbalancer for BLB creation
22542256
raise InvalidArgumentValueError(
22552257
"{outbound_type} doesn't support basic load balancer sku".format(outbound_type=outbound_type)
22562258
)
@@ -5500,6 +5502,12 @@ def get_disable_static_egress_gateway(self) -> bool:
55005502
# because it's already checked in get_enable_static_egress_gateway
55015503
return self.raw_param.get("disable_static_egress_gateway")
55025504

5505+
def get_migrate_vmas_to_vms(self) -> bool:
5506+
"""Obtain the value of migrate_vmas_to_vms.
5507+
:return: bool
5508+
"""
5509+
return self.raw_param.get("migrate_vmas_to_vms")
5510+
55035511

55045512
class AKSManagedClusterCreateDecorator(BaseAKSManagedClusterDecorator):
55055513
def __init__(
@@ -8781,6 +8789,34 @@ def update_static_egress_gateway(self, mc: ManagedCluster) -> ManagedCluster:
87818789
mc.network_profile.static_egress_gateway_profile.enabled = False
87828790
return mc
87838791

8792+
def update_vmas_to_vms(self, mc: ManagedCluster) -> ManagedCluster:
8793+
"""Update the agent pool profile type from VMAS to VMS and LB sku to standard
8794+
:return: the ManagedCluster object
8795+
"""
8796+
self._ensure_mc(mc)
8797+
8798+
if self.context.get_migrate_vmas_to_vms():
8799+
msg = (
8800+
"\nWARNING: This operation will be disruptive to your workload while underway. "
8801+
"Do you wish to continue?"
8802+
)
8803+
if not self.context.get_yes() and not prompt_y_n(msg, default="n"):
8804+
raise DecoratorEarlyExitException()
8805+
# Ensure we have valid vmas AP
8806+
if len(mc.agent_pool_profiles) == 1 and mc.agent_pool_profiles[0].type == CONST_AVAILABILITY_SET:
8807+
mc.agent_pool_profiles[0].type = CONST_VIRTUAL_MACHINES
8808+
else:
8809+
raise ArgumentUsageError('This is not a valid VMAS cluster with {} agent pool profiles and {} agent pool type, we cannot proceed with the migration.'.format(len(mc.agent_pool_profiles), mc.agent_pool_profiles[0].type))
8810+
8811+
if mc.network_profile.load_balancer_sku == CONST_LOAD_BALANCER_SKU_BASIC:
8812+
mc.network_profile.load_balancer_sku = CONST_LOAD_BALANCER_SKU_STANDARD
8813+
8814+
# Set agent pool profile count and vm_size to None
8815+
mc.agent_pool_profiles[0].count = None
8816+
mc.agent_pool_profiles[0].vm_size = None
8817+
8818+
return mc
8819+
87848820
def update_mc_profile_default(self) -> ManagedCluster:
87858821
"""The overall controller used to update the default ManagedCluster profile.
87868822
@@ -8868,6 +8904,8 @@ def update_mc_profile_default(self) -> ManagedCluster:
88688904
mc = self.update_static_egress_gateway(mc)
88698905
# update kubernetes version and orchestrator version
88708906
mc = self.update_kubernetes_version_and_orchestrator_version(mc)
8907+
# update VMAS to VMS
8908+
mc = self.update_vmas_to_vms(mc)
88718909
return mc
88728910

88738911
def update_kubernetes_version_and_orchestrator_version(self, mc: ManagedCluster) -> ManagedCluster:

0 commit comments

Comments
 (0)