Skip to content

Commit f21cb0e

Browse files
committed
feat: Szupport az aks loadbalancer rebalance-nodes command
1 parent 9338921 commit f21cb0e

File tree

8 files changed

+1225
-361
lines changed

8 files changed

+1225
-361
lines changed

src/aks-preview/HISTORY.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ To release a new version, please select a new version number (usually plus 1 to
1111

1212
Pending
1313
+++++++
14+
15+
13.0.0b9
16+
+++++++
1417
* Vendor new SDK and bump API version to 2024-10-02-preview.
18+
* Support `az aks loadbalancer show/list/add/update/delete/rebalance` commands.
1519

1620
13.0.0b8
1721
+++++++

src/aks-preview/azext_aks_preview/_params.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2323,7 +2323,32 @@ def load_arguments(self, _):
23232323
),
23242324
)
23252325

2326-
# Use same parameters for update command
2326+
with self.argument_context("aks loadbalancer rebalance-nodes") as c:
2327+
c.argument(
2328+
"resource_group_name",
2329+
options_list=["--resource-group", "-g"],
2330+
help="Name of resource group.",
2331+
id_part="resource_group",
2332+
configured_default="aks",
2333+
)
2334+
c.argument(
2335+
"cluster_name",
2336+
options_list=["--name", "-n"],
2337+
help="Name of the managed cluster.",
2338+
)
2339+
c.argument(
2340+
"load_balancer_names",
2341+
options_list=["--load-balancer-names", "--lb-names"],
2342+
nargs="+",
2343+
help=(
2344+
"Space-separated list of load balancer names to rebalance. "
2345+
"If not specified, all load balancers will be rebalanced."
2346+
),
2347+
)
2348+
c.argument(
2349+
"no_wait", help="Do not wait for the long-running operation to finish."
2350+
)
2351+
23272352
with self.argument_context("aks loadbalancer update") as c:
23282353
c.argument(
23292354
"name",

src/aks-preview/azext_aks_preview/commands.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ def load_command_table(self, _):
207207
g.custom_command("add", "aks_loadbalancer_add")
208208
g.custom_command("update", "aks_loadbalancer_update")
209209
g.custom_command("delete", "aks_loadbalancer_delete")
210+
g.custom_command("rebalance-nodes", "aks_loadbalancer_rebalance_nodes")
210211

211212
# AKS addon commands
212213
with self.command_group(
@@ -261,8 +262,12 @@ def load_command_table(self, _):
261262
"aks nodepool manual-scale", managed_clusters_sdk, client_factory=cf_agent_pools
262263
) as g:
263264
g.custom_command("add", "aks_agentpool_manual_scale_add", supports_no_wait=True)
264-
g.custom_command("update", "aks_agentpool_manual_scale_update", supports_no_wait=True)
265-
g.custom_command("delete", "aks_agentpool_manual_scale_delete", supports_no_wait=True)
265+
g.custom_command(
266+
"update", "aks_agentpool_manual_scale_update", supports_no_wait=True
267+
)
268+
g.custom_command(
269+
"delete", "aks_agentpool_manual_scale_delete", supports_no_wait=True
270+
)
266271

267272
with self.command_group(
268273
"aks machine", machines_sdk, client_factory=cf_machines
@@ -278,10 +283,14 @@ def load_command_table(self, _):
278283
"aks operation", operations_sdk, client_factory=cf_operations
279284
) as g:
280285
g.custom_show_command(
281-
"show", "aks_operation_show", table_transformer=aks_operation_show_table_format
286+
"show",
287+
"aks_operation_show",
288+
table_transformer=aks_operation_show_table_format,
282289
)
283290
g.custom_command(
284-
"show-latest", "aks_operation_show_latest", table_transformer=aks_operation_show_table_format
291+
"show-latest",
292+
"aks_operation_show_latest",
293+
table_transformer=aks_operation_show_table_format,
285294
)
286295

287296
# AKS draft commands
@@ -400,7 +409,7 @@ def load_command_table(self, _):
400409
"aks_mesh_disable",
401410
supports_no_wait=True,
402411
confirmation="Existing Azure Service Mesh Profile values will be reset.\n"
403-
+ "Are you sure you want to perform this operation?"
412+
+ "Are you sure you want to perform this operation?",
404413
)
405414
g.custom_command(
406415
"enable-ingress-gateway",

src/aks-preview/azext_aks_preview/custom.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4180,3 +4180,44 @@ def aks_loadbalancer_show(cmd, client, resource_group_name, cluster_name, name):
41804180
:type name: str
41814181
"""
41824182
return client.get(resource_group_name, cluster_name, name)
4183+
4184+
4185+
# pylint: disable=unused-argument
4186+
def aks_loadbalancer_rebalance_nodes(
4187+
cmd,
4188+
client,
4189+
resource_group_name,
4190+
cluster_name,
4191+
load_balancer_names=None,
4192+
):
4193+
"""Rebalance nodes across specific load balancers.
4194+
4195+
:param cmd: Command context
4196+
:param client: AKS client
4197+
:param resource_group_name: Name of resource group.
4198+
:type resource_group_name: str
4199+
:param cluster_name: Name of the managed cluster.
4200+
:type cluster_name: str
4201+
:param load_balancer_names: Names of load balancers to rebalance.
4202+
If not specified, all load balancers will be rebalanced.
4203+
:type load_balancer_names: list[str]
4204+
:param no_wait: Do not wait for the long-running operation to finish.
4205+
:type no_wait: bool
4206+
:return: The result of the rebalance operation
4207+
"""
4208+
from azext_aks_preview.loadbalancerconfiguration import (
4209+
aks_loadbalancer_rebalance_internal,
4210+
)
4211+
from azext_aks_preview._client_factory import cf_load_balancers
4212+
4213+
# Get the load balancers client
4214+
load_balancers_client = cf_load_balancers(cmd.cli_ctx)
4215+
4216+
# Prepare parameters for the internal function
4217+
parameters = {
4218+
"resource_group_name": resource_group_name,
4219+
"cluster_name": cluster_name,
4220+
"load_balancer_names": load_balancer_names,
4221+
}
4222+
4223+
return aks_loadbalancer_rebalance_internal(cmd, load_balancers_client, parameters)

0 commit comments

Comments
 (0)