Skip to content

Commit

Permalink
aks-preview: feature support for web application routing (#4872)
Browse files Browse the repository at this point in the history
  • Loading branch information
yizhang4321 authored May 25, 2022
1 parent 1464c39 commit 46399b6
Show file tree
Hide file tree
Showing 12 changed files with 1,968 additions and 14 deletions.
4 changes: 4 additions & 0 deletions src/aks-preview/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ To release a new version, please select a new version number (usually plus 1 to
Pending
+++++++

0.5.75
++++++

* Add support for web application routing.
* Refactor: Removed redundant `--disable-workload-identity` flag. User can disable the workload identity feature by using `--enable-workload-identity False`.

0.5.74
Expand Down
5 changes: 4 additions & 1 deletion src/aks-preview/azext_aks_preview/_consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@
"confcom": CONST_CONFCOM_ADDON_NAME,
'open-service-mesh': CONST_OPEN_SERVICE_MESH_ADDON_NAME,
'azure-keyvault-secrets-provider': CONST_AZURE_KEYVAULT_SECRETS_PROVIDER_ADDON_NAME,
'gitops': CONST_GITOPS_ADDON_NAME
'gitops': CONST_GITOPS_ADDON_NAME,
# web_application_routing key has no mapping to a name since ingress profile, not addon profile, is
# used to contain settings for web_application_routing
'web_application_routing': ""
}

ADDONS_DESCRIPTIONS = {
Expand Down
15 changes: 15 additions & 0 deletions src/aks-preview/azext_aks_preview/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@
open-service-mesh - enable Open Service Mesh addon (PREVIEW).
gitops - enable GitOps (PREVIEW).
azure-keyvault-secrets-provider - enable Azure Keyvault Secrets Provider addon (PREVIEW).
web_application_routing - enable Web Application Routing addon (PREVIEW). Specify "--dns-zone-resource-id" to configure DNS.
- name: --disable-rbac
type: bool
short-summary: Disable Kubernetes Role-Based Access Control.
Expand Down Expand Up @@ -437,6 +438,9 @@
- name: --azure-keyvault-kms-key-id
type: string
short-summary: Identifier of Azure Key Vault key.
- name: --dns-zone-resource-id
type: string
short-summary: The resource ID of the DNS zone resource to use with the web_application_routing addon.
examples:
- name: Create a Kubernetes cluster with an existing SSH public key.
text: az aks create -g MyResourceGroup -n MyManagedCluster --ssh-key-value /path/to/publickey
Expand Down Expand Up @@ -1331,6 +1335,7 @@
open-service-mesh - enable Open Service Mesh addon (PREVIEW).
gitops - enable GitOps (PREVIEW).
azure-keyvault-secrets-provider - enable Azure Keyvault Secrets Provider addon (PREVIEW).
web_application_routing - enable Web Application Routing addon (PREVIEW). Specify "--dns-zone-resource-id" to configure DNS.
parameters:
- name: --addon -a
type: string
Expand Down Expand Up @@ -1371,6 +1376,9 @@
- name: --rotation-poll-interval
type: string
short-summary: Set interval of rotation poll. Use with azure-keyvault-secrets-provider addon.
- name: --dns-zone-resource-id
type: string
short-summary: The resource ID of the DNS zone resource to use with the web_application_routing addon.
examples:
- name: Enable a Kubernetes addon. (autogenerated)
text: az aks addon enable --addon virtual-node --name MyManagedCluster --resource-group MyResourceGroup --subnet-name VirtualNodeSubnet
Expand Down Expand Up @@ -1426,6 +1434,9 @@
- name: --rotation-poll-interval
type: string
short-summary: Set interval of rotation poll. Use with azure-keyvault-secrets-provider addon.
- name: --dns-zone-resource-id
type: string
short-summary: The resource ID of the DNS zone resource to use with the web_application_routing addon.
examples:
- name: Update a Kubernetes addon. (autogenerated)
text: az aks addon update --addon virtual-node --name MyManagedCluster --resource-group MyResourceGroup --subnet-name VirtualNodeSubnet
Expand Down Expand Up @@ -1454,6 +1465,7 @@
open-service-mesh - enable Open Service Mesh addon (PREVIEW).
gitops - enable GitOps (PREVIEW).
azure-keyvault-secrets-provider - enable Azure Keyvault Secrets Provider addon (PREVIEW).
web_application_routing - enable Web Application Routing addon (PREVIEW). Specify "--dns-zone-resource-id" to configure DNS.
parameters:
- name: --addons -a
type: string
Expand Down Expand Up @@ -1494,6 +1506,9 @@
- name: --rotation-poll-interval
type: string
short-summary: Set interval of rotation poll. Use with azure-keyvault-secrets-provider addon.
- name: --dns-zone-resource-id
type: string
short-summary: The resource ID of the DNS zone resource to use with the web_application_routing addon.
examples:
- name: Enable Kubernetes addons. (autogenerated)
text: az aks enable-addons --addons virtual-node --name MyManagedCluster --resource-group MyResourceGroup --subnet-name VirtualNodeSubnet
Expand Down
4 changes: 4 additions & 0 deletions src/aks-preview/azext_aks_preview/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ def load_arguments(self, _):
c.argument('workload_runtime', arg_type=get_enum_type(workload_runtimes), default=CONST_WORKLOAD_RUNTIME_OCI_CONTAINER)
c.argument('enable_apiserver_vnet_integration', action='store_true', is_preview=True)
c.argument('apiserver_subnet_id', validator=validate_apiserver_subnet_id, is_preview=True)
c.argument('dns-zone-resource-id')

with self.argument_context('aks update') as c:
# managed cluster paramerters
Expand Down Expand Up @@ -512,6 +513,7 @@ def load_arguments(self, _):
c.argument('workspace_resource_id')
c.argument('enable_msi_auth_for_monitoring',
arg_type=get_three_state_flag(), is_preview=True)
c.argument('dns-zone-resource-id')

with self.argument_context('aks addon disable') as c:
c.argument('addon', options_list=[
Expand Down Expand Up @@ -540,6 +542,7 @@ def load_arguments(self, _):
c.argument('workspace_resource_id')
c.argument('enable_msi_auth_for_monitoring',
arg_type=get_three_state_flag(), is_preview=True)
c.argument('dns-zone-resource-id')

with self.argument_context('aks disable-addons') as c:
c.argument('addons', options_list=[
Expand Down Expand Up @@ -568,6 +571,7 @@ def load_arguments(self, _):
c.argument('workspace_resource_id')
c.argument('enable_msi_auth_for_monitoring',
arg_type=get_three_state_flag(), is_preview=True)
c.argument('dns-zone-resource-id')

with self.argument_context('aks get-credentials') as c:
c.argument('admin', options_list=['--admin', '-a'], default=False)
Expand Down
22 changes: 21 additions & 1 deletion src/aks-preview/azext_aks_preview/addonconfiguration.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
CONST_INGRESS_APPGW_WATCH_NAMESPACE, CONST_OPEN_SERVICE_MESH_ADDON_NAME, CONST_CONFCOM_ADDON_NAME, \
CONST_ACC_SGX_QUOTE_HELPER_ENABLED, CONST_AZURE_KEYVAULT_SECRETS_PROVIDER_ADDON_NAME, CONST_SECRET_ROTATION_ENABLED, CONST_ROTATION_POLL_INTERVAL, \
CONST_KUBE_DASHBOARD_ADDON_NAME
from .vendored_sdks.azure_mgmt_preview_aks.v2022_04_02_preview.models import (
ManagedClusterIngressProfile,
ManagedClusterIngressProfileWebAppRouting,
)

logger = get_logger(__name__)

Expand All @@ -43,6 +47,7 @@ def enable_addons(cmd,
enable_secret_rotation=False,
rotation_poll_interval=None,
no_wait=False,
dns_zone_resource_id=None,
enable_msi_auth_for_monitoring=False):
instance = client.get(resource_group_name, name)
# this is overwritten by _update_addons(), so the value needs to be recorded here
Expand All @@ -57,7 +62,8 @@ def enable_addons(cmd,
appgw_subnet_cidr=appgw_subnet_cidr, appgw_id=appgw_id, appgw_subnet_id=appgw_subnet_id,
appgw_watch_namespace=appgw_watch_namespace,
enable_sgxquotehelper=enable_sgxquotehelper,
enable_secret_rotation=enable_secret_rotation, rotation_poll_interval=rotation_poll_interval, no_wait=no_wait)
enable_secret_rotation=enable_secret_rotation, rotation_poll_interval=rotation_poll_interval, no_wait=no_wait,
dns_zone_resource_id=dns_zone_resource_id)

if CONST_MONITORING_ADDON_NAME in instance.addon_profiles and instance.addon_profiles[
CONST_MONITORING_ADDON_NAME].enabled:
Expand Down Expand Up @@ -142,6 +148,7 @@ def update_addons(cmd, # pylint: disable=too-many-branches,too-many-statements
enable_sgxquotehelper=False,
enable_secret_rotation=False,
rotation_poll_interval=None,
dns_zone_resource_id=None,
no_wait=False): # pylint: disable=unused-argument
# parse the comma-separated addons argument
addon_args = addons.split(',')
Expand All @@ -159,6 +166,19 @@ def update_addons(cmd, # pylint: disable=too-many-branches,too-many-statements

# for each addons argument
for addon_arg in addon_args:
if addon_arg == "web_application_routing":
# web app routing settings are in ingress profile, not addon profile, so deal
# with it separately
if instance.ingress_profile is None:
instance.ingress_profile = ManagedClusterIngressProfile()
if instance.ingress_profile.web_app_routing is None:
instance.ingress_profile.web_app_routing = ManagedClusterIngressProfileWebAppRouting()
instance.ingress_profile.web_app_routing.enabled = enable

if dns_zone_resource_id is not None:
instance.ingress_profile.web_app_routing.dns_zone_resource_id = dns_zone_resource_id
continue

if addon_arg not in ADDONS:
raise CLIError("Invalid addon name: {}.".format(addon_arg))
addon = ADDONS[addon_arg]
Expand Down
49 changes: 39 additions & 10 deletions src/aks-preview/azext_aks_preview/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@
ManagedClusterSnapshot,
SysctlConfig,
UserAssignedIdentity,
ManagedClusterIngressProfile,
ManagedClusterIngressProfileWebAppRouting,
)

from azext_aks_preview.aks_draft.commands import (
Expand Down Expand Up @@ -809,6 +811,7 @@ def aks_create(cmd,
azure_keyvault_kms_key_id=None,
enable_apiserver_vnet_integration=False,
apiserver_subnet_id=None,
dns_zone_resource_id=None,
yes=False):
# DO NOT MOVE: get all the original parameters and save them as a dictionary
raw_parameters = locals()
Expand Down Expand Up @@ -1362,6 +1365,7 @@ def _handle_addons_args(cmd, # pylint: disable=too-many-statements
aci_subnet_name=None,
vnet_subnet_id=None,
enable_secret_rotation=False,
dns_zone_resource_id=None,
rotation_poll_interval=None,):
if not addon_profiles:
addon_profiles = {}
Expand Down Expand Up @@ -2049,13 +2053,15 @@ def aks_addon_enable(cmd, client, resource_group_name, name, addon, workspace_re
subnet_name=None, appgw_name=None, appgw_subnet_prefix=None, appgw_subnet_cidr=None, appgw_id=None,
appgw_subnet_id=None,
appgw_watch_namespace=None, enable_sgxquotehelper=False, enable_secret_rotation=False, rotation_poll_interval=None,
no_wait=False, enable_msi_auth_for_monitoring=False):
no_wait=False, enable_msi_auth_for_monitoring=False,
dns_zone_resource_id=None):
return enable_addons(cmd, client, resource_group_name, name, addon, workspace_resource_id=workspace_resource_id,
subnet_name=subnet_name, appgw_name=appgw_name, appgw_subnet_prefix=appgw_subnet_prefix,
appgw_subnet_cidr=appgw_subnet_cidr, appgw_id=appgw_id, appgw_subnet_id=appgw_subnet_id,
appgw_watch_namespace=appgw_watch_namespace, enable_sgxquotehelper=enable_sgxquotehelper,
enable_secret_rotation=enable_secret_rotation, rotation_poll_interval=rotation_poll_interval, no_wait=no_wait,
enable_msi_auth_for_monitoring=enable_msi_auth_for_monitoring)
enable_msi_auth_for_monitoring=enable_msi_auth_for_monitoring,
dns_zone_resource_id=dns_zone_resource_id)


def aks_addon_disable(cmd, client, resource_group_name, name, addon, no_wait=False):
Expand All @@ -2066,20 +2072,27 @@ def aks_addon_update(cmd, client, resource_group_name, name, addon, workspace_re
subnet_name=None, appgw_name=None, appgw_subnet_prefix=None, appgw_subnet_cidr=None, appgw_id=None,
appgw_subnet_id=None,
appgw_watch_namespace=None, enable_sgxquotehelper=False, enable_secret_rotation=False, rotation_poll_interval=None,
no_wait=False, enable_msi_auth_for_monitoring=False):
addon_profiles = client.get(resource_group_name, name).addon_profiles
addon_key = ADDONS[addon]
no_wait=False, enable_msi_auth_for_monitoring=False,
dns_zone_resource_id=None):
instance = client.get(resource_group_name, name)
addon_profiles = instance.addon_profiles

if not addon_profiles or addon_key not in addon_profiles or not addon_profiles[addon_key].enabled:
raise CLIError(f'Addon "{addon}" is not enabled in this cluster.')
if addon == "web_application_routing":
if (instance.ingress_profile is None) or (instance.ingress_profile.web_app_routing is None) or not instance.ingress_profile.web_app_routing.enabled:
raise InvalidArgumentValueError(f'Addon "{addon}" is not enabled in this cluster.')
else:
addon_key = ADDONS[addon]
if not addon_profiles or addon_key not in addon_profiles or not addon_profiles[addon_key].enabled:
raise InvalidArgumentValueError(f'Addon "{addon}" is not enabled in this cluster.')

return enable_addons(cmd, client, resource_group_name, name, addon, check_enabled=False,
workspace_resource_id=workspace_resource_id,
subnet_name=subnet_name, appgw_name=appgw_name, appgw_subnet_prefix=appgw_subnet_prefix,
appgw_subnet_cidr=appgw_subnet_cidr, appgw_id=appgw_id, appgw_subnet_id=appgw_subnet_id,
appgw_watch_namespace=appgw_watch_namespace, enable_sgxquotehelper=enable_sgxquotehelper,
enable_secret_rotation=enable_secret_rotation, rotation_poll_interval=rotation_poll_interval, no_wait=no_wait,
enable_msi_auth_for_monitoring=enable_msi_auth_for_monitoring)
enable_msi_auth_for_monitoring=enable_msi_auth_for_monitoring,
dns_zone_resource_id=dns_zone_resource_id)


def aks_disable_addons(cmd, client, resource_group_name, name, addons, no_wait=False):
Expand Down Expand Up @@ -2124,7 +2137,8 @@ def aks_disable_addons(cmd, client, resource_group_name, name, addons, no_wait=F

def aks_enable_addons(cmd, client, resource_group_name, name, addons, workspace_resource_id=None,
subnet_name=None, appgw_name=None, appgw_subnet_prefix=None, appgw_subnet_cidr=None, appgw_id=None, appgw_subnet_id=None,
appgw_watch_namespace=None, enable_sgxquotehelper=False, enable_secret_rotation=False, rotation_poll_interval=None, no_wait=False, enable_msi_auth_for_monitoring=False):
appgw_watch_namespace=None, enable_sgxquotehelper=False, enable_secret_rotation=False, rotation_poll_interval=None, no_wait=False, enable_msi_auth_for_monitoring=False,
dns_zone_resource_id=None):

instance = client.get(resource_group_name, name)
# this is overwritten by _update_addons(), so the value needs to be recorded here
Expand All @@ -2134,7 +2148,8 @@ def aks_enable_addons(cmd, client, resource_group_name, name, addons, workspace_
instance = _update_addons(cmd, instance, subscription_id, resource_group_name, name, addons, enable=True,
workspace_resource_id=workspace_resource_id, enable_msi_auth_for_monitoring=enable_msi_auth_for_monitoring, subnet_name=subnet_name,
appgw_name=appgw_name, appgw_subnet_prefix=appgw_subnet_prefix, appgw_subnet_cidr=appgw_subnet_cidr, appgw_id=appgw_id, appgw_subnet_id=appgw_subnet_id, appgw_watch_namespace=appgw_watch_namespace,
enable_sgxquotehelper=enable_sgxquotehelper, enable_secret_rotation=enable_secret_rotation, rotation_poll_interval=rotation_poll_interval, no_wait=no_wait)
enable_sgxquotehelper=enable_sgxquotehelper, enable_secret_rotation=enable_secret_rotation, rotation_poll_interval=rotation_poll_interval, no_wait=no_wait,
dns_zone_resource_id=dns_zone_resource_id)

if CONST_MONITORING_ADDON_NAME in instance.addon_profiles and instance.addon_profiles[CONST_MONITORING_ADDON_NAME].enabled:
if CONST_MONITORING_USING_AAD_MSI_AUTH in instance.addon_profiles[CONST_MONITORING_ADDON_NAME].config and \
Expand Down Expand Up @@ -2219,6 +2234,7 @@ def _update_addons(cmd, # pylint: disable=too-many-branches,too-many-statements
enable_secret_rotation=False,
disable_secret_rotation=False,
rotation_poll_interval=None,
dns_zone_resource_id=None,
no_wait=False): # pylint: disable=unused-argument

# parse the comma-separated addons argument
Expand All @@ -2230,6 +2246,19 @@ def _update_addons(cmd, # pylint: disable=too-many-branches,too-many-statements

# for each addons argument
for addon_arg in addon_args:
if addon_arg == "web_application_routing":
# web app routing settings are in ingress profile, not addon profile, so deal
# with it separately
if instance.ingress_profile is None:
instance.ingress_profile = ManagedClusterIngressProfile()
if instance.ingress_profile.web_app_routing is None:
instance.ingress_profile.web_app_routing = ManagedClusterIngressProfileWebAppRouting()
instance.ingress_profile.web_app_routing.enabled = enable

if dns_zone_resource_id is not None:
instance.ingress_profile.web_app_routing.dns_zone_resource_id = dns_zone_resource_id
continue

if addon_arg not in ADDONS:
raise CLIError("Invalid addon name: {}.".format(addon_arg))
addon = ADDONS[addon_arg]
Expand Down
Loading

0 comments on commit 46399b6

Please sign in to comment.