Skip to content

Commit c5bd23f

Browse files
authored
[AKS] az aks create/approuting: Add default NIC config for app routing (#31286)
1 parent 930ec5d commit c5bd23f

14 files changed

+5674
-2901
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,13 @@
167167
CONST_AZURE_KEYVAULT_NETWORK_ACCESS_PUBLIC = "Public"
168168
CONST_AZURE_KEYVAULT_NETWORK_ACCESS_PRIVATE = "Private"
169169

170+
# app routing nginx config options
171+
CONST_WEB_APPLICATION_ROUTING_KEY_NAME = "ingress/webApplicationRouting"
172+
CONST_APP_ROUTING_ANNOTATION_CONTROLLED_NGINX = "AnnotationControlled"
173+
CONST_APP_ROUTING_EXTERNAL_NGINX = "External"
174+
CONST_APP_ROUTING_INTERNAL_NGINX = "Internal"
175+
CONST_APP_ROUTING_NONE_NGINX = "None"
176+
170177
# all supported addons
171178
ADDONS = {
172179
'http_application_routing': CONST_HTTP_APPLICATION_ROUTING_ADDON_NAME,
@@ -177,7 +184,8 @@
177184
'ingress-appgw': CONST_INGRESS_APPGW_ADDON_NAME,
178185
"confcom": CONST_CONFCOM_ADDON_NAME,
179186
'open-service-mesh': CONST_OPEN_SERVICE_MESH_ADDON_NAME,
180-
'azure-keyvault-secrets-provider': CONST_AZURE_KEYVAULT_SECRETS_PROVIDER_ADDON_NAME
187+
'azure-keyvault-secrets-provider': CONST_AZURE_KEYVAULT_SECRETS_PROVIDER_ADDON_NAME,
188+
"web_application_routing": CONST_WEB_APPLICATION_ROUTING_KEY_NAME,
181189
}
182190

183191
# consts for check-acr command

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,9 @@
542542
- name: --enable-app-routing
543543
type: bool
544544
short-summary: Enable Application Routing addon.
545+
- name: --app-routing-default-nginx-controller --ardnc
546+
type: string
547+
short-summary: Configure default nginx ingress controller type. Valid values are annotationControlled (default behavior), external, internal, or none.
545548
- name: --revision
546549
type: string
547550
short-summary: Azure Service Mesh revision to install.
@@ -2469,6 +2472,10 @@
24692472
type: string
24702473
short-summary: Attach a keyvault id to access secrets and certificates.
24712474
long-summary: This optional flag attaches a keyvault id to access secrets and certificates.
2475+
- name: --nginx
2476+
type: string
2477+
short-summary: Configure default NginxIngressController resource
2478+
long-summary: Configure default nginx ingress controller type. Valid values are annotationControlled (default behavior), external, internal, or none.
24722479
"""
24732480

24742481
helps['aks approuting disable'] = """
@@ -2490,6 +2497,10 @@
24902497
type: bool
24912498
short-summary: Enable the keyvault secrets provider addon.
24922499
long-summary: This optional flag enables the keyvault-secrets-provider addon in given cluster. This is required for most App Routing use-cases.
2500+
- name: --nginx
2501+
type: string
2502+
short-summary: Configure default NginxIngressController resource
2503+
long-summary: Configure default nginx ingress controller type. Valid values are annotationControlled (default behavior), external, internal, or none.
24932504
"""
24942505

24952506
helps['aks approuting zone'] = """

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@
5252
CONST_NRG_LOCKDOWN_RESTRICTION_LEVEL_READONLY,
5353
CONST_NRG_LOCKDOWN_RESTRICTION_LEVEL_UNRESTRICTED,
5454
CONST_ARTIFACT_SOURCE_DIRECT,
55-
CONST_ARTIFACT_SOURCE_CACHE)
55+
CONST_ARTIFACT_SOURCE_CACHE,
56+
CONST_APP_ROUTING_ANNOTATION_CONTROLLED_NGINX,
57+
CONST_APP_ROUTING_EXTERNAL_NGINX,
58+
CONST_APP_ROUTING_INTERNAL_NGINX,
59+
CONST_APP_ROUTING_NONE_NGINX)
5660
from azure.cli.command_modules.acs.azurecontainerstorage._consts import (
5761
CONST_ACSTOR_ALL,
5862
CONST_DISK_TYPE_EPHEMERAL_VOLUME_ONLY,
@@ -283,9 +287,16 @@
283287
CONST_ARTIFACT_SOURCE_CACHE,
284288
]
285289

