Skip to content

Commit 1207571

Browse files
committed
Refactor
1 parent 47dc38c commit 1207571

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
@@ -5112,98 +5112,6 @@ def immediate_processing_after_request(self, mc: ManagedCluster) -> None:
51125112
"Could not create a role assignment for subnet. Are you an Owner on this subscription?"
51135113
)
51145114

5115-
def _should_create_dcra(self) -> bool:
5116-
"""Return True if any flag that triggers a DCRA/DCR create or update was provided."""
5117-
params = self.context.raw_param
5118-
return (
5119-
params.get("enable_addons") is not None or
5120-
params.get("enable_azure_monitor_logs") is not None or
5121-
self._is_cnl_or_hlsm_changing()
5122-
)
5123-
5124-
def _is_cnl_or_hlsm_changing(self) -> bool:
5125-
"""Return True if any CNL or High Log Scale Mode flag was provided."""
5126-
params = self.context.raw_param
5127-
return (
5128-
params.get("enable_container_network_logs") is not None or
5129-
params.get("enable_retina_flow_logs") is not None or
5130-
params.get("disable_container_network_logs") is not None or
5131-
params.get("disable_retina_flow_logs") is not None or
5132-
params.get("enable_high_log_scale_mode") is not None
5133-
)
5134-
5135-
def _postprocess_monitoring_enable(self, cluster: ManagedCluster) -> None:
5136-
"""Handle monitoring addon postprocessing for the enable case."""
5137-
enable_msi_auth_for_monitoring = self.context.get_enable_msi_auth_for_monitoring()
5138-
if not enable_msi_auth_for_monitoring:
5139-
# add cluster spn/msi Monitoring Metrics Publisher role assignment to publish metrics to MDM
5140-
# mdm metrics is supported only in azure public cloud, so add the role assignment only in this cloud
5141-
cloud_name = self.cmd.cli_ctx.cloud.name
5142-
if cloud_name.lower() == "azurecloud":
5143-
cluster_resource_id = resource_id(
5144-
subscription=self.context.get_subscription_id(),
5145-
resource_group=self.context.get_resource_group_name(),
5146-
namespace="Microsoft.ContainerService",
5147-
type="managedClusters",
5148-
name=self.context.get_name(),
5149-
)
5150-
self.context.external_functions.add_monitoring_role_assignment(
5151-
cluster, cluster_resource_id, self.cmd
5152-
)
5153-
elif self._should_create_dcra():
5154-
addon_consts = self.context.get_addon_consts()
5155-
monitoring_addon_key = _get_monitoring_addon_key(cluster, addon_consts)
5156-
self.context.external_functions.ensure_container_insights_for_monitoring(
5157-
self.cmd,
5158-
cluster.addon_profiles[monitoring_addon_key],
5159-
self.context.get_subscription_id(),
5160-
self.context.get_resource_group_name(),
5161-
self.context.get_name(),
5162-
self.context.get_location(),
5163-
remove_monitoring=False,
5164-
aad_route=self.context.get_enable_msi_auth_for_monitoring(),
5165-
create_dcr=self._is_cnl_or_hlsm_changing(),
5166-
create_dcra=True,
5167-
enable_syslog=self.context.get_enable_syslog(),
5168-
data_collection_settings=self.context.get_data_collection_settings(),
5169-
is_private_cluster=self.context.get_enable_private_cluster(),
5170-
ampls_resource_id=self.context.get_ampls_resource_id(),
5171-
enable_high_log_scale_mode=self.context.get_enable_high_log_scale_mode(),
5172-
)
5173-
5174-
def _postprocess_monitoring_disable(self) -> None:
5175-
"""Handle monitoring addon postprocessing for the disable case."""
5176-
addon_consts = self.context.get_addon_consts()
5177-
CONST_MONITORING_ADDON_NAME = addon_consts.get("CONST_MONITORING_ADDON_NAME")
5178-
5179-
# Get the current cluster state to check config before it was disabled
5180-
current_cluster = self.client.get(self.context.get_resource_group_name(), self.context.get_name())
5181-
5182-
if (current_cluster.addon_profiles and
5183-
CONST_MONITORING_ADDON_NAME in current_cluster.addon_profiles):
5184-
5185-
addon_profile = current_cluster.addon_profiles[CONST_MONITORING_ADDON_NAME]
5186-
5187-
try:
5188-
self.context.external_functions.ensure_container_insights_for_monitoring(
5189-
self.cmd,
5190-
addon_profile,
5191-
self.context.get_subscription_id(),
5192-
self.context.get_resource_group_name(),
5193-
self.context.get_name(),
5194-
self.context.get_location(),
5195-
remove_monitoring=True,
5196-
aad_route=True,
5197-
create_dcr=False,
5198-
create_dcra=True,
5199-
enable_syslog=False,
5200-
data_collection_settings=None,
5201-
ampls_resource_id=None,
5202-
enable_high_log_scale_mode=False
5203-
)
5204-
except TypeError:
5205-
pass
5206-
52075115
# pylint: disable=too-many-locals,too-many-branches
52085116
def postprocessing_after_mc_created(self, cluster: ManagedCluster) -> None:
52095117
"""Postprocessing performed after the cluster is created.
@@ -5363,6 +5271,98 @@ def postprocessing_after_mc_created(self, cluster: ManagedCluster) -> None:
53635271
resolve_assignee=False,
53645272
)
53655273

5274+
def _should_create_dcra(self) -> bool:
5275+
"""Return True if any flag that triggers a DCRA/DCR create or update was provided."""
5276+
params = self.context.raw_param
5277+
return (
5278+
params.get("enable_addons") is not None or
5279+
params.get("enable_azure_monitor_logs") is not None or
5280+
self._is_cnl_or_hlsm_changing()
5281+
)
5282+
5283+
def _is_cnl_or_hlsm_changing(self) -> bool:
5284+
"""Return True if any CNL or High Log Scale Mode flag was provided."""
5285+
params = self.context.raw_param
5286+
return (
5287+
params.get("enable_container_network_logs") is not None or
5288+
params.get("enable_retina_flow_logs") is not None or
5289+
params.get("disable_container_network_logs") is not None or
5290+
params.get("disable_retina_flow_logs") is not None or
5291+
params.get("enable_high_log_scale_mode") is not None
5292+
)
5293+
5294+
def _postprocess_monitoring_enable(self, cluster: ManagedCluster) -> None:
5295+
"""Handle monitoring addon postprocessing for the enable case."""
5296+
enable_msi_auth_for_monitoring = self.context.get_enable_msi_auth_for_monitoring()
5297+
if not enable_msi_auth_for_monitoring:
5298+
# add cluster spn/msi Monitoring Metrics Publisher role assignment to publish metrics to MDM
5299+
# mdm metrics is supported only in azure public cloud, so add the role assignment only in this cloud
5300+
cloud_name = self.cmd.cli_ctx.cloud.name
5301+
if cloud_name.lower() == "azurecloud":
5302+
cluster_resource_id = resource_id(
5303+
subscription=self.context.get_subscription_id(),
5304+
resource_group=self.context.get_resource_group_name(),
5305+
namespace="Microsoft.ContainerService",
5306+
type="managedClusters",
5307+
name=self.context.get_name(),
5308+
)
5309+
self.context.external_functions.add_monitoring_role_assignment(
5310+
cluster, cluster_resource_id, self.cmd
5311+
)
5312+
elif self._should_create_dcra():
5313+
addon_consts = self.context.get_addon_consts()
5314+
monitoring_addon_key = _get_monitoring_addon_key(cluster, addon_consts)
5315+
self.context.external_functions.ensure_container_insights_for_monitoring(
5316+
self.cmd,
5317+
cluster.addon_profiles[monitoring_addon_key],
5318+
self.context.get_subscription_id(),
5319+
self.context.get_resource_group_name(),
5320+
self.context.get_name(),
5321+
self.context.get_location(),
5322+
remove_monitoring=False,
5323+
aad_route=self.context.get_enable_msi_auth_for_monitoring(),
5324+
create_dcr=self._is_cnl_or_hlsm_changing(),
5325+
create_dcra=True,
5326+
enable_syslog=self.context.get_enable_syslog(),
5327+
data_collection_settings=self.context.get_data_collection_settings(),
5328+
is_private_cluster=self.context.get_enable_private_cluster(),
5329+
ampls_resource_id=self.context.get_ampls_resource_id(),
5330+
enable_high_log_scale_mode=self.context.get_enable_high_log_scale_mode(),
5331+
)
5332+
5333+
def _postprocess_monitoring_disable(self) -> None:
5334+
"""Handle monitoring addon postprocessing for the disable case."""
5335+
addon_consts = self.context.get_addon_consts()
5336+
CONST_MONITORING_ADDON_NAME = addon_consts.get("CONST_MONITORING_ADDON_NAME")
5337+
5338+
# Get the current cluster state to check config before it was disabled
5339+
current_cluster = self.client.get(self.context.get_resource_group_name(), self.context.get_name())
5340+
5341+
if (current_cluster.addon_profiles and
5342+
CONST_MONITORING_ADDON_NAME in current_cluster.addon_profiles):
5343+
5344+
addon_profile = current_cluster.addon_profiles[CONST_MONITORING_ADDON_NAME]
5345+
5346+
try:
5347+
self.context.external_functions.ensure_container_insights_for_monitoring(
5348+
self.cmd,
5349+
addon_profile,
5350+
self.context.get_subscription_id(),
5351+
self.context.get_resource_group_name(),
5352+
self.context.get_name(),
5353+
self.context.get_location(),
5354+
remove_monitoring=True,
5355+
aad_route=True,
5356+
create_dcr=False,
5357+
create_dcra=True,
5358+
enable_syslog=False,
5359+
data_collection_settings=None,
5360+
ampls_resource_id=None,
5361+
enable_high_log_scale_mode=False
5362+
)
5363+
except TypeError:
5364+
pass
5365+
53665366

53675367
class AKSPreviewManagedClusterUpdateDecorator(AKSManagedClusterUpdateDecorator):
53685368
def __init__(

0 commit comments

Comments
 (0)