Skip to content

Commit 20f57de

Browse files
committed
feat: Support updating load balancer sku from basic to standard
1 parent db8472d commit 20f57de

5 files changed

Lines changed: 101 additions & 1 deletion

File tree

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,10 @@
760760
type: string
761761
short-summary: Load balancer backend pool type.
762762
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.
763+
- name: --load-balancer-sku
764+
type: string
765+
short-summary: Azure Load Balancer SKU selection for your cluster. only standard is accepted.
766+
long-summary: Upgrade to Standard Azure Load Balancer SKU for your AKS cluster.
763767
- name: --nat-gateway-managed-outbound-ip-count
764768
type: int
765769
short-summary: NAT gateway managed outbound IP count.
@@ -1128,6 +1132,8 @@
11281132
text: az aks update -g MyResourceGroup -n MyManagedCLuster --enable-vpa
11291133
- name: Disable VPA(Vertical Pod Autoscaler) for an existing kubernetes cluster.
11301134
text: az aks update -g MyResourceGroup -n MyManagedCLuster --disable-vpa
1135+
- name: Upgrade load balancer sku to standard
1136+
text: az aks update --load-balancer-sku standard -g MyResourceGroup -n MyManagedCluster
11311137
"""
11321138

11331139
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
@@ -547,6 +547,7 @@ def load_arguments(self, _):
547547
c.argument('load_balancer_outbound_ports', type=int, validator=validate_load_balancer_outbound_ports)
548548
c.argument('load_balancer_idle_timeout', type=int, validator=validate_load_balancer_idle_timeout)
549549
c.argument('load_balancer_backend_pool_type', arg_type=get_enum_type(backend_pool_types))
550+
c.argument("load_balancer_sku", arg_type=get_enum_type([CONST_LOAD_BALANCER_SKU_STANDARD]), validator=validate_load_balancer_sku)
550551
c.argument('nrg_lockdown_restriction_level', arg_type=get_enum_type(nrg_lockdown_restriction_levels))
551552
c.argument('nat_gateway_managed_outbound_ip_count', type=int, validator=validate_nat_gateway_managed_outbound_ip_count)
552553
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
@@ -731,6 +731,7 @@ def aks_update(
731731
load_balancer_outbound_ports=None,
732732
load_balancer_idle_timeout=None,
733733
load_balancer_backend_pool_type=None,
734+
load_balancer_sku=None,
734735
nat_gateway_managed_outbound_ip_count=None,
735736
nat_gateway_idle_timeout=None,
736737
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
@@ -1969,16 +1969,20 @@ def _get_load_balancer_sku(self, enable_validation: bool = False) -> Union[str,
19691969
:return: string or None
19701970
"""
19711971
# read the original value passed by the command
1972-
load_balancer_sku = safe_lower(self.raw_param.get("load_balancer_sku", CONST_LOAD_BALANCER_SKU_STANDARD))
1972+
load_balancer_sku = safe_lower(self.raw_param.get("load_balancer_sku"))
19731973
# try to read the property value corresponding to the parameter from the `mc` object
19741974
if (
1975+
load_balancer_sku is None and
19751976
self.mc and
19761977
self.mc.network_profile and
19771978
self.mc.network_profile.load_balancer_sku is not None
19781979
):
19791980
load_balancer_sku = safe_lower(
19801981
self.mc.network_profile.load_balancer_sku
19811982
)
1983+
if self.decorator_mode == DecoratorMode.CREATE and load_balancer_sku is None:
1984+
# default value
1985+
load_balancer_sku = CONST_LOAD_BALANCER_SKU_STANDARD
19821986

19831987
# validation
19841988
if enable_validation:
@@ -7787,6 +7791,10 @@ def update_network_profile(self, mc: ManagedCluster) -> ManagedCluster:
77877791

77887792
self.update_network_plugin_settings(mc)
77897793

7794+
loadbalancer_sku = self.context.get_load_balancer_sku()
7795+
if loadbalancer_sku:
7796+
mc.network_profile.load_balancer_sku = loadbalancer_sku
7797+
77907798
return mc
77917799

77927800
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(
@@ -9209,6 +9243,56 @@ def test_update_load_balancer_profile(self):
92099243
print(ground_truth_mc_3.network_profile.load_balancer_profile)
92109244
self.assertEqual(dec_mc_3, ground_truth_mc_3)
92119245

9246+
def test_update_network_profile_load_balancer_sku(self):
9247+
# default (no update)
9248+
dec_1 = AKSManagedClusterUpdateDecorator(
9249+
self.cmd,
9250+
self.client,
9251+
{},
9252+
ResourceType.MGMT_CONTAINERSERVICE,
9253+
)
9254+
mc_1 = self.models.ManagedCluster(
9255+
location="test_location",
9256+
network_profile=self.models.ContainerServiceNetworkProfile(
9257+
load_balancer_sku=CONST_LOAD_BALANCER_SKU_BASIC
9258+
),
9259+
)
9260+
dec_1.context.attach_mc(mc_1)
9261+
# fail on passing the wrong mc object
9262+
with self.assertRaises(CLIInternalError):
9263+
dec_1.update_network_profile(None)
9264+
dec_mc_1 = dec_1.update_network_profile(mc_1)
9265+
ground_truth_mc_1 = self.models.ManagedCluster(
9266+
location="test_location",
9267+
network_profile=self.models.ContainerServiceNetworkProfile(
9268+
load_balancer_sku=CONST_LOAD_BALANCER_SKU_BASIC
9269+
),
9270+
)
9271+
self.assertEqual(dec_mc_1, ground_truth_mc_1)
9272+
9273+
# upgrade from basic to standard
9274+
dec_2 = AKSManagedClusterUpdateDecorator(
9275+
self.cmd,
9276+
self.client,
9277+
{"load_balancer_sku": CONST_LOAD_BALANCER_SKU_STANDARD},
9278+
ResourceType.MGMT_CONTAINERSERVICE,
9279+
)
9280+
mc_2 = self.models.ManagedCluster(
9281+
location="test_location",
9282+
network_profile=self.models.ContainerServiceNetworkProfile(
9283+
load_balancer_sku=CONST_LOAD_BALANCER_SKU_BASIC
9284+
),
9285+
)
9286+
dec_2.context.attach_mc(mc_2)
9287+
dec_mc_2 = dec_2.update_network_profile(mc_2)
9288+
ground_truth_mc_2 = self.models.ManagedCluster(
9289+
location="test_location",
9290+
network_profile=self.models.ContainerServiceNetworkProfile(
9291+
load_balancer_sku=CONST_LOAD_BALANCER_SKU_STANDARD
9292+
),
9293+
)
9294+
self.assertEqual(dec_mc_2, ground_truth_mc_2)
9295+
92129296
def test_update_nat_gateway_profile(self):
92139297
# default value in `aks_update`
92149298
dec_1 = AKSManagedClusterUpdateDecorator(

0 commit comments

Comments
 (0)