Skip to content

Commit 37f839c

Browse files
Application Gateway for Containers addon commands (#9387)
* Application Gateway for Containers add-on commands * Update HISTORY.rst * Update HISTORY.rst * Update HISTORY.rst * Update HISTORY.rst * Update src/aks-preview/azext_aks_preview/managed_cluster_decorator.py Co-authored-by: Copilot <[email protected]> * tests * enable params * parameter length linter exclusion * Enable gateway api * Missing update and passing test * Linter exception * Linter - take 2 * Update HISTORY.rst * Update src/aks-preview/azext_aks_preview/tests/latest/test_aks_commands.py Co-authored-by: Copilot <[email protected]> * Update src/aks-preview/azext_aks_preview/tests/latest/test_aks_commands.py Co-authored-by: Copilot <[email protected]> * Update src/aks-preview/azext_aks_preview/tests/latest/test_aks_commands.py Co-authored-by: Copilot <[email protected]> * Update src/aks-preview/azext_aks_preview/tests/latest/test_aks_commands.py Co-authored-by: Copilot <[email protected]> * Update src/aks-preview/azext_aks_preview/custom.py Co-authored-by: Copilot <[email protected]> * Update src/aks-preview/azext_aks_preview/tests/latest/test_aks_commands.py Co-authored-by: Copilot <[email protected]> * Update custom.py * update test results --------- Co-authored-by: Copilot <[email protected]>
1 parent 5c28c3b commit 37f839c

File tree

11 files changed

+2016
-5
lines changed

11 files changed

+2016
-5
lines changed

linter_exclusions.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ aks create:
4040
enable_private_cluster:
4141
rule_exclusions:
4242
- option_length_too_long
43+
enable_application_load_balancer:
44+
rule_exclusions:
45+
- option_length_too_long
4346
load_balancer_idle_timeout:
4447
rule_exclusions:
4548
- option_length_too_long
@@ -198,6 +201,12 @@ aks update:
198201
cluster_service_load_balancer_health_probe_mode:
199202
rule_exclusions:
200203
- option_length_too_long
204+
enable_application_load_balancer:
205+
rule_exclusions:
206+
- option_length_too_long
207+
disable_application_load_balancer:
208+
rule_exclusions:
209+
- option_length_too_long
201210
aks agent:
202211
parameters:
203212
prompt:

src/aks-preview/HISTORY.rst

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

1212
Pending
1313
+++++++
14+
* Add add-on support for `ApplicationLoadBalancer` (Application Gateway for Containers)
15+
- AKS Create and Update parameters for `--enable-application-load-balancer` and `--disable-application-load-balancer`
16+
- `az aks applicationloadbalancer enable`: Enable Application Load Balancer add-on for an existing cluster.
17+
- `az aks applicationloadbalancer disable`: Disable Application Load Balancer add-on for an existing cluster.
18+
- `az aks applicationloadbalancer update`: Update Application Load Balancer add-on for an existing cluster.
1419

1520
19.0.0b18
1621
+++++++

src/aks-preview/azext_aks_preview/_consts.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@
168168
CONST_DISK_DRIVER_V2 = "v2"
169169

170170
# consts for addons
171+
# application load balancer (Application Gateway for Containers)
172+
CONST_APPLICATION_LOAD_BALANCER_ADDON_NAME = "applicationLoadBalancer"
173+
171174
# http application routing
172175
CONST_HTTP_APPLICATION_ROUTING_ADDON_NAME = "httpApplicationRouting"
173176

@@ -225,6 +228,7 @@
225228

226229
# all supported addons
227230
ADDONS = {
231+
"application-load-balancer": CONST_APPLICATION_LOAD_BALANCER_ADDON_NAME,
228232
"http_application_routing": CONST_HTTP_APPLICATION_ROUTING_ADDON_NAME,
229233
"monitoring": CONST_MONITORING_ADDON_NAME,
230234
"virtual-node": CONST_VIRTUAL_NODE_ADDON_NAME,
@@ -255,7 +259,10 @@
255259
"- enable Azure policy. The Azure Policy add-on for AKS enables at-scale enforcements and safeguards on "
256260
"your clusters in a centralized, consistent manner.\nLearn more at aka.ms/aks/policy."
257261
),
258-
CONST_INGRESS_APPGW_ADDON_NAME: "- enable Application Gateway Ingress Controller addon (PREVIEW).",
262+
CONST_APPLICATION_LOAD_BALANCER_ADDON_NAME: (
263+
"- enable Application Load Balancer (Application Gateway for Containers) addon (PREVIEW)."
264+
),
265+
CONST_INGRESS_APPGW_ADDON_NAME: "- enable Application Gateway Ingress Controller addon.",
259266
CONST_CONFCOM_ADDON_NAME: "- enable confcom addon, this will enable SGX device plugin by default (PREVIEW).",
260267
CONST_OPEN_SERVICE_MESH_ADDON_NAME: "- enable Open Service Mesh addon (PREVIEW).",
261268
CONST_AZURE_KEYVAULT_SECRETS_PROVIDER_ADDON_NAME: "- enable Azure Keyvault Secrets Provider addon.",

src/aks-preview/azext_aks_preview/_help.py

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@
175175
- monitoring : turn on Log Analytics monitoring. Uses the Log Analytics Default Workspace if it exists, else creates one. Specify "--workspace-resource-id" to use an existing workspace. If monitoring addon is enabled --no-wait argument will have no effect
176176
- virtual-node : enable AKS Virtual Node. Requires --aci-subnet-name to provide the name of an existing subnet for the Virtual Node to use. aci-subnet-name must be in the same vnet which is specified by --vnet-subnet-id (required as well).
177177
- azure-policy : enable Azure policy. The Azure Policy add-on for AKS enables at-scale enforcements and safeguards on your clusters in a centralized, consistent manner. Required if enabling deployment safeguards. Learn more at aka.ms/aks/policy.
178-
- ingress-appgw : enable Application Gateway Ingress Controller addon (PREVIEW).
178+
- application-load-balancer : enable the Application Load Balancer (Application Gateway for Containers) addon (PREVIEW).
179+
- ingress-appgw : enable Application Gateway Ingress Controller addon.
179180
- confcom : enable confcom addon, this will enable SGX device plugin by default(PREVIEW).
180181
- open-service-mesh : enable Open Service Mesh addon (PREVIEW).
181182
- gitops : enable GitOps (PREVIEW).
@@ -635,6 +636,9 @@
635636
Auto: A standard set of Karpenter NodePools are provisioned.
636637
None: No Karpenter NodePools are provisioned.
637638
WARNING: Changing this from Auto to None on an existing cluster will cause the default Karpenter NodePools to be deleted, which will in turn drain and delete the nodes associated with those pools. It is strongly recommended to not do this unless there are idle nodes ready to take the pods evicted by that action.
639+
- name: --enable-application-load-balancer
640+
type: bool
641+
short-summary: Enable Application Load Balancer (Application Gateway for Containers) addon.
638642
- name: --enable-app-routing
639643
type: bool
640644
short-summary: Enable Application Routing addon.
@@ -1417,6 +1421,12 @@
14171421
- name: --disable-gateway-api
14181422
type: bool
14191423
short-summary: Disable managed installation of Gateway API CRDs.
1424+
- name: --enable-application-load-balancer
1425+
type: bool
1426+
short-summary: Enable Application Load Balancer (Application Gateway for Containers) addon.
1427+
- name: --disable-application-load-balancer
1428+
type: bool
1429+
short-summary: Disable Application Load Balancer (Application Gateway for Containers) addon.
14201430
examples:
14211431
- name: Reconcile the cluster back to its current state.
14221432
text: az aks update -g MyResourceGroup -n MyManagedCluster
@@ -2782,7 +2792,8 @@
27822792
virtual-node - enable AKS Virtual Node. Requires --subnet-name to provide the name of an existing subnet for the Virtual Node to use.
27832793
azure-policy - enable Azure policy. The Azure Policy add-on for AKS enables at-scale enforcements and safeguards on your clusters in a centralized, consistent manner.
27842794
Learn more at aka.ms/aks/policy.
2785-
ingress-appgw - enable Application Gateway Ingress Controller addon (PREVIEW).
2795+
application-load-balancer - enable the Application Load Balancer (Application Gateway for Containers) addon (PREVIEW).
2796+
ingress-appgw - enable Application Gateway Ingress Controller addon.
27862797
open-service-mesh - enable Open Service Mesh addon (PREVIEW).
27872798
gitops - enable GitOps (PREVIEW).
27882799
azure-keyvault-secrets-provider - enable Azure Keyvault Secrets Provider addon.
@@ -2942,7 +2953,8 @@
29422953
virtual-node - enable AKS Virtual Node. Requires --subnet-name to provide the name of an existing subnet for the Virtual Node to use.
29432954
azure-policy - enable Azure policy. The Azure Policy add-on for AKS enables at-scale enforcements and safeguards on your clusters in a centralized, consistent manner.
29442955
Learn more at aka.ms/aks/policy.
2945-
ingress-appgw - enable Application Gateway Ingress Controller addon (PREVIEW).
2956+
application-load-balancer - enable the Application Load Balancer (Application Gateway for Containers) addon (PREVIEW).
2957+
ingress-appgw - enable Application Gateway Ingress Controller addon.
29462958
open-service-mesh - enable Open Service Mesh addon (PREVIEW).
29472959
gitops - enable GitOps (PREVIEW).
29482960
azure-keyvault-secrets-provider - enable Azure Keyvault Secrets Provider addon.
@@ -3615,9 +3627,33 @@
36153627
text: az aks mesh disable-istio-cni --resource-group MyResourceGroup --name MyManagedCluster
36163628
"""
36173629

3630+
helps['aks applicationloadbalancer'] = """
3631+
type: group
3632+
short-summary: Commands to manage Application Load Balancer (Application Gateway for Containers) addon.
3633+
long-summary: A group of commands to manage Application Load Balancer (Application Gateway for Containers) in given cluster.
3634+
"""
3635+
3636+
helps['aks applicationloadbalancer enable'] = """
3637+
type: command
3638+
short-summary: Enable Application Load Balancer (Application Gateway for Containers) addon.
3639+
long-summary: This command enables Application Load Balancer in given cluster.
3640+
"""
3641+
3642+
helps['aks applicationloadbalancer update'] = """
3643+
type: command
3644+
short-summary: Update Application Load Balancer (Application Gateway for Containers) addon.
3645+
long-summary: This command is used to make a put operation on the Application Load Balancer in a given cluster.
3646+
"""
3647+
3648+
helps['aks applicationloadbalancer disable'] = """
3649+
type: command
3650+
short-summary: Disable Application Load Balancer (Application Gateway for Containers) addon.
3651+
long-summary: This command disables Application Load Balancer (Application Gateway for Containers) in given cluster.
3652+
"""
3653+
36183654
helps['aks approuting'] = """
36193655
type: group
3620-
short-summary: Commands to manage App Routing aadon.
3656+
short-summary: Commands to manage App Routing addon.
36213657
long-summary: A group of commands to manage App Routing in given cluster.
36223658
"""
36233659

src/aks-preview/azext_aks_preview/_params.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,7 @@ def load_arguments(self, _):
782782
c.argument("enable_secret_rotation", action="store_true")
783783
c.argument("rotation_poll_interval")
784784
c.argument("enable_sgxquotehelper", action="store_true")
785+
c.argument("enable_application_load_balancer", action="store_true", is_preview=True)
785786
c.argument("enable_app_routing", action="store_true", is_preview=True)
786787
c.argument(
787788
"app_routing_default_nginx_controller",
@@ -1765,6 +1766,18 @@ def load_arguments(self, _):
17651766
action="store_true",
17661767
help="Disable managed installation of Gateway API CRDs."
17671768
)
1769+
c.argument(
1770+
"enable_application_load_balancer",
1771+
action="store_true",
1772+
is_preview=True,
1773+
help="Enable Application Load Balancer (Application Gateway for Containers)."
1774+
)
1775+
c.argument(
1776+
"disable_application_load_balancer",
1777+
action="store_true",
1778+
is_preview=True,
1779+
help="Disable Application Load Balancer (Application Gateway for Containers)."
1780+
)
17681781

17691782
with self.argument_context("aks upgrade") as c:
17701783
c.argument("kubernetes_version", completer=get_k8s_upgrades_completion_list)

src/aks-preview/azext_aks_preview/addonconfiguration.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,11 @@ def update_addons(
253253
resource_type=CUSTOM_MGMT_AKS_PREVIEW,
254254
operation_group="managed_clusters",
255255
)
256+
ManagedClusterIngressProfileApplicationLoadBalancer = cmd.get_models(
257+
"ManagedClusterIngressProfileApplicationLoadBalancer",
258+
resource_type=CUSTOM_MGMT_AKS_PREVIEW,
259+
operation_group="managed_clusters",
260+
)
256261
ManagedClusterIngressProfileWebAppRouting = cmd.get_models(
257262
"ManagedClusterIngressProfileWebAppRouting",
258263
resource_type=CUSTOM_MGMT_AKS_PREVIEW,
@@ -261,6 +266,19 @@ def update_addons(
261266

262267
# for each addons argument
263268
for addon_arg in addon_args:
269+
if addon_arg == "applicationloadbalancer":
270+
# application load balancer settings are in ingress profile, not addon profile
271+
if instance.ingress_profile is None:
272+
instance.ingress_profile = ManagedClusterIngressProfile()
273+
if instance.ingress_profile.application_load_balancer is None:
274+
instance.ingress_profile.application_load_balancer = (
275+
ManagedClusterIngressProfileApplicationLoadBalancer()
276+
)
277+
278+
instance.ingress_profile.application_load_balancer.enabled = enable
279+
280+
continue
281+
264282
if addon_arg == "web_application_routing":
265283
# web app routing settings are in ingress profile, not addon profile, so deal
266284
# with it separately

src/aks-preview/azext_aks_preview/commands.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,14 @@ def load_command_table(self, _):
460460
g.custom_command("complete", "aks_mesh_upgrade_complete", supports_no_wait=True)
461461
g.custom_command("rollback", "aks_mesh_upgrade_rollback", supports_no_wait=True)
462462

463+
# AKS applicationloadbalancer (Application Gateway for Containers) commands
464+
with self.command_group(
465+
"aks applicationloadbalancer", managed_clusters_sdk, client_factory=cf_managed_clusters
466+
) as g:
467+
g.custom_command("enable", "aks_applicationloadbalancer_enable")
468+
g.custom_command("disable", "aks_applicationloadbalancer_disable", confirmation=True)
469+
g.custom_command("update", "aks_applicationloadbalancer_update")
470+
463471
# AKS approuting commands
464472
with self.command_group(
465473
"aks approuting", managed_clusters_sdk, client_factory=cf_managed_clusters

src/aks-preview/azext_aks_preview/custom.py

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,7 @@ def aks_create(
10251025
enable_sgxquotehelper=False,
10261026
enable_secret_rotation=False,
10271027
rotation_poll_interval=None,
1028+
enable_application_load_balancer=False,
10281029
enable_app_routing=False,
10291030
app_routing_default_nginx_controller=None,
10301031
# nodepool paramerters
@@ -1399,6 +1400,9 @@ def aks_update(
13991400
# managed gateway installation
14001401
enable_gateway_api=False,
14011402
disable_gateway_api=False,
1403+
# application load balancer
1404+
enable_application_load_balancer=False,
1405+
disable_application_load_balancer=False,
14021406
):
14031407
# DO NOT MOVE: get all the original parameters and save them as a dictionary
14041408
raw_parameters = locals()
@@ -2666,6 +2670,12 @@ def aks_addon_list(cmd, client, resource_group_name, name):
26662670
mc.ingress_profile.web_app_routing and
26672671
mc.ingress_profile.web_app_routing.enabled
26682672
)
2673+
elif addon_name == "application-load-balancer":
2674+
enabled = bool(
2675+
mc.ingress_profile and
2676+
mc.ingress_profile.application_load_balancer and
2677+
mc.ingress_profile.application_load_balancer.enabled
2678+
)
26692679
else:
26702680
if addon_name == "virtual-node":
26712681
addon_key += os_type
@@ -2702,6 +2712,20 @@ def aks_addon_show(cmd, client, resource_group_name, name, addon):
27022712
"config": mc.ingress_profile.web_app_routing,
27032713
}
27042714

2715+
# application-load-balancer is a special case, the configuration is stored in a separate profile
2716+
if addon == "application-load-balancer":
2717+
if (
2718+
not mc.ingress_profile and
2719+
not mc.ingress_profile.application_load_balancer and
2720+
not mc.ingress_profile.application_load_balancer.enabled
2721+
):
2722+
raise InvalidArgumentValueError(f'Addon "{addon}" is not enabled in this cluster.')
2723+
return {
2724+
"name": addon,
2725+
"api_key": addon_key,
2726+
"config": mc.ingress_profile.application_load_balancer,
2727+
}
2728+
27052729
# normal addons
27062730
if not mc.addon_profiles or addon_key not in mc.addon_profiles or not mc.addon_profiles[addon_key].enabled:
27072731
raise InvalidArgumentValueError(f'Addon "{addon}" is not enabled in this cluster.')
@@ -3099,6 +3123,11 @@ def _update_addons(cmd, # pylint: disable=too-many-branches,too-many-statements
30993123
resource_type=CUSTOM_MGMT_AKS_PREVIEW,
31003124
operation_group="managed_clusters",
31013125
)
3126+
ManagedClusterIngressProfileApplicationLoadBalancer = cmd.get_models(
3127+
"ManagedClusterIngressProfileApplicationLoadBalancer",
3128+
resource_type=CUSTOM_MGMT_AKS_PREVIEW,
3129+
operation_group="managed_clusters",
3130+
)
31023131
ManagedClusterIngressProfileWebAppRouting = cmd.get_models(
31033132
"ManagedClusterIngressProfileWebAppRouting",
31043133
resource_type=CUSTOM_MGMT_AKS_PREVIEW,
@@ -3114,6 +3143,16 @@ def _update_addons(cmd, # pylint: disable=too-many-branches,too-many-statements
31143143

31153144
# for each addons argument
31163145
for addon_arg in addon_args:
3146+
if addon_arg == "applicationloadbalancer":
3147+
# application load balancer routing settings are in ingress profile, not addon profile
3148+
if instance.ingress_profile is None:
3149+
instance.ingress_profile = ManagedClusterIngressProfile()
3150+
if instance.ingress_profile.application_load_balancer is None:
3151+
instance.ingress_profile.application_load_balancer = ManagedClusterIngressProfileApplicationLoadBalancer()
3152+
instance.ingress_profile.application_load_balancer.enabled = enable
3153+
3154+
continue
3155+
31173156
if addon_arg == "web_application_routing":
31183157
# web app routing settings are in ingress profile, not addon profile, so deal
31193158
# with it separately
@@ -4118,6 +4157,47 @@ def _aks_mesh_update(
41184157
return aks_update_decorator.update_mc(mc)
41194158

41204159

4160+
def aks_applicationloadbalancer_enable(
4161+
cmd,
4162+
client,
4163+
resource_group_name,
4164+
name
4165+
):
4166+
return _aks_applicationloadbalancer_update(
4167+
cmd,
4168+
client,
4169+
resource_group_name,
4170+
name,
4171+
enable_application_load_balancer=True)
4172+
4173+
4174+
def aks_applicationloadbalancer_disable(
4175+
cmd,
4176+
client,
4177+
resource_group_name,
4178+
name
4179+
):
4180+
return _aks_applicationloadbalancer_update(
4181+
cmd,
4182+
client,
4183+
resource_group_name,
4184+
name,
4185+
disable_application_load_balancer=True)
4186+
4187+
4188+
def aks_applicationloadbalancer_update(
4189+
cmd,
4190+
client,
4191+
resource_group_name,
4192+
name
4193+
):
4194+
return _aks_applicationloadbalancer_update(
4195+
cmd,
4196+
client,
4197+
resource_group_name,
4198+
name)
4199+
4200+
41214201
def aks_approuting_enable(
41224202
cmd,
41234203
client,
@@ -4250,6 +4330,36 @@ def aks_approuting_zone_list(
42504330
raise CLIError('App routing addon is not enabled')
42514331

42524332

4333+
# pylint: disable=unused-argument
4334+
def _aks_applicationloadbalancer_update(
4335+
cmd,
4336+
client,
4337+
resource_group_name,
4338+
name,
4339+
enable_application_load_balancer=None,
4340+
disable_application_load_balancer=None
4341+
):
4342+
from azure.cli.command_modules.acs._consts import DecoratorEarlyExitException
4343+
from azext_aks_preview.managed_cluster_decorator import AKSPreviewManagedClusterUpdateDecorator
4344+
4345+
raw_parameters = locals()
4346+
4347+
aks_update_decorator = AKSPreviewManagedClusterUpdateDecorator(
4348+
cmd=cmd,
4349+
client=client,
4350+
raw_parameters=raw_parameters,
4351+
resource_type=CUSTOM_MGMT_AKS_PREVIEW,
4352+
)
4353+
4354+
try:
4355+
mc = aks_update_decorator.fetch_mc()
4356+
mc = aks_update_decorator.update_application_load_balancer_profile(mc)
4357+
except DecoratorEarlyExitException:
4358+
return None
4359+
4360+
return aks_update_decorator.update_mc(mc)
4361+
4362+
42534363
# pylint: disable=unused-argument
42544364
def _aks_approuting_update(
42554365
cmd,

0 commit comments

Comments
 (0)