Skip to content

Commit

Permalink
[AKS] Adding Default NIC Config for App Routing (#7865)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaiveerk authored Aug 13, 2024
1 parent 16b2cfe commit 77fc21e
Show file tree
Hide file tree
Showing 11 changed files with 3,661 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/aks-preview/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Pending
++++++++
* Fix bug related to the --ampls-resource-id option in the `az aks enable-addons` command.
* Vendor new SDK and bump API version to 2024-06-02-preview.
* Add support for default nginx ingress controller config for app routing add-on

7.0.0b3
++++++++
Expand Down
4 changes: 4 additions & 0 deletions src/aks-preview/azext_aks_preview/_consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@
# only used as the key of the corresponding description, not to map to the key name in addonProfiles,
# since its configuration is actually stored in a separate ingress profile
CONST_WEB_APPLICATION_ROUTING_KEY_NAME = "ingress/webApplicationRouting"
CONST_APP_ROUTING_ANNOTATION_CONTROLLED_NGINX = "AnnotationControlled"
CONST_APP_ROUTING_EXTERNAL_NGINX = "External"
CONST_APP_ROUTING_INTERNAL_NGINX = "Internal"
CONST_APP_ROUTING_NONE_NGINX = "None"

# all supported addons
ADDONS = {
Expand Down
11 changes: 11 additions & 0 deletions src/aks-preview/azext_aks_preview/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,9 @@
- name: --enable-app-routing
type: bool
short-summary: Enable Application Routing addon.
- name: --app-routing-default-nginx-controller --ardnc
type: string
short-summary: Configure default nginx ingress controller type. Valid values are annotationControlled (default behavior), external, internal, or none.
- name: --enable-ai-toolchain-operator
type: bool
short-summary: Enable AI toolchain operator to the cluster.
Expand Down Expand Up @@ -3154,6 +3157,10 @@
type: string
short-summary: Attach a keyvault id to access secrets and certificates.
long-summary: This optional flag attaches a keyvault id to access secrets and certificates.
- name: --nginx
type: string
short-summary: Configure default NginxIngressController resource
long-summary: Configure default nginx ingress controller type. Valid values are annotationControlled (default behavior), external, internal, or none.
"""

helps['aks approuting disable'] = """
Expand All @@ -3175,6 +3182,10 @@
type: bool
short-summary: Enable the keyvault secrets provider addon.
long-summary: This optional flag enables the keyvault-secrets-provider addon in given cluster. This is required for most App Routing use-cases.
- name: --nginx
type: string
short-summary: Configure default NginxIngressController resource
long-summary: Configure default nginx ingress controller type. Valid values are annotationControlled (default behavior), external, internal, or none.
"""

helps['aks approuting zone'] = """
Expand Down
19 changes: 19 additions & 0 deletions src/aks-preview/azext_aks_preview/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@
CONST_ARTIFACT_SOURCE_DIRECT,
CONST_ARTIFACT_SOURCE_CACHE,
CONST_OUTBOUND_TYPE_NONE,
CONST_APP_ROUTING_ANNOTATION_CONTROLLED_NGINX,
CONST_APP_ROUTING_EXTERNAL_NGINX,
CONST_APP_ROUTING_INTERNAL_NGINX,
CONST_APP_ROUTING_NONE_NGINX,
)
from azext_aks_preview._validators import (
validate_acr,
Expand Down Expand Up @@ -399,6 +403,14 @@
CONST_ARTIFACT_SOURCE_CACHE,
]

# consts for app routing add-on
app_routing_nginx_configs = [
CONST_APP_ROUTING_ANNOTATION_CONTROLLED_NGINX,
CONST_APP_ROUTING_EXTERNAL_NGINX,
CONST_APP_ROUTING_INTERNAL_NGINX,
CONST_APP_ROUTING_NONE_NGINX
]


def load_arguments(self, _):
acr_arg_type = CLIArgumentType(metavar="ACR_NAME_OR_RESOURCE_ID")
Expand Down Expand Up @@ -644,6 +656,11 @@ def load_arguments(self, _):
c.argument("rotation_poll_interval")
c.argument("enable_sgxquotehelper", action="store_true")
c.argument("enable_app_routing", action="store_true", is_preview=True)
c.argument(
"app_routing_default_nginx_controller",
arg_type=get_enum_type(app_routing_nginx_configs),
options_list=["--app-routing-default-nginx-controller", "--ardnc"]
)
# nodepool paramerters
c.argument(
"nodepool_name",
Expand Down Expand Up @@ -2270,10 +2287,12 @@ def load_arguments(self, _):
with self.argument_context("aks approuting enable") as c:
c.argument("enable_kv", action="store_true")
c.argument("keyvault_id", options_list=["--attach-kv"])
c.argument("nginx", arg_type=get_enum_type(app_routing_nginx_configs))

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

with self.argument_context("aks approuting zone add") as c:
c.argument("dns_zone_resource_ids", options_list=["--ids"], required=True)
Expand Down
16 changes: 11 additions & 5 deletions src/aks-preview/azext_aks_preview/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ def aks_create(
enable_secret_rotation=False,
rotation_poll_interval=None,
enable_app_routing=False,
app_routing_default_nginx_controller=None,
# nodepool paramerters
nodepool_name="nodepool1",
node_vm_size=None,
Expand Down Expand Up @@ -3407,7 +3408,8 @@ def aks_approuting_enable(
resource_group_name,
name,
enable_kv=False,
keyvault_id=None
keyvault_id=None,
nginx=None,
):
return _aks_approuting_update(
cmd,
Expand All @@ -3416,7 +3418,8 @@ def aks_approuting_enable(
name,
enable_app_routing=True,
keyvault_id=keyvault_id,
enable_kv=enable_kv)
enable_kv=enable_kv,
nginx=nginx)


def aks_approuting_disable(
Expand All @@ -3439,15 +3442,17 @@ def aks_approuting_update(
resource_group_name,
name,
keyvault_id=None,
enable_kv=False
enable_kv=False,
nginx=None
):
return _aks_approuting_update(
cmd,
client,
resource_group_name,
name,
keyvault_id=keyvault_id,
enable_kv=enable_kv)
enable_kv=enable_kv,
nginx=nginx)


def aks_approuting_zone_add(
Expand Down Expand Up @@ -3542,7 +3547,8 @@ def _aks_approuting_update(
delete_dns_zone=None,
update_dns_zone=None,
dns_zone_resource_ids=None,
attach_zones=None
attach_zones=None,
nginx=None
):
from azure.cli.command_modules.acs._consts import DecoratorEarlyExitException
from azext_aks_preview.managed_cluster_decorator import AKSPreviewManagedClusterUpdateDecorator
Expand Down
43 changes: 43 additions & 0 deletions src/aks-preview/azext_aks_preview/managed_cluster_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
ManagedClusterStorageProfileBlobCSIDriver = TypeVar('ManagedClusterStorageProfileBlobCSIDriver')
ManagedClusterStorageProfileSnapshotController = TypeVar('ManagedClusterStorageProfileSnapshotController')
ManagedClusterIngressProfileWebAppRouting = TypeVar("ManagedClusterIngressProfileWebAppRouting")
ManagedClusterIngressProfileNginx = TypeVar("ManagedClusterIngressProfileNginx")
ManagedClusterSecurityProfileDefender = TypeVar("ManagedClusterSecurityProfileDefender")
ManagedClusterSecurityProfileNodeRestriction = TypeVar("ManagedClusterSecurityProfileNodeRestriction")
ManagedClusterWorkloadProfileVerticalPodAutoscaler = TypeVar("ManagedClusterWorkloadProfileVerticalPodAutoscaler")
Expand Down Expand Up @@ -2756,6 +2757,20 @@ def get_update_dns_zone(self) -> bool:
"""
return self.raw_param.get("update_dns_zone")

def get_app_routing_default_nginx_controller(self) -> str:
"""Obtain the value of app_routing_default_nginx_controller.
:return: str
"""
return self.raw_param.get("app_routing_default_nginx_controller")

def get_nginx(self):
"""Obtain the value of nginx, written to the update decorator context by _aks_approuting_update
:return: string
"""
return self.raw_param.get("nginx")

def get_node_provisioning_mode(self) -> Union[str, None]:
"""Obtain the value of node_provisioning_mode.
"""
Expand Down Expand Up @@ -3130,6 +3145,16 @@ def set_up_ingress_web_app_routing(self, mc: ManagedCluster) -> ManagedCluster:
mc.ingress_profile.web_app_routing = (
self.models.ManagedClusterIngressProfileWebAppRouting(enabled=True) # pylint: disable=no-member
)

nginx_ingress_controller = self.context.get_app_routing_default_nginx_controller()

if nginx_ingress_controller:
mc.ingress_profile.web_app_routing.nginx = (
self.models.ManagedClusterIngressProfileNginx(
default_ingress_controller_type=nginx_ingress_controller
)
)

if "web_application_routing" in addons:
dns_zone_resource_ids = self.context.get_dns_zone_resource_ids()
mc.ingress_profile.web_app_routing.dns_zone_resource_ids = dns_zone_resource_ids
Expand Down Expand Up @@ -5035,6 +5060,7 @@ def update_app_routing_profile(self, mc: ManagedCluster) -> ManagedCluster:
enable_app_routing = self.context.get_enable_app_routing()
enable_keyvault_secret_provider = self.context.get_enable_kv()
dns_zone_resource_ids = self.context.get_dns_zone_resource_ids_from_input()
nginx = self.context.get_nginx()

# update ManagedCluster object with app routing settings
mc.ingress_profile = (
Expand Down Expand Up @@ -5063,6 +5089,10 @@ def update_app_routing_profile(self, mc: ManagedCluster) -> ManagedCluster:
if dns_zone_resource_ids:
self._update_dns_zone_resource_ids(mc, dns_zone_resource_ids)

# modify default nic config
if nginx:
self._update_app_routing_nginx(mc, nginx)

return mc

def _enable_keyvault_secret_provider_addon(self, mc: ManagedCluster) -> None:
Expand All @@ -5088,6 +5118,19 @@ def _enable_keyvault_secret_provider_addon(self, mc: ManagedCluster) -> None:
CONST_ROTATION_POLL_INTERVAL: "2m",
}

def _update_app_routing_nginx(self, mc: ManagedCluster, nginx) -> None:
"""Helper function to set default nginx ingress controller config for app routing
:return: None
"""
# web app routing object has been created
if mc.ingress_profile and mc.ingress_profile.web_app_routing and mc.ingress_profile.web_app_routing.enabled:
if mc.ingress_profile.web_app_routing.nginx is None:
mc.ingress_profile.web_app_routing.nginx = self.models.ManagedClusterIngressProfileNginx()
mc.ingress_profile.web_app_routing.nginx.default_ingress_controller_type = nginx
else:
raise CLIError('App Routing must be enabled to modify the default nginx ingress controller.\n')

# pylint: disable=too-many-nested-blocks
def _update_dns_zone_resource_ids(self, mc: ManagedCluster, dns_zone_resource_ids) -> None:
"""Helper function to update dns zone resource ids in app routing addon.
Expand Down
Loading

0 comments on commit 77fc21e

Please sign in to comment.