Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/aks-preview/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ To release a new version, please select a new version number (usually plus 1 to

Pending
+++++++
* Fix monitoring addon key casing compatibility with azure-cli/acs

19.0.0b28
+++++++
Expand Down
40 changes: 21 additions & 19 deletions src/aks-preview/azext_aks_preview/managed_cluster_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7597,21 +7597,9 @@ def _setup_azure_monitor_logs(self, mc: ManagedCluster) -> None:
mc.addon_profiles = {}

CONST_MONITORING_ADDON_NAME = addon_consts.get("CONST_MONITORING_ADDON_NAME")

# Detect existing key (could be "omsagent" or "omsAgent" from Azure API)
existing_key = None
if CONST_MONITORING_ADDON_NAME in mc.addon_profiles:
existing_key = CONST_MONITORING_ADDON_NAME
elif CONST_MONITORING_ADDON_NAME_CAMELCASE in mc.addon_profiles:
existing_key = CONST_MONITORING_ADDON_NAME_CAMELCASE

if existing_key:
addon_profile = mc.addon_profiles[existing_key]
else:
addon_profile = self.models.ManagedClusterAddonProfile(enabled=False)
existing_key = CONST_MONITORING_ADDON_NAME

addon_profile.enabled = True
CONST_MONITORING_LOG_ANALYTICS_WORKSPACE_RESOURCE_ID = addon_consts.get(
"CONST_MONITORING_LOG_ANALYTICS_WORKSPACE_RESOURCE_ID")
CONST_MONITORING_USING_AAD_MSI_AUTH = addon_consts.get("CONST_MONITORING_USING_AAD_MSI_AUTH")

# Get or create workspace resource ID
workspace_resource_id = self.context.raw_param.get("workspace_resource_id")
Expand All @@ -7628,16 +7616,30 @@ def _setup_azure_monitor_logs(self, mc: ManagedCluster) -> None:
sanitize_func = self.context.external_functions.sanitize_loganalytics_ws_resource_id
workspace_resource_id = sanitize_func(workspace_resource_id)

CONST_MONITORING_LOG_ANALYTICS_WORKSPACE_RESOURCE_ID = addon_consts.get(
"CONST_MONITORING_LOG_ANALYTICS_WORKSPACE_RESOURCE_ID")
CONST_MONITORING_USING_AAD_MSI_AUTH = addon_consts.get("CONST_MONITORING_USING_AAD_MSI_AUTH")

# Call get_enable_msi_auth_for_monitoring BEFORE detecting the existing key,
# because the parent's implementation may normalize addon_profiles keys in-place
# (e.g., renaming "omsAgent" to "omsagent").
enable_msi_auth_bool = self.context.get_enable_msi_auth_for_monitoring()
if enable_msi_auth_bool:
enable_msi_auth = "true"
else:
enable_msi_auth = "false"

# Detect existing key (could be "omsagent" or "omsAgent" from Azure API)
existing_key = None
if CONST_MONITORING_ADDON_NAME in mc.addon_profiles:
existing_key = CONST_MONITORING_ADDON_NAME
elif CONST_MONITORING_ADDON_NAME_CAMELCASE in mc.addon_profiles:
existing_key = CONST_MONITORING_ADDON_NAME_CAMELCASE

if existing_key:
addon_profile = mc.addon_profiles[existing_key]
else:
addon_profile = self.models.ManagedClusterAddonProfile(enabled=False)
existing_key = CONST_MONITORING_ADDON_NAME

addon_profile.enabled = True

new_config = {
CONST_MONITORING_LOG_ANALYTICS_WORKSPACE_RESOURCE_ID: workspace_resource_id,
CONST_MONITORING_USING_AAD_MSI_AUTH: enable_msi_auth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10922,12 +10922,13 @@ def test_setup_azure_monitor_logs_with_omsagent_camelcase(self):
# Call _setup_azure_monitor_logs
dec_1._setup_azure_monitor_logs(mc_1)

# Verify: Should update existing omsAgent key (not create omsagent lowercase)
self.assertIn("omsAgent", mc_1.addon_profiles)
self.assertNotIn("omsagent", mc_1.addon_profiles) # Should NOT create duplicate
self.assertTrue(mc_1.addon_profiles["omsAgent"].enabled)
# Verify: The parent class normalizes addon keys to lowercase in-place,
# so "omsAgent" becomes "omsagent". The key point is no duplicate is created.
self.assertIn("omsagent", mc_1.addon_profiles)
self.assertEqual(len([k for k in mc_1.addon_profiles if k.lower() == "omsagent"]), 1) # No duplicate
self.assertTrue(mc_1.addon_profiles["omsagent"].enabled)
self.assertEqual(
mc_1.addon_profiles["omsAgent"].config["logAnalyticsWorkspaceResourceID"],
mc_1.addon_profiles["omsagent"].config["logAnalyticsWorkspaceResourceID"],
"/subscriptions/test/resourceGroups/test/providers/Microsoft.OperationalInsights/workspaces/test-workspace"
)

Expand Down
Loading