Skip to content

Commit 36f1959

Browse files
authored
AKS: add --fqdn-subdomain for private cluster with custom private dns zone (Azure#3049)
1 parent 7ba9725 commit 36f1959

File tree

5 files changed

+1248
-3
lines changed

5 files changed

+1248
-3
lines changed

src/aks-preview/azext_aks_preview/_help.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,9 @@
250250
type: string
251251
short-summary: (PREVIEW) private dns zone mode for private cluster.
252252
long-summary: Allowed values are "system", "none" or your custom private dns zone resource id. If not set, defaults to type system. Requires --enable-private-cluster to be used.
253+
- name: --fqdn-subdomain
254+
type: string
255+
short-summary: (Preview) Prefix for FQDN that is created for private cluster with custom private dns zone scenario.
253256
- name: --enable-node-public-ip
254257
type: bool
255258
short-summary: Enable VMSS node public IP.

src/aks-preview/azext_aks_preview/_params.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def load_arguments(self, _):
110110
c.argument('aks_custom_headers')
111111
c.argument('enable_private_cluster', action='store_true')
112112
c.argument('private_dns_zone')
113+
c.argument('fqdn_subdomain')
113114
c.argument('enable_managed_identity', action='store_true')
114115
c.argument('assign_identity', type=str, validator=validate_assign_identity)
115116
c.argument('enable_sgxquotehelper', action='store_true')

src/aks-preview/azext_aks_preview/custom.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
from ._consts import CONST_CONFCOM_ADDON_NAME, CONST_ACC_SGX_QUOTE_HELPER_ENABLED
106106
from ._consts import CONST_OPEN_SERVICE_MESH_ADDON_NAME
107107
from ._consts import ADDONS
108+
from ._consts import CONST_PRIVATE_DNS_ZONE_SYSTEM, CONST_PRIVATE_DNS_ZONE_NONE
108109
logger = get_logger(__name__)
109110

110111

@@ -883,6 +884,7 @@ def aks_create(cmd, # pylint: disable=too-many-locals,too-many-statements,to
883884
enable_private_cluster=False,
884885
private_dns_zone=None,
885886
enable_managed_identity=True,
887+
fqdn_subdomain=None,
886888
api_server_authorized_ip_ranges=None,
887889
aks_custom_headers=None,
888890
appgw_name=None,
@@ -913,7 +915,10 @@ def aks_create(cmd, # pylint: disable=too-many-locals,too-many-statements,to
913915
raise CLIError('Provided ssh key ({}) is invalid or non-existent'.format(shortened_key))
914916

915917
subscription_id = get_subscription_id(cmd.cli_ctx)
916-
if not dns_name_prefix:
918+
919+
if dns_name_prefix and fqdn_subdomain:
920+
raise CLIError('--dns-name-prefix and --fqdn-subdomain cannot be used at same time')
921+
if not dns_name_prefix and not fqdn_subdomain:
917922
dns_name_prefix = _get_default_dns_prefix(name, resource_group_name, subscription_id)
918923

919924
rg_location = _get_rg_location(cmd.cli_ctx, resource_group_name)
@@ -1001,7 +1006,7 @@ def aks_create(cmd, # pylint: disable=too-many-locals,too-many-statements,to
10011006
principal_obj = _ensure_aks_service_principal(cmd.cli_ctx,
10021007
service_principal=service_principal, client_secret=client_secret,
10031008
subscription_id=subscription_id, dns_name_prefix=dns_name_prefix,
1004-
location=location, name=name)
1009+
fqdn_subdomain=fqdn_subdomain, location=location, name=name)
10051010
service_principal_profile = ManagedClusterServicePrincipalProfile(
10061011
client_id=principal_obj.get("service_principal"),
10071012
secret=principal_obj.get("client_secret"))
@@ -1215,6 +1220,7 @@ def aks_create(cmd, # pylint: disable=too-many-locals,too-many-statements,to
12151220
if node_resource_group:
12161221
mc.node_resource_group = node_resource_group
12171222

1223+
use_custom_private_dns_zone = False
12181224
if enable_private_cluster:
12191225
if load_balancer_sku.lower() != "standard":
12201226
raise CLIError("Please use standard load balancer for private cluster")
@@ -1226,6 +1232,17 @@ def aks_create(cmd, # pylint: disable=too-many-locals,too-many-statements,to
12261232
if not enable_private_cluster:
12271233
raise CLIError("Invalid private dns zone for public cluster. It should always be empty for public cluster")
12281234
mc.api_server_access_profile.private_dns_zone = private_dns_zone
1235+
from msrestazure.tools import is_valid_resource_id
1236+
if private_dns_zone.lower() != CONST_PRIVATE_DNS_ZONE_SYSTEM and private_dns_zone.lower() != CONST_PRIVATE_DNS_ZONE_NONE:
1237+
if is_valid_resource_id(private_dns_zone):
1238+
use_custom_private_dns_zone = True
1239+
else:
1240+
raise CLIError(private_dns_zone + " is not a valid Azure resource ID.")
1241+
1242+
if fqdn_subdomain:
1243+
if not use_custom_private_dns_zone:
1244+
raise CLIError("--fqdn-subdomain should only be used for private cluster with custom private dns zone")
1245+
mc.fqdn_subdomain = fqdn_subdomain
12291246

12301247
if uptime_sla:
12311248
mc.sku = ManagedClusterSKU(
@@ -2325,6 +2342,7 @@ def _ensure_aks_service_principal(cli_ctx,
23252342
client_secret=None,
23262343
subscription_id=None,
23272344
dns_name_prefix=None,
2345+
fqdn_subdomain=None,
23282346
location=None,
23292347
name=None):
23302348
file_name_aks = 'aksServicePrincipal.json'
@@ -2341,7 +2359,10 @@ def _ensure_aks_service_principal(cli_ctx,
23412359
if not client_secret:
23422360
client_secret = _create_client_secret()
23432361
salt = binascii.b2a_hex(os.urandom(3)).decode('utf-8')
2344-
url = 'http://{}.{}.{}.cloudapp.azure.com'.format(salt, dns_name_prefix, location)
2362+
if dns_name_prefix:
2363+
url = 'http://{}.{}.{}.cloudapp.azure.com'.format(salt, dns_name_prefix, location)
2364+
else:
2365+
url = 'http://{}.{}.{}.cloudapp.azure.com'.format(salt, fqdn_subdomain, location)
23452366

23462367
service_principal = _build_service_principal(rbac_client, cli_ctx, name, url, client_secret)
23472368
if not service_principal:

0 commit comments

Comments
 (0)