Skip to content

Commit

Permalink
{AKS} Fix bug related to updating DCR when non monitoring add enabled…
Browse files Browse the repository at this point in the history
… through az aks enable-addons (#30143)
  • Loading branch information
ganga1980 authored Oct 22, 2024
1 parent a7a218e commit 10eac57
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
23 changes: 21 additions & 2 deletions src/azure-cli/azure/cli/command_modules/acs/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -1152,8 +1152,7 @@ def aks_enable_addons(cmd, client, resource_group_name, name, addons,
rotation_poll_interval=rotation_poll_interval,
no_wait=no_wait,)

enable_monitoring = CONST_MONITORING_ADDON_NAME in instance.addon_profiles \
and instance.addon_profiles[CONST_MONITORING_ADDON_NAME].enabled
enable_monitoring = is_monitoring_addon_enabled(addons, instance)
ingress_appgw_addon_enabled = CONST_INGRESS_APPGW_ADDON_NAME in instance.addon_profiles \
and instance.addon_profiles[CONST_INGRESS_APPGW_ADDON_NAME].enabled

Expand Down Expand Up @@ -3254,3 +3253,23 @@ def _aks_approuting_update(
return None

return aks_update_decorator.update_mc(mc)


def is_monitoring_addon_enabled(addons, instance):
monitoring_addon_enabled = False
is_monitoring_addon = False
try:
addon_args = addons.split(',')
for addon_arg in addon_args:
if addon_arg in ADDONS:
addon = ADDONS[addon_arg]
if addon == CONST_MONITORING_ADDON_NAME:
is_monitoring_addon = True
break

addon_profiles = instance.addon_profiles or {}
monitoring_addon_enabled = is_monitoring_addon and CONST_MONITORING_ADDON_NAME in addon_profiles and addon_profiles[
CONST_MONITORING_ADDON_NAME].enabled
except Exception as ex: # pylint: disable=broad-except
logger.debug("failed to check monitoring addon enabled: %s", ex)
return monitoring_addon_enabled
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def _get_lts_versions(self, location):
).get_output_in_json()
sorted_lts_versions = sorted(lts_versions, key=version_to_tuple, reverse=False)
return sorted_lts_versions

def _get_newer_non_lts_version(self, location, version):
"""Return the nearest newer non-lts version of the specified version."""
supported_versions = self.cmd(
Expand Down Expand Up @@ -8144,6 +8144,13 @@ def test_aks_create_with_monitoring_aad_auth_msi_with_datacollectionsettings(sel
aks_name = self.create_random_name('cliakstest', 16)
self.create_new_cluster_with_monitoring_aad_auth(resource_group, resource_group_location, aks_name, user_assigned_identity=False, syslog_enabled=False, data_collection_settings=get_test_data_file_path('datacollectionsettings.json'))

@live_only()
@AllowLargeResponse()
@AKSCustomResourceGroupPreparer(random_name_length=17, name_prefix='clitest', location='westus2')
def test_aks_create_with_monitoring_aad_auth_msi_with_datacollectionsettings_and_otheraddon(self, resource_group, resource_group_location,):
aks_name = self.create_random_name('cliakstest', 16)
self.create_new_cluster_with_monitoring_aad_auth(resource_group, resource_group_location, aks_name, user_assigned_identity=False, syslog_enabled=False, data_collection_settings=get_test_data_file_path('datacollectionsettings.json'), use_ampls=False, highlogscale_mode_enabled=True, enableOtherAddon=True)

@live_only()
@AllowLargeResponse()
@AKSCustomResourceGroupPreparer(random_name_length=17, name_prefix='clitest', location='westus2')
Expand Down Expand Up @@ -8176,7 +8183,7 @@ def test_aks_create_with_private_cluster_with_monitoring_aad_auth_msi_with_ampls



def create_new_cluster_with_monitoring_aad_auth(self, resource_group, resource_group_location, aks_name, user_assigned_identity=False, syslog_enabled=False, data_collection_settings=None, use_ampls=False, highlogscale_mode_enabled=False):
def create_new_cluster_with_monitoring_aad_auth(self, resource_group, resource_group_location, aks_name, user_assigned_identity=False, syslog_enabled=False, data_collection_settings=None, use_ampls=False, highlogscale_mode_enabled=False, enableOtherAddon=False):
self.kwargs.update({
'resource_group': resource_group,
'name': aks_name,
Expand Down Expand Up @@ -8208,6 +8215,10 @@ def create_new_cluster_with_monitoring_aad_auth(self, resource_group, resource_g
create_cmd += f'--ampls-resource-id {ampls_resource_id} ' if use_ampls else ''
create_cmd += f'--enable-high-log-scale-mode ' if highlogscale_mode_enabled else ''

if enableOtherAddon:
# enable other addon such azure-policy to verify the monitoring addon and DCRs etc.. remainins intact.
self.cmd(f'aks enable-addons -a azure-policy -g={resource_group} -n={aks_name}')

response = self.cmd(create_cmd, checks=[
self.check('addonProfiles.omsagent.enabled', True),
self.check('addonProfiles.omsagent.config.useAADAuth', 'true')
Expand Down Expand Up @@ -10555,7 +10566,7 @@ def test_aks_upgrade_with_tier_switch(self, resource_group, resource_group_locat
upgrade_version = self._get_newer_non_lts_version(resource_group_location, create_version)
if upgrade_version is None:
self.skipTest('No newer non-LTS versions found in the location')

self.kwargs.update({
'resource_group': resource_group,
'name': aks_name,
Expand Down

0 comments on commit 10eac57

Please sign in to comment.