Skip to content

Commit ec65c5d

Browse files
committed
Update cnl hlsm workflow
1 parent b9e1e2d commit ec65c5d

5 files changed

Lines changed: 180 additions & 45 deletions

File tree

src/azure-cli/azure/cli/command_modules/acs/_consts.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@
150150

151151
# monitoring
152152
CONST_MONITORING_ADDON_NAME = "omsagent"
153+
CONST_MONITORING_ADDON_NAME_CAMELCASE = "omsAgent"
153154
CONST_MONITORING_LOG_ANALYTICS_WORKSPACE_RESOURCE_ID = "logAnalyticsWorkspaceResourceID"
154155
CONST_MONITORING_USING_AAD_MSI_AUTH = "useAADAuth"
155156

src/azure-cli/azure/cli/command_modules/acs/addonconfiguration.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import json
66
import os
77
import re
8+
import time
89

910
from azure.cli.command_modules.acs._client_factory import get_resource_groups_client, get_resources_client
1011
from azure.cli.core.util import get_file_json
@@ -22,7 +23,7 @@
2223
from azure.cli.core.azclierror import AzCLIError, CLIError, InvalidArgumentValueError, ArgumentUsageError
2324
from azure.cli.core.profiles import ResourceType
2425
from azure.cli.core.util import send_raw_request
25-
from azure.core.exceptions import HttpResponseError
26+
from azure.core.exceptions import HttpResponseError, ResourceExistsError
2627
from azure.mgmt.core.tools import parse_resource_id, resource_id
2728
from knack.log import get_logger
2829

@@ -325,18 +326,33 @@ def ensure_default_log_analytics_workspace_for_monitoring(
325326
location=workspace_region, properties={"sku": {"name": "standalone"}}
326327
)
327328

328-
async_poller = resources.begin_create_or_update_by_id(
329-
default_workspace_resource_id, "2015-11-01-preview", generic_resource
330-
)
329+
# Retry with backoff for workspace provisioning conflicts (409 Conflict)
330+
_MAX_RETRY_TIMES = 3
331+
_RETRY_SLEEP_SECONDS = 30
332+
for retry_count in range(_MAX_RETRY_TIMES):
333+
try:
334+
async_poller = resources.begin_create_or_update_by_id(
335+
default_workspace_resource_id, "2015-11-01-preview", generic_resource
336+
)
331337

332-
ws_resource_id = ""
333-
while True:
334-
result = async_poller.result(15)
335-
if async_poller.done():
336-
ws_resource_id = result.id
337-
break
338+
ws_resource_id = ""
339+
while True:
340+
result = async_poller.result(15)
341+
if async_poller.done():
342+
ws_resource_id = result.id
343+
break
344+
345+
return ws_resource_id
346+
except (HttpResponseError, ResourceExistsError) as ex:
347+
if retry_count >= (_MAX_RETRY_TIMES - 1):
348+
raise ex
349+
logger.warning(
350+
"Workspace creation conflict (attempt %d/%d), retrying in %ds...",
351+
retry_count + 1, _MAX_RETRY_TIMES, _RETRY_SLEEP_SECONDS
352+
)
353+
time.sleep(_RETRY_SLEEP_SECONDS)
338354

339-
return ws_resource_id
355+
return default_workspace_resource_id
340356

341357

342358
def sanitize_loganalytics_ws_resource_id(workspace_resource_id):

src/azure-cli/azure/cli/command_modules/acs/custom.py

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
CONST_INGRESS_APPGW_WATCH_NAMESPACE,
6060
CONST_KUBE_DASHBOARD_ADDON_NAME,
6161
CONST_MONITORING_ADDON_NAME,
62+
CONST_MONITORING_ADDON_NAME_CAMELCASE,
6263
CONST_MONITORING_LOG_ANALYTICS_WORKSPACE_RESOURCE_ID,
6364
CONST_MONITORING_USING_AAD_MSI_AUTH,
6465
CONST_NODEPOOL_MODE_USER,
@@ -1510,19 +1511,31 @@ def _remove_nulls(managed_clusters):
15101511
return managed_clusters
15111512

15121513

