Skip to content

Commit bde8dce

Browse files
{aks}: Add support for basic lb migration (#8731)
* add support for basic lb migration * add support for basic lb migration
1 parent 9a05db7 commit bde8dce

File tree

9 files changed

+2394
-2
lines changed

9 files changed

+2394
-2
lines changed

src/aks-preview/HISTORY.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ To release a new version, please select a new version number (usually plus 1 to
1212
Pending
1313
+++++++
1414

15+
18.0.0b3
16+
+++++++
17+
* Add basic lb sku migration support `az aks update --load-balancer-sku standard`
18+
1519
18.0.0b2
1620
+++++++
1721
* Vendor new SDK and bump API version to 2025-03-02-preview.

src/aks-preview/azext_aks_preview/_help.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,10 @@
816816
- name: --tier
817817
type: string
818818
short-summary: Specify SKU tier for managed clusters. '--tier standard' enables a standard managed cluster service with a financially backed SLA. '--tier free' changes a standard managed cluster to a free one.
819+
- name: --load-balancer-sku
820+
type: string
821+
short-summary: Azure Load Balancer SKU selection for your cluster. only standard is accepted.
822+
long-summary: Upgrade to Standard Azure Load Balancer SKU for your AKS cluster.
819823
- name: --load-balancer-managed-outbound-ip-count
820824
type: int
821825
short-summary: Load balancer managed outbound IP count.
@@ -1267,6 +1271,8 @@
12671271
text: az aks update --disable-cluster-autoscaler -g MyResourceGroup -n MyManagedCluster
12681272
- name: Update min-count or max-count for cluster autoscaler.
12691273
text: az aks update --update-cluster-autoscaler --min-count 1 --max-count 10 -g MyResourceGroup -n MyManagedCluster
1274+
- name: Upgrade load balancer sku to standard
1275+
text: az aks update --load-balancer-sku standard -g MyResourceGroup -n MyManagedCluster
12701276
- name: Update a kubernetes cluster with standard SKU load balancer to use two AKS created IPs for the load balancer outbound connection usage.
12711277
text: az aks update -g MyResourceGroup -n MyManagedCluster --load-balancer-managed-outbound-ip-count 2
12721278
- name: Update a kubernetes cluster with standard SKU load balancer to use the provided public IPs for the load balancer outbound connection usage.

src/aks-preview/azext_aks_preview/_params.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,11 @@ def load_arguments(self, _):
997997
# managed cluster paramerters
998998
c.argument("disable_local_accounts", action="store_true")
999999
c.argument("enable_local_accounts", action="store_true")
1000+
c.argument(
1001+
"load_balancer_sku",
1002+
arg_type=get_enum_type([CONST_LOAD_BALANCER_SKU_STANDARD]),
1003+
validator=validate_load_balancer_sku,
1004+
)
10001005
c.argument("load_balancer_managed_outbound_ip_count", type=int)
10011006
c.argument(
10021007
"load_balancer_outbound_ips", validator=validate_load_balancer_outbound_ips

src/aks-preview/azext_aks_preview/custom.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,7 @@ def aks_update(
598598
tags=None,
599599
disable_local_accounts=False,
600600
enable_local_accounts=False,
601+
load_balancer_sku=None,
601602
load_balancer_managed_outbound_ip_count=None,
602603
load_balancer_outbound_ips=None,
603604
load_balancer_outbound_ip_prefixes=None,

src/aks-preview/azext_aks_preview/managed_cluster_decorator.py

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
CONST_AZURE_SERVICE_MESH_UPGRADE_COMMAND_START,
2121
CONST_AZURE_SERVICE_MESH_DEFAULT_EGRESS_NAMESPACE,
2222
CONST_LOAD_BALANCER_SKU_BASIC,
23-
CONST_LOAD_BALANCER_SKU_STANDARD,
2423
CONST_MANAGED_CLUSTER_SKU_NAME_BASE,
2524
CONST_MANAGED_CLUSTER_SKU_NAME_AUTOMATIC,
2625
CONST_MANAGED_CLUSTER_SKU_TIER_FREE,
@@ -86,6 +85,7 @@
8685
CONST_OUTBOUND_TYPE_MANAGED_NAT_GATEWAY,
8786
CONST_OUTBOUND_TYPE_USER_ASSIGNED_NAT_GATEWAY,
8887
CONST_OUTBOUND_TYPE_USER_DEFINED_ROUTING,
88+
CONST_LOAD_BALANCER_SKU_STANDARD,
8989
DecoratorEarlyExitException,
9090
DecoratorMode,
9191
)
@@ -347,6 +347,48 @@ def get_enable_msi_auth_for_monitoring(self) -> Union[bool, None]:
347347
return True
348348
return enable_msi_auth_for_monitoring
349349

350+
def _get_load_balancer_sku(self, enable_validation: bool = False) -> Union[str, None]:
351+
"""Internal function to obtain the value of load_balancer_sku, default value is
352+
CONST_LOAD_BALANCER_SKU_STANDARD.
353+
354+
Note: When returning a string, it will always be lowercase.
355+
356+
This function supports the option of enable_validation. When enabled, it will check if load_balancer_sku equals
357+
to CONST_LOAD_BALANCER_SKU_BASIC, if so, when api_server_authorized_ip_ranges is assigned or
358+
enable_private_cluster is specified, raise an InvalidArgumentValueError.
359+
360+
:return: string or None
361+
"""
362+
# read the original value passed by the command
363+
load_balancer_sku = safe_lower(self.raw_param.get("load_balancer_sku"))
364+
# try to read the property value corresponding to the parameter from the `mc` object
365+
if (
366+
load_balancer_sku is None and
367+
self.mc and
368+
self.mc.network_profile and
369+
self.mc.network_profile.load_balancer_sku is not None
370+
):
371+
load_balancer_sku = safe_lower(
372+
self.mc.network_profile.load_balancer_sku
373+
)
374+
if self.decorator_mode == DecoratorMode.CREATE and load_balancer_sku is None:
375+
# default value
376+
load_balancer_sku = CONST_LOAD_BALANCER_SKU_STANDARD
377+
378+
# validation
379+
if enable_validation:
380+
if load_balancer_sku == CONST_LOAD_BALANCER_SKU_BASIC:
381+
if self._get_api_server_authorized_ip_ranges(enable_validation=False):
382+
raise InvalidArgumentValueError(
383+
"--api-server-authorized-ip-ranges can only be used with standard load balancer"
384+
)
385+
if self._get_enable_private_cluster(enable_validation=False):
386+
raise InvalidArgumentValueError(
387+
"Please use standard load balancer for private cluster"
388+
)
389+
390+
return load_balancer_sku
391+
350392
def _get_disable_local_accounts(self, enable_validation: bool = False) -> bool:
351393
"""Internal function to obtain the value of disable_local_accounts.
352394
@@ -3972,6 +4014,9 @@ def update_network_profile(self, mc: ManagedCluster) -> ManagedCluster:
39724014

39734015
self.update_network_plugin_settings(mc)
39744016

4017+
loadbalancer_sku = self.context.get_load_balancer_sku()
4018+
if loadbalancer_sku:
4019+
mc.network_profile.load_balancer_sku = loadbalancer_sku
39754020
return mc
39764021

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

0 commit comments

Comments
 (0)