@@ -5748,6 +5748,11 @@ def update_monitoring_profile_flow_logs(self, mc: ManagedCluster) -> ManagedClus
57485748 """
57495749 self ._ensure_mc (mc )
57505750
5751+ # Call the base class implementation if it exists (CLI >= 2.84.0 added this method to the base).
5752+ # This ensures any base-class monitoring handling (e.g., enable/disable) is applied first.
5753+ if hasattr (super (), 'update_monitoring_profile_flow_logs' ):
5754+ mc = super ().update_monitoring_profile_flow_logs (mc )
5755+
57515756 # Trigger validation for high log scale mode when container network logs are enabled.
57525757 # This ensures proper error messages are raised before cluster update if the user
57535758 # explicitly disables high log scale mode while enabling container network logs.
@@ -5784,35 +5789,45 @@ def update_monitoring_profile_flow_logs(self, mc: ManagedCluster) -> ManagedClus
57845789 # monitoring with MSI auth is already enabled, then trigger the DCR update via postprocessing.
57855790 enable_high_log_scale_mode = self .context .raw_param .get ("enable_high_log_scale_mode" )
57865791 if enable_high_log_scale_mode is True :
5787- addon_consts = self .context .get_addon_consts ()
5788- CONST_MONITORING_ADDON_NAME = addon_consts .get ("CONST_MONITORING_ADDON_NAME" )
5789- CONST_MONITORING_USING_AAD_MSI_AUTH = addon_consts .get ("CONST_MONITORING_USING_AAD_MSI_AUTH" )
5792+ # Check if monitoring is being enabled in the same command
5793+ enable_azure_monitor_logs = self .context .raw_param .get ("enable_azure_monitor_logs" )
5794+ enable_addons = self .context .raw_param .get ("enable_addons" )
5795+ monitoring_being_enabled = (
5796+ enable_azure_monitor_logs or
5797+ (enable_addons and "monitoring" in enable_addons )
5798+ )
57905799
5791- # Resolve the addon profile, handling both "omsagent" and "omsAgent" key variants.
5792- monitoring_addon_profile = None
5793- if mc .addon_profiles :
5794- monitoring_addon_profile = (
5795- mc .addon_profiles .get (CONST_MONITORING_ADDON_NAME ) or
5796- mc .addon_profiles .get (CONST_MONITORING_ADDON_NAME_CAMELCASE )
5797- )
5800+ if not monitoring_being_enabled :
5801+ # Only validate existing addon state when not enabling monitoring simultaneously
5802+ addon_consts = self .context .get_addon_consts ()
5803+ CONST_MONITORING_ADDON_NAME = addon_consts .get ("CONST_MONITORING_ADDON_NAME" )
5804+ CONST_MONITORING_USING_AAD_MSI_AUTH = addon_consts .get ("CONST_MONITORING_USING_AAD_MSI_AUTH" )
5805+
5806+ # Resolve the addon profile, handling both "omsagent" and "omsAgent" key variants.
5807+ monitoring_addon_profile = None
5808+ if mc .addon_profiles :
5809+ monitoring_addon_profile = (
5810+ mc .addon_profiles .get (CONST_MONITORING_ADDON_NAME ) or
5811+ mc .addon_profiles .get (CONST_MONITORING_ADDON_NAME_CAMELCASE )
5812+ )
57985813
5799- if not monitoring_addon_profile or not monitoring_addon_profile .enabled :
5800- raise RequiredArgumentMissingError (
5801- "--enable-high-log-scale-mode requires the Azure Monitor logs addon (omsagent) "
5802- "to be enabled on the cluster. Please enable it first with "
5803- "--enable-addons monitoring or --enable-azure-monitor-logs."
5804- )
5814+ if not monitoring_addon_profile or not monitoring_addon_profile .enabled :
5815+ raise RequiredArgumentMissingError (
5816+ "--enable-high-log-scale-mode requires the Azure Monitor logs addon (omsagent) "
5817+ "to be enabled on the cluster. Please enable it first with "
5818+ "--enable-addons monitoring or --enable-azure-monitor-logs."
5819+ )
58055820
5806- addon_config = monitoring_addon_profile .config or {}
5807- msi_auth_enabled = (
5808- CONST_MONITORING_USING_AAD_MSI_AUTH in addon_config and
5809- str (addon_config [CONST_MONITORING_USING_AAD_MSI_AUTH ]).lower () == "true"
5810- )
5811- if not msi_auth_enabled :
5812- raise RequiredArgumentMissingError (
5813- "--enable-high-log-scale-mode requires MSI authentication to be enabled "
5814- "for the monitoring addon. Please enable it with --enable-msi-auth-for-monitoring."
5821+ addon_config = monitoring_addon_profile .config or {}
5822+ msi_auth_enabled = (
5823+ CONST_MONITORING_USING_AAD_MSI_AUTH in addon_config and
5824+ str (addon_config [CONST_MONITORING_USING_AAD_MSI_AUTH ]).lower () == "true"
58155825 )
5826+ if not msi_auth_enabled :
5827+ raise RequiredArgumentMissingError (
5828+ "--enable-high-log-scale-mode requires MSI authentication to be enabled "
5829+ "for the monitoring addon. Please enable it with --enable-msi-auth-for-monitoring."
5830+ )
58165831
58175832 self .context .set_intermediate ("monitoring_addon_postprocessing_required" , True , overwrite_exists = True )
58185833
@@ -7777,10 +7792,14 @@ def _disable_azure_monitor_logs(self, mc: ManagedCluster) -> None:
77777792
77787793 # Now disable the addon and clear configuration
77797794 mc .addon_profiles [addon_key ].enabled = False
7795+ mc .addon_profiles [addon_key ].config = None
77807796
7781- # Use empty dict instead of None - setting config=None causes the SDK serializer
7782- # to omit the config key entirely, which Azure interprets as "keep existing config"
7783- mc .addon_profiles [addon_key ].config = {}
7797+ # Also disable azureMonitorProfile.containerInsights (the new API surface)
7798+ # The RP uses containerInsights.enabled as the source of truth; if it remains
7799+ # true while the legacy addon is disabled, the RP re-enables the addon.
7800+ if (mc .azure_monitor_profile and
7801+ mc .azure_monitor_profile .container_insights ):
7802+ mc .azure_monitor_profile .container_insights .enabled = False
77847803
77857804 # Also disable OpenTelemetry logs when disabling Azure Monitor logs
77867805 if opentelemetry_logs_enabled :
@@ -7917,7 +7936,10 @@ def update_mc_profile_preview(self) -> ManagedCluster:
79177936 # update acns in network_profile
79187937 mc = self .update_acns_in_network_profile (mc )
79197938 # update update_monitoring_profile_flow_logs
7920- mc = self .update_monitoring_profile_flow_logs (mc )
7939+ # Only call here if the base class doesn't already call it in update_mc_profile_default
7940+ # (CLI >= 2.84.0 added this call to the base class)
7941+ if not hasattr (super (), 'update_monitoring_profile_flow_logs' ):
7942+ mc = self .update_monitoring_profile_flow_logs (mc )
79217943 # update kubernetes support plan
79227944 mc = self .update_k8s_support_plan (mc )
79237945 # update AI toolchain operator
0 commit comments