Skip to content
Merged
39 changes: 25 additions & 14 deletions src/azure-cli/azure/cli/command_modules/acs/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
CONST_VIRTUAL_NODE_SUBNET_NAME,
DecoratorEarlyExitException,
)
from azure.cli.command_modules.acs._helpers import (
get_user_assigned_identity_by_resource_id,
)
from azure.cli.command_modules.acs._helpers import get_snapshot_by_snapshot_id
from azure.cli.command_modules.acs._resourcegroup import get_rg_location
from azure.cli.command_modules.acs._validators import extract_comma_separated_string
Expand Down Expand Up @@ -452,7 +455,7 @@ def aks_create(
# addons
enable_addons=None,
workspace_resource_id=None,
enable_msi_auth_for_monitoring=False,
enable_msi_auth_for_monitoring=True,
Comment thread
wanlonghenry marked this conversation as resolved.
enable_syslog=False,
data_collection_settings=None,
aci_subnet_name=None,
Expand Down Expand Up @@ -854,7 +857,7 @@ def aks_enable_addons(cmd, client, resource_group_name, name, addons,
enable_secret_rotation=False,
rotation_poll_interval=None,
no_wait=False,
enable_msi_auth_for_monitoring=False,
enable_msi_auth_for_monitoring=True,
enable_syslog=False,
data_collection_settings=None,):
instance = client.get(resource_group_name, name)
Expand Down Expand Up @@ -925,21 +928,29 @@ def aks_enable_addons(cmd, client, resource_group_name, name, addons,
result = LongRunningOperation(cmd.cli_ctx)(
client.begin_create_or_update(resource_group_name, name, instance))

# For monitoring addon, Metrics role assignement doesnt require in case of MSI auth
if enable_monitoring and not enable_msi_auth_for_monitoring:
if enable_monitoring:
from msrestazure.tools import resource_id
cluster_resource_id = resource_id(
subscription=subscription_id,
resource_group=resource_group_name,
namespace='Microsoft.ContainerService', type='managedClusters',
name=name
)
cloud_name = cmd.cli_ctx.cloud.name
# mdm metrics supported only in Azure Public cloud so add the role assignment only in this cloud
if cloud_name.lower() == 'azurecloud':
from msrestazure.tools import resource_id
cluster_resource_id = resource_id(
subscription=subscription_id,
resource_group=resource_group_name,
namespace='Microsoft.ContainerService', type='managedClusters',
name=name
)
# For monitoring addon, Metrics role assignement doesnt require in case of MSI auth
if not enable_msi_auth_for_monitoring and cloud_name.lower() == 'azurecloud':
Comment thread
wanlonghenry marked this conversation as resolved.
Outdated
# mdm metrics supported only in Azure Public cloud so add the role assignment only in this cloud
add_monitoring_role_assignment(
result, cluster_resource_id, cmd)

if enable_msi_auth_for_monitoring and cloud_name.lower() != 'azurecloud':
Comment thread
wanlonghenry marked this conversation as resolved.
Outdated
try:
get_user_assigned_identity_by_resource_id(cluster_resource_id)
Comment thread
wanlonghenry marked this conversation as resolved.
Outdated
Comment thread
wanlonghenry marked this conversation as resolved.
Outdated
except InvalidArgumentValueError:
enable_msi_auth_for_monitoring = False
# raise ArgumentUsageError("--enable_msi_auth_for_monitoring are only support in public cloud.")
# logger.warning("--enable_msi_auth_for_monitoring are only support in public cloud.")
Comment thread
wanlonghenry marked this conversation as resolved.
Outdated

if ingress_appgw_addon_enabled:
add_ingress_appgw_addon_role_assignment(result, cmd)

Expand All @@ -960,7 +971,7 @@ def aks_enable_addons(cmd, client, resource_group_name, name, addons,

def _update_addons(cmd, instance, subscription_id, resource_group_name, name, addons, enable,
workspace_resource_id=None,
enable_msi_auth_for_monitoring=False,
enable_msi_auth_for_monitoring=True,
Comment thread
wanlonghenry marked this conversation as resolved.
subnet_name=None,
appgw_name=None,
appgw_subnet_cidr=None,
Expand Down