290+
# consts for app routing add-on
291+
app_routing_nginx_configs = [
292+
CONST_APP_ROUTING_ANNOTATION_CONTROLLED_NGINX,
293+
CONST_APP_ROUTING_EXTERNAL_NGINX,
294+
CONST_APP_ROUTING_INTERNAL_NGINX,
295+
CONST_APP_ROUTING_NONE_NGINX
296+
]
286297

287-
def load_arguments(self, _):
288298

299+
def load_arguments(self, _):
289300
acr_arg_type = CLIArgumentType(metavar='ACR_NAME_OR_RESOURCE_ID')
290301
k8s_support_plans = self.get_models("KubernetesSupportPlan", resource_type=ResourceType.MGMT_CONTAINERSERVICE, operation_group='managed_clusters')
291302

@@ -418,6 +429,11 @@ def load_arguments(self, _):
418429
c.argument('rotation_poll_interval')
419430
c.argument('enable_sgxquotehelper', action='store_true')
420431
c.argument('enable_app_routing', action="store_true")
432+
c.argument(
433+
"app_routing_default_nginx_controller",
434+
arg_type=get_enum_type(app_routing_nginx_configs),
435+
options_list=["--app-routing-default-nginx-controller", "--ardnc"]
436+
)
421437

422438
# nodepool paramerters
423439
c.argument('nodepool_name', default='nodepool1',
@@ -975,10 +991,12 @@ def load_arguments(self, _):
975991
with self.argument_context('aks approuting enable') as c:
976992
c.argument('enable_kv', action='store_true')
977993
c.argument('keyvault_id', options_list=['--attach-kv'])
994+
c.argument("nginx", arg_type=get_enum_type(app_routing_nginx_configs))
978995

979996
with self.argument_context('aks approuting update') as c:
980997
c.argument('keyvault_id', options_list=['--attach-kv'])
981998
c.argument('enable_kv', action='store_true')
999+
c.argument("nginx", arg_type=get_enum_type(app_routing_nginx_configs))
9821000

9831001
with self.argument_context('aks approuting zone add') as c:
9841002
c.argument('dns_zone_resource_ids', options_list=['--ids'], required=True)

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,7 @@ def aks_create(
601601
enable_secret_rotation=False,
602602
rotation_poll_interval=None,
603603
enable_app_routing=False,
604+
app_routing_default_nginx_controller=None,
604605
# nodepool paramerters
605606
nodepool_name="nodepool1",
606607
node_vm_size=None,
@@ -3201,7 +3202,8 @@ def aks_approuting_enable(
32013202
resource_group_name,
32023203
name,
32033204
enable_kv=False,
3204-
keyvault_id=None
3205+
keyvault_id=None,
3206+
nginx=None
32053207
):
32063208
return _aks_approuting_update(
32073209
cmd,
@@ -3210,7 +3212,8 @@ def aks_approuting_enable(
32103212
name,
32113213
enable_app_routing=True,
32123214
keyvault_id=keyvault_id,
3213-
enable_kv=enable_kv)
3215+
enable_kv=enable_kv,
3216+
nginx=nginx)
32143217

32153218

32163219
def aks_approuting_disable(
@@ -3233,15 +3236,17 @@ def aks_approuting_update(
32333236
resource_group_name,
32343237
name,
32353238
keyvault_id=None,
3236-
enable_kv=False
3239+
enable_kv=False,
3240+
nginx=None
32373241
):
32383242
return _aks_approuting_update(
32393243
cmd,
32403244
client,
32413245
resource_group_name,
32423246
name,
32433247
keyvault_id=keyvault_id,
3244-
enable_kv=enable_kv)
3248+
enable_kv=enable_kv,
3249+
nginx=nginx)
32453250

32463251

32473252
def aks_approuting_zone_add(
@@ -3336,7 +3341,8 @@ def _aks_approuting_update(
33363341
delete_dns_zone=None,
33373342
update_dns_zone=None,
33383343
dns_zone_resource_ids=None,
3339-
attach_zones=None
3344+
attach_zones=None,
3345+
nginx=None
33403346
):
33413347
from azure.cli.command_modules.acs.managed_cluster_decorator import AKSManagedClusterUpdateDecorator
33423348

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
ManagedClusterStorageProfileSnapshotController = TypeVar('ManagedClusterStorageProfileSnapshotController')
142142
ManagedClusterIngressProfile = TypeVar("ManagedClusterIngressProfile")
143143
ManagedClusterIngressProfileWebAppRouting = TypeVar("ManagedClusterIngressProfileWebAppRouting")
144+
ManagedClusterIngressProfileNginx = TypeVar("ManagedClusterIngressProfileNginx")
144145
ServiceMeshProfile = TypeVar("ServiceMeshProfile")
145146

146147
# TODO
@@ -815,6 +816,18 @@ def get_update_dns_zone(self) -> bool:
815816
"""
816817
return self.raw_param.get("update_dns_zone")
817818

819+
def get_app_routing_default_nginx_controller(self) -> str:
820+
"""Obtain the value of app_routing_default_nginx_controller.
821+
:return: str
822+
"""
823+
return self.raw_param.get("app_routing_default_nginx_controller")
824+
825+
def get_nginx(self):
826+
"""Obtain the value of nginx, written to the update decorator context by _aks_approuting_update
827+
:return: string
828+
"""
829+
return self.raw_param.get("nginx")
830+
818831
def get_enable_keda(self) -> bool:
819832
"""Obtain the value of enable_keda.
820833
@@ -6689,6 +6702,16 @@ def set_up_ingress_web_app_routing(self, mc: ManagedCluster) -> ManagedCluster:
66896702
mc.ingress_profile.web_app_routing = (
66906703
self.models.ManagedClusterIngressProfileWebAppRouting(enabled=True) # pylint: disable=no-member
66916704
)
6705+
6706+
nginx_ingress_controller = self.context.get_app_routing_default_nginx_controller()
6707+
6708+
if nginx_ingress_controller:
6709+
mc.ingress_profile.web_app_routing.nginx = (
6710+
self.models.ManagedClusterIngressProfileNginx(
6711+
default_ingress_controller_type=nginx_ingress_controller
6712+
)
6713+
)
6714+
66926715
if "web_application_routing" in addons:
66936716
dns_zone_resource_ids = self.context.get_dns_zone_resource_ids()
66946717
mc.ingress_profile.web_app_routing.dns_zone_resource_ids = dns_zone_resource_ids
@@ -8076,6 +8099,7 @@ def update_app_routing_profile(self, mc: ManagedCluster) -> ManagedCluster:
80768099
enable_app_routing = self.context.get_enable_app_routing()
80778100
enable_keyvault_secret_provider = self.context.get_enable_kv()
80788101
dns_zone_resource_ids = self.context.get_dns_zone_resource_ids_from_input()
8102+
nginx = self.context.get_nginx()
80798103

80808104
# update ManagedCluster object with app routing settings
80818105
mc.ingress_profile = (
@@ -8104,8 +8128,24 @@ def update_app_routing_profile(self, mc: ManagedCluster) -> ManagedCluster:
81048128
if dns_zone_resource_ids:
81058129
self._update_dns_zone_resource_ids(mc, dns_zone_resource_ids)
81068130

8131+
# modify default nic config
8132+
if nginx:
8133+
self._update_app_routing_nginx(mc, nginx)
8134+
81078135
return mc
81088136

8137+
def _update_app_routing_nginx(self, mc: ManagedCluster, nginx) -> None:
8138+
"""Helper function to set default nginx ingress controller config for app routing
8139+
:return: None
8140+
"""
8141+
# web app routing object has been created
8142+
if mc.ingress_profile and mc.ingress_profile.web_app_routing and mc.ingress_profile.web_app_routing.enabled:
8143+
if mc.ingress_profile.web_app_routing.nginx is None:
8144+
mc.ingress_profile.web_app_routing.nginx = self.models.ManagedClusterIngressProfileNginx()
8145+
mc.ingress_profile.web_app_routing.nginx.default_ingress_controller_type = nginx
8146+
else:
8147+
raise CLIError('App Routing must be enabled to modify the default nginx ingress controller.\n')
8148+
81098149
def update_node_resource_group_profile(self, mc: ManagedCluster) -> ManagedCluster:
81108150
"""Update node resource group profile for the ManagedCluster object.
81118151
:return: the ManagedCluster object

0 commit comments

Comments
 (0)