@@ -5027,6 +5027,19 @@ def immediate_processing_after_request(self, mc: ManagedCluster) -> None:
50275027 "Could not create a role assignment for subnet. Are you an Owner on this subscription?"
50285028 )
50295029
5030+ def _should_create_dcra (self ) -> bool :
5031+ """Return True if any flag that triggers a DCRA/DCR create or update was provided."""
5032+ params = self .context .raw_param
5033+ return (
5034+ params .get ("enable_addons" ) is not None or
5035+ params .get ("enable-azure-monitor-logs" ) is not None or
5036+ params .get ("enable_container_network_logs" ) is not None or
5037+ params .get ("enable_retina_flow_logs" ) is not None or
5038+ params .get ("disable_container_network_logs" ) is not None or
5039+ params .get ("disable_retina_flow_logs" ) is not None or
5040+ params .get ("enable_high_log_scale_mode" ) is not None
5041+ )
5042+
50305043 # pylint: disable=too-many-locals,too-many-branches
50315044 def postprocessing_after_mc_created (self , cluster : ManagedCluster ) -> None :
50325045 """Postprocessing performed after the cluster is created.
@@ -5052,13 +5065,7 @@ def postprocessing_after_mc_created(self, cluster: ManagedCluster) -> None:
50525065 self .context .external_functions .add_monitoring_role_assignment (
50535066 cluster , cluster_resource_id , self .cmd
50545067 )
5055- elif (self .context .raw_param .get ("enable_addons" ) is not None or
5056- self .context .raw_param .get ("enable-azure-monitor-logs" ) is not None or
5057- self .context .raw_param .get ("enable_container_network_logs" ) is not None or
5058- self .context .raw_param .get ("enable_retina_flow_logs" ) is not None or
5059- self .context .raw_param .get ("disable_container_network_logs" ) is not None or
5060- self .context .raw_param .get ("disable_retina_flow_logs" ) is not None or
5061- self .context .raw_param .get ("enable_high_log_scale_mode" ) is not None ):
5068+ elif self ._should_create_dcra ():
50625069 # Create/update the DCR when CNL or HLSM flags change so that the DCR streams
50635070 # (e.g. Microsoft-ContainerLogV2-HighScale) are kept in sync.
50645071 cnl_or_hlsm_changing = (
@@ -5537,6 +5544,49 @@ def update_monitoring_profile_flow_logs(self, mc: ManagedCluster) -> ManagedClus
55375544 config = monitoring_addon_profile .config or {}
55385545 config ["enableRetinaNetworkFlags" ] = str (container_network_logs_enabled )
55395546 mc .addon_profiles [CONST_MONITORING_ADDON_NAME ].config = config
5547+
5548+ # When enabling CNL, the DCR must be updated to add the high-scale stream.
5549+ # Set the postprocessing intermediate so that the update path calls ensure_container_insights.
5550+ if self .context .raw_param .get ("enable_container_network_logs" ) or \
5551+ self .context .raw_param .get ("enable_retina_flow_logs" ):
5552+ self .context .set_intermediate ("monitoring_addon_postprocessing_required" , True , overwrite_exists = True )
5553+
5554+ # When --enable-high-log-scale-mode is passed standalone on the update path, validate that
5555+ # monitoring with MSI auth is already enabled, then trigger the DCR update via postprocessing.
5556+ enable_high_log_scale_mode = self .context .raw_param .get ("enable_high_log_scale_mode" )
5557+ if enable_high_log_scale_mode is True :
5558+ addon_consts = self .context .get_addon_consts ()
5559+ CONST_MONITORING_ADDON_NAME = addon_consts .get ("CONST_MONITORING_ADDON_NAME" )
5560+ CONST_MONITORING_USING_AAD_MSI_AUTH = addon_consts .get ("CONST_MONITORING_USING_AAD_MSI_AUTH" )
5561+
5562+ # Resolve the addon profile, handling both "omsagent" and "omsAgent" key variants.
5563+ monitoring_addon_profile = None
5564+ if mc .addon_profiles :
5565+ monitoring_addon_profile = (
5566+ mc .addon_profiles .get (CONST_MONITORING_ADDON_NAME ) or
5567+ mc .addon_profiles .get (CONST_MONITORING_ADDON_NAME_CAMELCASE )
5568+ )
5569+
5570+ if not monitoring_addon_profile or not monitoring_addon_profile .enabled :
5571+ raise RequiredArgumentMissingError (
5572+ "--enable-high-log-scale-mode requires the Azure Monitor logs addon (omsagent) "
5573+ "to be enabled on the cluster. Please enable it first with "
5574+ "--enable-addons monitoring or --enable-azure-monitor-logs."
5575+ )
5576+
5577+ addon_config = monitoring_addon_profile .config or {}
5578+ msi_auth_enabled = (
5579+ CONST_MONITORING_USING_AAD_MSI_AUTH in addon_config and
5580+ str (addon_config [CONST_MONITORING_USING_AAD_MSI_AUTH ]).lower () == "true"
5581+ )
5582+ if not msi_auth_enabled :
5583+ raise RequiredArgumentMissingError (
5584+ "--enable-high-log-scale-mode requires MSI authentication to be enabled "
5585+ "for the monitoring addon. Please enable it with --enable-msi-auth-for-monitoring."
5586+ )
5587+
5588+ self .context .set_intermediate ("monitoring_addon_postprocessing_required" , True , overwrite_exists = True )
5589+
55405590 return mc
55415591
55425592 # pylint: disable=too-many-statements,too-many-locals,too-many-branches
0 commit comments