1514+
def _get_monitoring_addon_key_custom(addon_profiles):
1515+
"""Return the key present in addon_profiles for the monitoring addon (omsagent or omsAgent)."""
1516+
if addon_profiles is None:
1517+
return CONST_MONITORING_ADDON_NAME
1518+
if CONST_MONITORING_ADDON_NAME in addon_profiles:
1519+
return CONST_MONITORING_ADDON_NAME
1520+
if CONST_MONITORING_ADDON_NAME_CAMELCASE in addon_profiles:
1521+
return CONST_MONITORING_ADDON_NAME_CAMELCASE
1522+
return CONST_MONITORING_ADDON_NAME
1523+
1524+
15131525
# pylint: disable=line-too-long
15141526
def aks_disable_addons(cmd, client, resource_group_name, name, addons, no_wait=False):
15151527
instance = client.get(resource_group_name, name)
15161528
subscription_id = get_subscription_id(cmd.cli_ctx)
1529+
monitoring_addon_key = _get_monitoring_addon_key_custom(instance.addon_profiles)
15171530
try:
1518-
if addons == "monitoring" and CONST_MONITORING_ADDON_NAME in instance.addon_profiles and \
1519-
instance.addon_profiles[CONST_MONITORING_ADDON_NAME].enabled and \
1520-
CONST_MONITORING_USING_AAD_MSI_AUTH in instance.addon_profiles[CONST_MONITORING_ADDON_NAME].config and \
1521-
str(instance.addon_profiles[CONST_MONITORING_ADDON_NAME].config[CONST_MONITORING_USING_AAD_MSI_AUTH]).lower() == 'true':
1531+
if addons == "monitoring" and monitoring_addon_key in instance.addon_profiles and \
1532+
instance.addon_profiles[monitoring_addon_key].enabled and \
1533+
CONST_MONITORING_USING_AAD_MSI_AUTH in instance.addon_profiles[monitoring_addon_key].config and \
1534+
str(instance.addon_profiles[monitoring_addon_key].config[CONST_MONITORING_USING_AAD_MSI_AUTH]).lower() == 'true':
15221535
# remove the DCR association because otherwise the DCR can't be deleted
15231536
ensure_container_insights_for_monitoring(
15241537
cmd,
1525-
instance.addon_profiles[CONST_MONITORING_ADDON_NAME],
1538+
instance.addon_profiles[monitoring_addon_key],
15261539
subscription_id,
15271540
resource_group_name,
15281541
name,
@@ -1612,12 +1625,13 @@ def aks_enable_addons(cmd, client, resource_group_name, name, addons,
16121625

16131626
if need_pull_for_result:
16141627
if enable_monitoring:
1615-
if CONST_MONITORING_USING_AAD_MSI_AUTH in instance.addon_profiles[CONST_MONITORING_ADDON_NAME].config and \
1616-
str(instance.addon_profiles[CONST_MONITORING_ADDON_NAME].config[CONST_MONITORING_USING_AAD_MSI_AUTH]).lower() == 'true':
1628+
monitoring_addon_key = _get_monitoring_addon_key_custom(instance.addon_profiles)
1629+
if CONST_MONITORING_USING_AAD_MSI_AUTH in instance.addon_profiles[monitoring_addon_key].config and \
1630+
str(instance.addon_profiles[monitoring_addon_key].config[CONST_MONITORING_USING_AAD_MSI_AUTH]).lower() == 'true':
16171631
if msi_auth:
16181632
# create a Data Collection Rule (DCR) and associate it with the cluster
16191633
ensure_container_insights_for_monitoring(
1620-
cmd, instance.addon_profiles[CONST_MONITORING_ADDON_NAME],
1634+
cmd, instance.addon_profiles[monitoring_addon_key],
16211635
subscription_id,
16221636
resource_group_name,
16231637
name,
@@ -1648,7 +1662,7 @@ def aks_enable_addons(cmd, client, resource_group_name, name, addons,
16481662
raise ArgumentUsageError(
16491663
"--ampls-resource-id supported only in MSI auth mode.")
16501664
ensure_container_insights_for_monitoring(
1651-
cmd, instance.addon_profiles[CONST_MONITORING_ADDON_NAME], subscription_id, resource_group_name, name, instance.location, aad_route=False)
1665+
cmd, instance.addon_profiles[monitoring_addon_key], subscription_id, resource_group_name, name, instance.location, aad_route=False)
16521666

16531667
# adding a wait here since we rely on the result for role assignment
16541668
result = LongRunningOperation(cmd.cli_ctx)(
@@ -1741,6 +1755,15 @@ def _update_addons(cmd, instance, subscription_id, resource_group_name, name, ad
17411755
addon_profile.config = {
17421756
CONST_MONITORING_LOG_ANALYTICS_WORKSPACE_RESOURCE_ID: workspace_resource_id}
17431757
addon_profile.config[CONST_MONITORING_USING_AAD_MSI_AUTH] = "true" if enable_msi_auth_for_monitoring else "false"
1758+
1759+
# Preserve enableRetinaNetworkFlags (CNL) if it was set on the existing addon
1760+
# or if container network logs are being enabled simultaneously
1761+
existing_cnl = None
1762+
existing_addon = addon_profiles.get(addon) or addon_profiles.get(CONST_MONITORING_ADDON_NAME_CAMELCASE)
1763+
if existing_addon and existing_addon.config:
1764+
existing_cnl = existing_addon.config.get("enableRetinaNetworkFlags")
1765+
if existing_cnl is not None:
1766+
addon_profile.config["enableRetinaNetworkFlags"] = existing_cnl
17441767
elif addon == (CONST_VIRTUAL_NODE_ADDON_NAME + os_type):
17451768
if addon_profile.enabled:
17461769
raise CLIError('The virtual-node addon is already enabled for this managed cluster.\n'
@@ -4076,8 +4099,9 @@ def is_monitoring_addon_enabled(addons, instance):
40764099
break
40774100

40784101
addon_profiles = instance.addon_profiles or {}
4079-
monitoring_addon_enabled = is_monitoring_addon and CONST_MONITORING_ADDON_NAME in addon_profiles and addon_profiles[
4080-
CONST_MONITORING_ADDON_NAME].enabled
4102+
monitoring_addon_key = _get_monitoring_addon_key_custom(addon_profiles)
4103+
monitoring_addon_enabled = is_monitoring_addon and monitoring_addon_key in addon_profiles and addon_profiles[
4104+
monitoring_addon_key].enabled
40814105
except Exception as ex: # pylint: disable=broad-except
40824106
logger.debug("failed to check monitoring addon enabled: %s", ex)
40834107
return monitoring_addon_enabled

0 commit comments

Comments
 (0)