Skip to content

Commit 92148c2

Browse files
committed
feat: Support az aks loadbalancer commands
1 parent edef6a6 commit 92148c2

File tree

11 files changed

+4780
-1
lines changed

11 files changed

+4780
-1
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/_client_factory.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,7 @@ def get_providers_client_factory(cli_ctx, subscription_id=None):
151151

152152
def get_keyvault_client(cli_ctx, subscription_id=None):
153153
return get_mgmt_service_client(cli_ctx, ResourceType.MGMT_KEYVAULT, subscription_id=subscription_id).vaults
154+
155+
156+
def cf_load_balancers(cli_ctx, *_):
157+
return get_container_service_client(cli_ctx).load_balancers

src/aks-preview/azext_aks_preview/_help.py

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3260,3 +3260,119 @@
32603260
type: string
32613261
short-summary: Additional endpoint(s) to perform the connectivity check, separated by comma.
32623262
"""
3263+
3264+
helps['aks loadbalancer'] = """
3265+
type: group
3266+
short-summary: Commands to manage load balancer configurations in a managed Kubernetes cluster.
3267+
long-summary: These commands enable the feature of multiple standard load balancers for Azure Kubernetes Service clusters.
3268+
"""
3269+
3270+
helps['aks loadbalancer add'] = """
3271+
type: command
3272+
short-summary: Add a load balancer configuration to a managed Kubernetes cluster.
3273+
parameters:
3274+
- name: --name -n
3275+
type: string
3276+
short-summary: Name of the load balancer configuration.
3277+
long-summary: Load balancer name used for identification. There must be a configuration named "kubernetes" in the cluster.
3278+
- name: --primary-agent-pool-name -p
3279+
type: string
3280+
short-summary: Name of the primary agent pool for this load balancer.
3281+
long-summary: Required field. A string value that must specify the ID of an existing agent pool. All nodes in the given pool will always be added to this load balancer.
3282+
- name: --allow-service-placement -a
3283+
type: bool
3284+
short-summary: Whether to automatically place services on the load balancer.
3285+
long-summary: If not supplied, the default value is true. If set to false manually, both the external and internal load balancer will not be selected for services unless they explicitly target it.
3286+
- name: --service-label-selector -l
3287+
type: string
3288+
short-summary: Label selector for services that can be placed on this load balancer.
3289+
long-summary: Only services that match this selector can be placed on this load balancer. Format as comma-separated key=value pairs or expressions like "key In value1,value2".
3290+
- name: --service-namespace-selector -s
3291+
type: string
3292+
short-summary: Namespace label selector for services that can be placed on this load balancer.
3293+
long-summary: Services created in namespaces that match the selector can be placed on this load balancer. Format as comma-separated key=value pairs.
3294+
- name: --node-selector -d
3295+
type: string
3296+
short-summary: Node label selector for nodes that can be members of this load balancer.
3297+
long-summary: Nodes that match this selector will be possible members of this load balancer. Format as comma-separated key=value pairs.
3298+
examples:
3299+
- name: Add a load balancer configuration with a specific primary agent pool
3300+
text: az aks loadbalancer add -g MyResourceGroup -n secondary --cluster-name MyManagedCluster --primary-agent-pool-name nodepool1
3301+
- name: Add a load balancer configuration with service label selector
3302+
text: az aks loadbalancer add -g MyResourceGroup -n app-lb --cluster-name MyManagedCluster --primary-agent-pool-name nodepool2 --service-label-selector app=frontend
3303+
- name: Add a load balancer configuration that doesn't automatically place services
3304+
text: az aks loadbalancer add -g MyResourceGroup -n restricted-lb --cluster-name MyManagedCluster --primary-agent-pool-name nodepool3 --allow-service-placement false
3305+
"""
3306+
3307+
helps['aks loadbalancer update'] = """
3308+
type: command
3309+
short-summary: Update a load balancer configuration in a managed Kubernetes cluster.
3310+
parameters:
3311+
- name: --name -n
3312+
type: string
3313+
short-summary: Name of the load balancer configuration to update.
3314+
- name: --primary-agent-pool-name -p
3315+
type: string
3316+
short-summary: Name of the primary agent pool for this load balancer.
3317+
long-summary: A string value that must specify the ID of an existing agent pool. All nodes in the given pool will always be added to this load balancer.
3318+
- name: --allow-service-placement -a
3319+
type: bool
3320+
short-summary: Whether to automatically place services on the load balancer.
3321+
long-summary: If set to false, both the external and internal load balancer will not be selected for services unless they explicitly target it.
3322+
- name: --service-label-selector -l
3323+
type: string
3324+
short-summary: Label selector for services that can be placed on this load balancer.
3325+
long-summary: Only services that match this selector can be placed on this load balancer. Format as comma-separated key=value pairs or expressions like "key In value1,value2".
3326+
- name: --service-namespace-selector -s
3327+
type: string
3328+
short-summary: Namespace label selector for services that can be placed on this load balancer.
3329+
long-summary: Services created in namespaces that match the selector can be placed on this load balancer. Format as comma-separated key=value pairs.
3330+
- name: --node-selector -d
3331+
type: string
3332+
short-summary: Node label selector for nodes that can be members of this load balancer.
3333+
long-summary: Nodes that match this selector will be possible members of this load balancer. Format as comma-separated key=value pairs.
3334+
examples:
3335+
- name: Update a load balancer configuration's primary agent pool
3336+
text: az aks loadbalancer update -g MyResourceGroup -n secondary --cluster-name MyManagedCluster --primary-agent-pool-name nodepool2
3337+
- name: Update a load balancer configuration to disable automatic service placement
3338+
text: az aks loadbalancer update -g MyResourceGroup -n app-lb --cluster-name MyManagedCluster --allow-service-placement false
3339+
- name: Update a load balancer configuration with new service selector
3340+
text: az aks loadbalancer update -g MyResourceGroup -n app-lb --cluster-name MyManagedCluster --service-label-selector tier=frontend,environment=production
3341+
"""
3342+
3343+
helps['aks loadbalancer delete'] = """
3344+
type: command
3345+
short-summary: Delete a load balancer configuration from a managed Kubernetes cluster.
3346+
parameters:
3347+
- name: --name -n
3348+
type: string
3349+
short-summary: Name of the load balancer configuration to delete.
3350+
long-summary: The "kubernetes" load balancer cannot be deleted as it's required for cluster operation.
3351+
examples:
3352+
- name: Delete a load balancer configuration
3353+
text: az aks loadbalancer delete -g MyResourceGroup -n secondary --cluster-name MyManagedCluster
3354+
"""
3355+
3356+
helps['aks loadbalancer list'] = """
3357+
type: command
3358+
short-summary: List all load balancer configurations in a managed Kubernetes cluster.
3359+
examples:
3360+
- name: List all load balancer configurations
3361+
text: az aks loadbalancer list -g MyResourceGroup --cluster-name MyManagedCluster
3362+
- name: List all load balancer configurations in table format
3363+
text: az aks loadbalancer list -g MyResourceGroup --cluster-name MyManagedCluster -o table
3364+
"""
3365+
3366+
helps['aks loadbalancer show'] = """
3367+
type: command
3368+
short-summary: Show details of a specific load balancer configuration in a managed Kubernetes cluster.
3369+
parameters:
3370+
- name: --name -n
3371+
type: string
3372+
short-summary: Name of the load balancer configuration to show.
3373+
examples:
3374+
- name: Show details of a specific load balancer configuration
3375+
text: az aks loadbalancer show -g MyResourceGroup -n secondary --cluster-name MyManagedCluster
3376+
- name: Show details of a load balancer configuration in table format
3377+
text: az aks loadbalancer show -g MyResourceGroup -n kubernetes --cluster-name MyManagedCluster -o table
3378+
"""

src/aks-preview/azext_aks_preview/_params.py

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2290,6 +2290,141 @@ def load_arguments(self, _):
22902290
help='Space-separated additional endpoint(s) to perform the connectivity check.',
22912291
validator=validate_custom_endpoints)
22922292

2293+
# AKS loadbalancer command parameter configuration
2294+
with self.argument_context("aks loadbalancer add") as c:
2295+
c.argument(
2296+
"name",
2297+
options_list=["--name", "-n"],
2298+
help="Name of the load balancer configuration. Required.",
2299+
)
2300+
c.argument(
2301+
"primary_agent_pool_name",
2302+
options_list=["--primary-agent-pool-name", "-p"],
2303+
help=(
2304+
"Name of the primary agent pool for this load balancer. "
2305+
"All nodes in this pool will be added to the load balancer. Required."
2306+
),
2307+
)
2308+
c.argument(
2309+
"allow_service_placement",
2310+
options_list=["--allow-service-placement", "-a"],
2311+
arg_type=get_three_state_flag(),
2312+
help="Whether to automatically place services on the load balancer. Default is true.",
2313+
)
2314+
c.argument(
2315+
"service_label_selector",
2316+
options_list=["--service-label-selector", "-l"],
2317+
help=(
2318+
"Only services that match this selector can be placed on this load balancer. "
2319+
"Format: key1=value1,key2=value2 for simple selectors, "
2320+
"or key1 In val1 val2,key2 Exists for advanced expressions."
2321+
),
2322+
)
2323+
c.argument(
2324+
"service_namespace_selector",
2325+
options_list=["--service-namespace-selector", "-s"],
2326+
help=(
2327+
"Services created in namespaces that match the selector can be placed on this load balancer. "
2328+
"Format: key1=value1,key2=value2 for simple selectors, "
2329+
"or key1 In val1 val2,key2 Exists for advanced expressions."
2330+
),
2331+
)
2332+
c.argument(
2333+
"node_selector",
2334+
options_list=["--node-selector", "-d"],
2335+
help=(
2336+
"Nodes that match this selector will be possible members of this load balancer. "
2337+
"Format: key1=value1,key2=value2 for simple selectors, "
2338+
"or key1 In val1 val2,key2 Exists for advanced expressions."
2339+
),
2340+
)
2341+
2342+
with self.argument_context("aks loadbalancer rebalance-nodes") as c:
2343+
c.argument(
2344+
"resource_group_name",
2345+
options_list=["--resource-group", "-g"],
2346+
help="Name of resource group.",
2347+
id_part="resource_group",
2348+
configured_default="aks",
2349+
)
2350+
c.argument(
2351+
"cluster_name",
2352+
options_list=["--name", "-n"],
2353+
help="Name of the managed cluster.",
2354+
)
2355+
c.argument(
2356+
"load_balancer_names",
2357+
options_list=["--load-balancer-names", "--lb-names"],
2358+
nargs="+",
2359+
help=(
2360+
"Space-separated list of load balancer names to rebalance. "
2361+
"If not specified, all load balancers will be rebalanced."
2362+
),
2363+
)
2364+
c.argument(
2365+
"no_wait", help="Do not wait for the long-running operation to finish."
2366+
)
2367+
2368+
with self.argument_context("aks loadbalancer update") as c:
2369+
c.argument(
2370+
"name",
2371+
options_list=["--name", "-n"],
2372+
help="Name of the public load balancer. Required.",
2373+
)
2374+
c.argument(
2375+
"primary_agent_pool_name",
2376+
options_list=["--primary-agent-pool-name", "-p"],
2377+
help=(
2378+
"Name of the primary agent pool for this load balancer. "
2379+
"All nodes in this pool will be added to the load balancer."
2380+
),
2381+
)
2382+
c.argument(
2383+
"allow_service_placement",
2384+
options_list=["--allow-service-placement", "-a"],
2385+
arg_type=get_three_state_flag(),
2386+
help="Whether to automatically place services on the load balancer. Default is true.",
2387+
)
2388+
c.argument(
2389+
"service_label_selector",
2390+
options_list=["--service-label-selector", "-l"],
2391+
help=(
2392+
"Only services that match this selector can be placed on this load balancer. "
2393+
"Format: key1=value1,key2=value2 for simple selectors, "
2394+
"or key1 In val1 val2,key2 Exists for advanced expressions."
2395+
),
2396+
)
2397+
c.argument(
2398+
"service_namespace_selector",
2399+
options_list=["--service-namespace-selector", "-s"],
2400+
help=(
2401+
"Services created in namespaces that match the selector can be placed on this load balancer. "
2402+
"Format: key1=value1,key2=value2 for simple selectors, "
2403+
"or key1 In val1 val2,key2 Exists for advanced expressions."
2404+
),
2405+
)
2406+
c.argument(
2407+
"node_selector",
2408+
options_list=["--node-selector", "-d"],
2409+
help=(
2410+
"Nodes that match this selector will be possible members of this load balancer. "
2411+
"Format: key1=value1,key2=value2 for simple selectors, "
2412+
"or key1 In val1 val2,key2 Exists for advanced expressions."
2413+
),
2414+
)
2415+
2416+
# Define parameters for show and delete commands
2417+
for scope in [
2418+
"aks loadbalancer show",
2419+
"aks loadbalancer delete",
2420+
]:
2421+
with self.argument_context(scope) as c:
2422+
c.argument(
2423+
"name",
2424+
options_list=["--name", "-n"],
2425+
help="Name of the load balancer configuration. Required.",
2426+
)
2427+
22932428

22942429
def _get_default_install_location(exe_name):
22952430
system = platform.system()

src/aks-preview/azext_aks_preview/commands.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
cf_trustedaccess_role_binding,
1616
cf_machines,
1717
cf_operations,
18+
cf_load_balancers,
1819
)
1920
from azext_aks_preview._format import (
2021
aks_addon_list_available_table_format,
@@ -196,6 +197,18 @@ def load_command_table(self, _):
196197
g.custom_command("update", "aks_maintenanceconfiguration_update")
197198
g.custom_command("delete", "aks_maintenanceconfiguration_delete")
198199

200+
# AKS loadbalancer commands
201+
with self.command_group(
202+
"aks loadbalancer",
203+
client_factory=cf_load_balancers,
204+
) as g:
205+
g.custom_command("list", "aks_loadbalancer_list")
206+
g.custom_show_command("show", "aks_loadbalancer_show")
207+
g.custom_command("add", "aks_loadbalancer_add")
208+
g.custom_command("update", "aks_loadbalancer_update")
209+
g.custom_command("delete", "aks_loadbalancer_delete")
210+
g.custom_command("rebalance-nodes", "aks_loadbalancer_rebalance_nodes")
211+
199212
# AKS addon commands
200213
with self.command_group(
201214
"aks addon", managed_clusters_sdk, client_factory=cf_managed_clusters

0 commit comments

Comments
 (0)