Skip to content

Commit c85fdfc

Browse files
committed
Refactor
1 parent 837ccac commit c85fdfc

File tree

1 file changed

+92
-92
lines changed

1 file changed

+92
-92
lines changed

src/aks-preview/azext_aks_preview/managed_cluster_decorator.py

Lines changed: 92 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -5201,98 +5201,6 @@ def immediate_processing_after_request(self, mc: ManagedCluster) -> None:
52015201
"Could not create a role assignment for subnet. Are you an Owner on this subscription?"
52025202
)
52035203

5204-
def _should_create_dcra(self) -> bool:
5205-
"""Return True if any flag that triggers a DCRA/DCR create or update was provided."""
5206-
params = self.context.raw_param
5207-
return (
5208-
params.get("enable_addons") is not None or
5209-
params.get("enable_azure_monitor_logs") is not None or
5210-
self._is_cnl_or_hlsm_changing()
5211-
)
5212-
5213-
def _is_cnl_or_hlsm_changing(self) -> bool:
5214-
"""Return True if any CNL or High Log Scale Mode flag was provided."""
5215-
params = self.context.raw_param
5216-
return (
5217-
params.get("enable_container_network_logs") is not None or
5218-
params.get("enable_retina_flow_logs") is not None or
5219-
params.get("disable_container_network_logs") is not None or
5220-
params.get("disable_retina_flow_logs") is not None or
5221-
params.get("enable_high_log_scale_mode") is not None
5222-
)
5223-
5224-
def _postprocess_monitoring_enable(self, cluster: ManagedCluster) -> None:
5225-
"""Handle monitoring addon postprocessing for the enable case."""
5226-
enable_msi_auth_for_monitoring = self.context.get_enable_msi_auth_for_monitoring()
5227-
if not enable_msi_auth_for_monitoring:
5228-
# add cluster spn/msi Monitoring Metrics Publisher role assignment to publish metrics to MDM
5229-
# mdm metrics is supported only in azure public cloud, so add the role assignment only in this cloud
5230-
cloud_name = self.cmd.cli_ctx.cloud.name
5231-
if cloud_name.lower() == "azurecloud":
5232-
cluster_resource_id = resource_id(
5233-
subscription=self.context.get_subscription_id(),
5234-
resource_group=self.context.get_resource_group_name(),
5235-
namespace="Microsoft.ContainerService",
5236-
type="managedClusters",
5237-
name=self.context.get_name(),
5238-
)
5239-
self.context.external_functions.add_monitoring_role_assignment(
5240-
cluster, cluster_resource_id, self.cmd
5241-
)
5242-
elif self._should_create_dcra():
5243-
addon_consts = self.context.get_addon_consts()
5244-
monitoring_addon_key = _get_monitoring_addon_key(cluster, addon_consts)
5245-
self.context.external_functions.ensure_container_insights_for_monitoring(
5246-
self.cmd,
5247-
cluster.addon_profiles[monitoring_addon_key],
5248-
self.context.get_subscription_id(),
5249-
self.context.get_resource_group_name(),
5250-
self.context.get_name(),
5251-
self.context.get_location(),
5252-
remove_monitoring=False,
5253-
aad_route=self.context.get_enable_msi_auth_for_monitoring(),
5254-
create_dcr=self._is_cnl_or_hlsm_changing(),
5255-
create_dcra=True,
5256-
enable_syslog=self.context.get_enable_syslog(),
5257-
data_collection_settings=self.context.get_data_collection_settings(),
5258-
is_private_cluster=self.context.get_enable_private_cluster(),
5259-
ampls_resource_id=self.context.get_ampls_resource_id(),
5260-
enable_high_log_scale_mode=self.context.get_enable_high_log_scale_mode(),
5261-
)
5262-
5263-
def _postprocess_monitoring_disable(self) -> None:
5264-
"""Handle monitoring addon postprocessing for the disable case."""
5265-
addon_consts = self.context.get_addon_consts()
5266-
CONST_MONITORING_ADDON_NAME = addon_consts.get("CONST_MONITORING_ADDON_NAME")
5267-
5268-
# Get the current cluster state to check config before it was disabled
5269-
current_cluster = self.client.get(self.context.get_resource_group_name(), self.context.get_name())
5270-
5271-
if (current_cluster.addon_profiles and
5272-
CONST_MONITORING_ADDON_NAME in current_cluster.addon_profiles):
5273-
5274-
addon_profile = current_cluster.addon_profiles[CONST_MONITORING_ADDON_NAME]
5275-
5276-
try:
5277-
self.context.external_functions.ensure_container_insights_for_monitoring(
5278-
self.cmd,
5279-
addon_profile,
5280-
self.context.get_subscription_id(),
5281-
self.context.get_resource_group_name(),
5282-
self.context.get_name(),
5283-
self.context.get_location(),
5284-
remove_monitoring=True,
5285-
aad_route=True,
5286-
create_dcr=False,
5287-
create_dcra=True,
5288-
enable_syslog=False,
5289-
data_collection_settings=None,
5290-
ampls_resource_id=None,
5291-
enable_high_log_scale_mode=False
5292-
)
5293-
except TypeError:
5294-
pass
5295-
52965204
# pylint: disable=too-many-locals,too-many-branches
52975205
def postprocessing_after_mc_created(self, cluster: ManagedCluster) -> None:
52985206
"""Postprocessing performed after the cluster is created.
@@ -5480,6 +5388,98 @@ def put_mc(self, mc: ManagedCluster) -> ManagedCluster:
54805388
)
54815389
return cluster
54825390

5391+
def _should_create_dcra(self) -> bool:
5392+
"""Return True if any flag that triggers a DCRA/DCR create or update was provided."""
5393+
params = self.context.raw_param
5394+
return (
5395+
params.get("enable_addons") is not None or
5396+
params.get("enable_azure_monitor_logs") is not None or
5397+
self._is_cnl_or_hlsm_changing()
5398+
)
5399+
5400+
def _is_cnl_or_hlsm_changing(self) -> bool:
5401+
"""Return True if any CNL or High Log Scale Mode flag was provided."""
5402+
params = self.context.raw_param
5403+
return (
5404+
params.get("enable_container_network_logs") is not None or
5405+
params.get("enable_retina_flow_logs") is not None or
5406+
params.get("disable_container_network_logs") is not None or
5407+
params.get("disable_retina_flow_logs") is not None or
5408+
params.get("enable_high_log_scale_mode") is not None
5409+
)
5410+
5411+
def _postprocess_monitoring_enable(self, cluster: ManagedCluster) -> None:
5412+
"""Handle monitoring addon postprocessing for the enable case."""
5413+
enable_msi_auth_for_monitoring = self.context.get_enable_msi_auth_for_monitoring()
5414+
if not enable_msi_auth_for_monitoring:
5415+
# add cluster spn/msi Monitoring Metrics Publisher role assignment to publish metrics to MDM
5416+
# mdm metrics is supported only in azure public cloud, so add the role assignment only in this cloud
5417+
cloud_name = self.cmd.cli_ctx.cloud.name
5418+
if cloud_name.lower() == "azurecloud":
5419+
cluster_resource_id = resource_id(
5420+
subscription=self.context.get_subscription_id(),
5421+
resource_group=self.context.get_resource_group_name(),
5422+
namespace="Microsoft.ContainerService",
5423+
type="managedClusters",
5424+
name=self.context.get_name(),
5425+
)
5426+
self.context.external_functions.add_monitoring_role_assignment(
5427+
cluster, cluster_resource_id, self.cmd
5428+
)
5429+
elif self._should_create_dcra():
5430+
addon_consts = self.context.get_addon_consts()
5431+
monitoring_addon_key = _get_monitoring_addon_key(cluster, addon_consts)
5432+
self.context.external_functions.ensure_container_insights_for_monitoring(
5433+
self.cmd,
5434+
cluster.addon_profiles[monitoring_addon_key],
5435+
self.context.get_subscription_id(),
5436+
self.context.get_resource_group_name(),
5437+
self.context.get_name(),
5438+
self.context.get_location(),
5439+
remove_monitoring=False,
5440+
aad_route=self.context.get_enable_msi_auth_for_monitoring(),
5441+
create_dcr=self._is_cnl_or_hlsm_changing(),
5442+
create_dcra=True,
5443+
enable_syslog=self.context.get_enable_syslog(),
5444+
data_collection_settings=self.context.get_data_collection_settings(),
5445+
is_private_cluster=self.context.get_enable_private_cluster(),
5446+
ampls_resource_id=self.context.get_ampls_resource_id(),
5447+
enable_high_log_scale_mode=self.context.get_enable_high_log_scale_mode(),
5448+
)
5449+
5450+
def _postprocess_monitoring_disable(self) -> None:
5451+
"""Handle monitoring addon postprocessing for the disable case."""
5452+
addon_consts = self.context.get_addon_consts()
5453+
CONST_MONITORING_ADDON_NAME = addon_consts.get("CONST_MONITORING_ADDON_NAME")
5454+
5455+
# Get the current cluster state to check config before it was disabled
5456+
current_cluster = self.client.get(self.context.get_resource_group_name(), self.context.get_name())
5457+
5458+
if (current_cluster.addon_profiles and
5459+
CONST_MONITORING_ADDON_NAME in current_cluster.addon_profiles):
5460+
5461+
addon_profile = current_cluster.addon_profiles[CONST_MONITORING_ADDON_NAME]
5462+
5463+
try:
5464+
self.context.external_functions.ensure_container_insights_for_monitoring(
5465+
self.cmd,
5466+
addon_profile,
5467+
self.context.get_subscription_id(),
5468+
self.context.get_resource_group_name(),
5469+
self.context.get_name(),
5470+
self.context.get_location(),
5471+
remove_monitoring=True,
5472+
aad_route=True,
5473+
create_dcr=False,
5474+
create_dcra=True,
5475+
enable_syslog=False,
5476+
data_collection_settings=None,
5477+
ampls_resource_id=None,
5478+
enable_high_log_scale_mode=False
5479+
)
5480+
except TypeError:
5481+
pass
5482+
54835483

54845484
class AKSPreviewManagedClusterUpdateDecorator(AKSManagedClusterUpdateDecorator):
54855485
def __init__(

0 commit comments

Comments
 (0)