Skip to content

Commit 4c579af

Browse files
committed
initial attempt
1 parent 024ced1 commit 4c579af

File tree

7 files changed

+327
-8
lines changed

7 files changed

+327
-8
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@
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_APP_ROUTING_ANNOTATION_CONTROLLED_NGINX = "AnnotationControlled"
172+
CONST_APP_ROUTING_EXTERNAL_NGINX = "External"
173+
CONST_APP_ROUTING_INTERNAL_NGINX = "Internal"
174+
CONST_APP_ROUTING_NONE_NGINX = "None"
175+
170176
# all supported addons
171177
ADDONS = {
172178
'http_application_routing': CONST_HTTP_APPLICATION_ROUTING_ADDON_NAME,

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,9 @@
536536
- name: --enable-app-routing
537537
type: bool
538538
short-summary: Enable Application Routing addon.
539+
- name: --app-routing-default-nginx-controller --ardnc
540+
type: string
541+
short-summary: Configure default nginx ingress controller type. Valid values are annotationControlled (default behavior), external, internal, or none.
539542
- name: --revision
540543
type: string
541544
short-summary: Azure Service Mesh revision to install.
@@ -2451,6 +2454,10 @@
24512454
type: string
24522455
short-summary: Attach a keyvault id to access secrets and certificates.
24532456
long-summary: This optional flag attaches a keyvault id to access secrets and certificates.
2457+
- name: --nginx
2458+
type: string
2459+
short-summary: Configure default NginxIngressController resource
2460+
long-summary: Configure default nginx ingress controller type. Valid values are annotationControlled (default behavior), external, internal, or none.
24542461
"""
24552462

24562463
helps['aks approuting disable'] = """
@@ -2472,6 +2479,10 @@
24722479
type: bool
24732480
short-summary: Enable the keyvault secrets provider addon.
24742481
long-summary: This optional flag enables the keyvault-secrets-provider addon in given cluster. This is required for most App Routing use-cases.
2482+
- name: --nginx
2483+
type: string
2484+
short-summary: Configure default NginxIngressController resource
2485+
long-summary: Configure default nginx ingress controller type. Valid values are annotationControlled (default behavior), external, internal, or none.
24752486
"""
24762487

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

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

Lines changed: 19 additions & 1 deletion
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,6 +287,13 @@
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

287298
def load_arguments(self, _):
288299

@@ -416,6 +427,11 @@ def load_arguments(self, _):
416427
c.argument('rotation_poll_interval')
417428
c.argument('enable_sgxquotehelper', action='store_true')
418429
c.argument('enable_app_routing', action="store_true")
430+
c.argument(
431+
"app_routing_default_nginx_controller",
432+
arg_type=get_enum_type(app_routing_nginx_configs),
433+
options_list=["--app-routing-default-nginx-controller", "--ardnc"]
434+
)
419435

420436
# nodepool paramerters
421437
c.argument('nodepool_name', default='nodepool1',
@@ -969,10 +985,12 @@ def load_arguments(self, _):
969985
with self.argument_context('aks approuting enable') as c:
970986
c.argument('enable_kv', action='store_true')
971987
c.argument('keyvault_id', options_list=['--attach-kv'])
988+
c.argument("nginx", arg_type=get_enum_type(app_routing_nginx_configs))
972989

973990
with self.argument_context('aks approuting update') as c:
974991
c.argument('keyvault_id', options_list=['--attach-kv'])
975992
c.argument('enable_kv', action='store_true')
993+
c.argument("nginx", arg_type=get_enum_type(app_routing_nginx_configs))
976994

977995
with self.argument_context('aks approuting zone add') as c:
978996
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,
@@ -3193,7 +3194,8 @@ def aks_approuting_enable(
31933194
resource_group_name,
31943195
name,
31953196
enable_kv=False,
3196-
keyvault_id=None
3197+
keyvault_id=None,
3198+
nginx=None
31973199
):
31983200
return _aks_approuting_update(
31993201
cmd,
@@ -3202,7 +3204,8 @@ def aks_approuting_enable(
32023204
name,
32033205
enable_app_routing=True,
32043206
keyvault_id=keyvault_id,
3205-
enable_kv=enable_kv)
3207+
enable_kv=enable_kv,
3208+
nginx=nginx)
32063209

32073210

32083211
def aks_approuting_disable(
@@ -3225,15 +3228,17 @@ def aks_approuting_update(
32253228
resource_group_name,
32263229
name,
32273230
keyvault_id=None,
3228-
enable_kv=False
3231+
enable_kv=False,
3232+
nginx=None
32293233
):
32303234
return _aks_approuting_update(
32313235
cmd,
32323236
client,
32333237
resource_group_name,
32343238
name,
32353239
keyvault_id=keyvault_id,
3236-
enable_kv=enable_kv)
3240+
enable_kv=enable_kv,
3241+
nginx=nginx)
32373242

32383243

32393244
def aks_approuting_zone_add(
@@ -3328,7 +3333,8 @@ def _aks_approuting_update(
33283333
delete_dns_zone=None,
33293334
update_dns_zone=None,
33303335
dns_zone_resource_ids=None,
3331-
attach_zones=None
3336+
attach_zones=None,
3337+
nginx=None
33323338
):
33333339
from azure.cli.command_modules.acs.managed_cluster_decorator import AKSManagedClusterUpdateDecorator
33343340

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
@@ -140,6 +140,7 @@
140140
ManagedClusterStorageProfileSnapshotController = TypeVar('ManagedClusterStorageProfileSnapshotController')
141141
ManagedClusterIngressProfile = TypeVar("ManagedClusterIngressProfile")
142142
ManagedClusterIngressProfileWebAppRouting = TypeVar("ManagedClusterIngressProfileWebAppRouting")
143+
ManagedClusterIngressProfileNginx = TypeVar("ManagedClusterIngressProfileNginx")
143144
ServiceMeshProfile = TypeVar("ServiceMeshProfile")
144145

145146
# TODO
@@ -813,6 +814,18 @@ def get_update_dns_zone(self) -> bool:
813814
:return: bool
814815
"""
815816
return self.raw_param.get("update_dns_zone")
817+
818+
def get_app_routing_default_nginx_controller(self) -> str:
819+
"""Obtain the value of app_routing_default_nginx_controller.
820+
:return: str
821+
"""
822+
return self.raw_param.get("app_routing_default_nginx_controller")
823+
824+
def get_nginx(self):
825+
"""Obtain the value of nginx, written to the update decorator context by _aks_approuting_update
826+
:return: string
827+
"""
828+
return self.raw_param.get("nginx")
816829

817830
def get_enable_keda(self) -> bool:
818831
"""Obtain the value of enable_keda.
@@ -6521,6 +6534,16 @@ def set_up_ingress_web_app_routing(self, mc: ManagedCluster) -> ManagedCluster:
65216534
mc.ingress_profile.web_app_routing = (
65226535
self.models.ManagedClusterIngressProfileWebAppRouting(enabled=True) # pylint: disable=no-member
65236536
)
6537+
6538+
nginx_ingress_controller = self.context.get_app_routing_default_nginx_controller()
6539+
6540+
if nginx_ingress_controller:
6541+
mc.ingress_profile.web_app_routing.nginx = (
6542+
self.models.ManagedClusterIngressProfileNginx(
6543+
default_ingress_controller_type=nginx_ingress_controller
6544+
)
6545+
)
6546+
65246547
if "web_application_routing" in addons:
65256548
dns_zone_resource_ids = self.context.get_dns_zone_resource_ids()
65266549
mc.ingress_profile.web_app_routing.dns_zone_resource_ids = dns_zone_resource_ids
@@ -7894,6 +7917,7 @@ def update_app_routing_profile(self, mc: ManagedCluster) -> ManagedCluster:
78947917
enable_app_routing = self.context.get_enable_app_routing()
78957918
enable_keyvault_secret_provider = self.context.get_enable_kv()
78967919
dns_zone_resource_ids = self.context.get_dns_zone_resource_ids_from_input()
7920+
nginx = self.context.get_nginx()
78977921

78987922
# update ManagedCluster object with app routing settings
78997923
mc.ingress_profile = (
@@ -7921,8 +7945,24 @@ def update_app_routing_profile(self, mc: ManagedCluster) -> ManagedCluster:
79217945
# modify DNS zone resource IDs
79227946
if dns_zone_resource_ids:
79237947
self._update_dns_zone_resource_ids(mc, dns_zone_resource_ids)
7948+
7949+
# modify default nic config
7950+
if nginx:
7951+
self._update_app_routing_nginx(mc, nginx)
79247952

79257953
return mc
7954+
7955+
def _update_app_routing_nginx(self, mc: ManagedCluster, nginx) -> None:
7956+
"""Helper function to set default nginx ingress controller config for app routing
7957+
:return: None
7958+
"""
7959+
# web app routing object has been created
7960+
if mc.ingress_profile and mc.ingress_profile.web_app_routing and mc.ingress_profile.web_app_routing.enabled:
7961+
if mc.ingress_profile.web_app_routing.nginx is None:
7962+
mc.ingress_profile.web_app_routing.nginx = self.models.ManagedClusterIngressProfileNginx()
7963+
mc.ingress_profile.web_app_routing.nginx.default_ingress_controller_type = nginx
7964+
else:
7965+
raise CLIError('App Routing must be enabled to modify the default nginx ingress controller.\n')
79267966

79277967
def update_node_resource_group_profile(self, mc: ManagedCluster) -> ManagedCluster:
79287968
"""Update node resource group profile for the ManagedCluster object.

0 commit comments

Comments
 (0)