105105from ._consts import CONST_CONFCOM_ADDON_NAME , CONST_ACC_SGX_QUOTE_HELPER_ENABLED
106106from ._consts import CONST_OPEN_SERVICE_MESH_ADDON_NAME
107107from ._consts import ADDONS
108+ from ._consts import CONST_PRIVATE_DNS_ZONE_SYSTEM , CONST_PRIVATE_DNS_ZONE_NONE
108109logger = 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