Skip to content

Commit 4783eaf

Browse files
authored
[AKS] az aks update: Support updating load balancer sku from basic to standard (#31874)
1 parent 981975a commit 4783eaf

File tree

5 files changed

+101
-1
lines changed

5 files changed

+101
-1
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,10 @@
778778
type: string
779779
short-summary: Load balancer backend pool type.
780780
long-summary: Define the LoadBalancer backend pool type of managed inbound backend pool. The nodeIP means the VMs will be attached to the LoadBalancer by adding its private IP address to the backend pool. The nodeIPConfiguration means the VMs will be attached to the LoadBalancer by referencing the backend pool ID in the VM's NIC.
781+
- name: --load-balancer-sku
782+
type: string
783+
short-summary: Azure Load Balancer SKU selection for your cluster. only standard is accepted.
784+
long-summary: Upgrade to Standard Azure Load Balancer SKU for your AKS cluster.
781785
- name: --nat-gateway-managed-outbound-ip-count
782786
type: int
783787
short-summary: NAT gateway managed outbound IP count.
@@ -1167,6 +1171,8 @@
11671171
text: az aks update -g MyResourceGroup -n MyManagedCluster --node-provisioning-mode Auto
11681172
- name: Update a kubernetes cluster to use auto node provisioning mode with no default pools.
11691173
text: az aks update -g MyResourceGroup -n MyManagedCluster --node-provisioning-mode Auto --node-provisioning-default-pools None
1174+
- name: Upgrade load balancer sku to standard
1175+
text: az aks update --load-balancer-sku standard -g MyResourceGroup -n MyManagedCluster
11701176
"""
11711177

11721178
helps['aks delete'] = """

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,7 @@ def load_arguments(self, _):
584584
c.argument('load_balancer_outbound_ports', type=int, validator=validate_load_balancer_outbound_ports)
585585
c.argument('load_balancer_idle_timeout', type=int, validator=validate_load_balancer_idle_timeout)
586586
c.argument('load_balancer_backend_pool_type', arg_type=get_enum_type(backend_pool_types))
587+
c.argument("load_balancer_sku", arg_type=get_enum_type([CONST_LOAD_BALANCER_SKU_STANDARD]), validator=validate_load_balancer_sku)
587588
c.argument('nrg_lockdown_restriction_level', arg_type=get_enum_type(nrg_lockdown_restriction_levels))
588589
c.argument('nat_gateway_managed_outbound_ip_count', type=int, validator=validate_nat_gateway_managed_outbound_ip_count)
589590
c.argument('nat_gateway_idle_timeout', type=int, validator=validate_nat_gateway_idle_timeout)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,7 @@ def aks_update(
852852
load_balancer_outbound_ports=None,
853853
load_balancer_idle_timeout=None,
854854
load_balancer_backend_pool_type=None,
855+
load_balancer_sku=None,
855856
nat_gateway_managed_outbound_ip_count=None,
856857
nat_gateway_idle_timeout=None,
857858
outbound_type=None,

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2034,16 +2034,20 @@ def _get_load_balancer_sku(self, enable_validation: bool = False) -> Union[str,
20342034
:return: string or None
20352035
"""
20362036
# read the original value passed by the command
2037-
load_balancer_sku = safe_lower(self.raw_param.get("load_balancer_sku", CONST_LOAD_BALANCER_SKU_STANDARD))
2037+
load_balancer_sku = safe_lower(self.raw_param.get("load_balancer_sku"))
20382038
# try to read the property value corresponding to the parameter from the `mc` object
20392039
if (
2040+
load_balancer_sku is None and
20402041
self.mc and
20412042
self.mc.network_profile and
20422043
self.mc.network_profile.load_balancer_sku is not None
20432044
):
20442045
load_balancer_sku = safe_lower(
20452046
self.mc.network_profile.load_balancer_sku
20462047
)
2048+
if self.decorator_mode == DecoratorMode.CREATE and load_balancer_sku is None:
2049+
# default value
2050+
load_balancer_sku = CONST_LOAD_BALANCER_SKU_STANDARD
20472051

20482052
# validation
20492053
if enable_validation:
@@ -7924,6 +7928,10 @@ def update_network_profile(self, mc: ManagedCluster) -> ManagedCluster:
79247928

79257929
self.update_network_plugin_settings(mc)
79267930

7931+
loadbalancer_sku = self.context.get_load_balancer_sku()
7932+
if loadbalancer_sku:
7933+
mc.network_profile.load_balancer_sku = loadbalancer_sku
7934+
79277935
return mc
79287936

79297937
def update_network_plugin_settings(self, mc: ManagedCluster) -> ManagedCluster:

src/azure-cli/azure/cli/command_modules/acs/tests/latest/test_managed_cluster_decorator.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,6 +1423,40 @@ def test_get_load_balancer_sku(self):
14231423
)
14241424
self.assertEqual(ctx_5.get_load_balancer_sku(), "standard")
14251425

1426+
# UPDATE mode: None parameter should return None (not default)
1427+
ctx_6 = AKSManagedClusterContext(
1428+
self.cmd,
1429+
AKSManagedClusterParamDict({"load_balancer_sku": None}),
1430+
self.models,
1431+
DecoratorMode.UPDATE,
1432+
)
1433+
self.assertEqual(ctx_6.get_load_balancer_sku(), None)
1434+
1435+
# UPDATE mode: custom value should be returned
1436+
ctx_7 = AKSManagedClusterContext(
1437+
self.cmd,
1438+
AKSManagedClusterParamDict({"load_balancer_sku": CONST_LOAD_BALANCER_SKU_STANDARD}),
1439+
self.models,
1440+
DecoratorMode.UPDATE,
1441+
)
1442+
self.assertEqual(ctx_7.get_load_balancer_sku(), CONST_LOAD_BALANCER_SKU_STANDARD)
1443+
1444+
# UPDATE mode: read from existing mc when parameter is None
1445+
mc_8 = self.models.ManagedCluster(
1446+
location="test_location",
1447+
network_profile=self.models.ContainerServiceNetworkProfile(
1448+
load_balancer_sku=CONST_LOAD_BALANCER_SKU_BASIC
1449+
),
1450+
)
1451+
ctx_8 = AKSManagedClusterContext(
1452+
self.cmd,
1453+
AKSManagedClusterParamDict({"load_balancer_sku": None}),
1454+
self.models,
1455+
DecoratorMode.UPDATE,
1456+
)
1457+
ctx_8.attach_mc(mc_8)
1458+
self.assertEqual(ctx_8.get_load_balancer_sku(), CONST_LOAD_BALANCER_SKU_BASIC)
1459+
14261460
def test_get_load_balancer_managed_outbound_ip_count(self):
14271461
# default
14281462
ctx_1 = AKSManagedClusterContext(
@@ -9328,6 +9362,56 @@ def test_update_load_balancer_profile(self):
93289362
print(ground_truth_mc_3.network_profile.load_balancer_profile)
93299363
self.assertEqual(dec_mc_3, ground_truth_mc_3)
93309364

9365+
def test_update_network_profile_load_balancer_sku(self):
9366+
# default (no update)
9367+
dec_1 = AKSManagedClusterUpdateDecorator(
9368+
self.cmd,
9369+
self.client,
9370+
{},
9371+
ResourceType.MGMT_CONTAINERSERVICE,
9372+
)
9373+
mc_1 = self.models.ManagedCluster(
9374+
location="test_location",
9375+
network_profile=self.models.ContainerServiceNetworkProfile(
9376+
load_balancer_sku=CONST_LOAD_BALANCER_SKU_BASIC
9377+
),
9378+
)
9379+
dec_1.context.attach_mc(mc_1)
9380+
# fail on passing the wrong mc object
9381+
with self.assertRaises(CLIInternalError):
9382+
dec_1.update_network_profile(None)
9383+
dec_mc_1 = dec_1.update_network_profile(mc_1)
9384+
ground_truth_mc_1 = self.models.ManagedCluster(
9385+
location="test_location",
9386+
network_profile=self.models.ContainerServiceNetworkProfile(
9387+
load_balancer_sku=CONST_LOAD_BALANCER_SKU_BASIC
9388+
),
9389+
)
9390+
self.assertEqual(dec_mc_1, ground_truth_mc_1)
9391+
9392+
# upgrade from basic to standard
9393+
dec_2 = AKSManagedClusterUpdateDecorator(
9394+
self.cmd,
9395+
self.client,
9396+
{"load_balancer_sku": CONST_LOAD_BALANCER_SKU_STANDARD},
9397+
ResourceType.MGMT_CONTAINERSERVICE,
9398+
)
9399+
mc_2 = self.models.ManagedCluster(
9400+
location="test_location",
9401+
network_profile=self.models.ContainerServiceNetworkProfile(
9402+
load_balancer_sku=CONST_LOAD_BALANCER_SKU_BASIC
9403+
),
9404+
)
9405+
dec_2.context.attach_mc(mc_2)
9406+
dec_mc_2 = dec_2.update_network_profile(mc_2)
9407+
ground_truth_mc_2 = self.models.ManagedCluster(
9408+
location="test_location",
9409+
network_profile=self.models.ContainerServiceNetworkProfile(
9410+
load_balancer_sku=CONST_LOAD_BALANCER_SKU_STANDARD
9411+
),
9412+
)
9413+
self.assertEqual(dec_mc_2, ground_truth_mc_2)
9414+
93319415
def test_update_nat_gateway_profile(self):
93329416
# default value in `aks_update`
93339417
dec_1 = AKSManagedClusterUpdateDecorator(

0 commit comments

Comments
 (0)