|
59 | 59 | CONST_INGRESS_APPGW_WATCH_NAMESPACE, |
60 | 60 | CONST_KUBE_DASHBOARD_ADDON_NAME, |
61 | 61 | CONST_MONITORING_ADDON_NAME, |
| 62 | + CONST_MONITORING_ADDON_NAME_CAMELCASE, |
62 | 63 | CONST_MONITORING_LOG_ANALYTICS_WORKSPACE_RESOURCE_ID, |
63 | 64 | CONST_MONITORING_USING_AAD_MSI_AUTH, |
64 | 65 | CONST_NODEPOOL_MODE_USER, |
@@ -1510,19 +1511,31 @@ def _remove_nulls(managed_clusters): |
1510 | 1511 | return managed_clusters |
1511 | 1512 |
|
1512 | 1513 |
|
| 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 | + |
1513 | 1525 | # pylint: disable=line-too-long |
1514 | 1526 | def aks_disable_addons(cmd, client, resource_group_name, name, addons, no_wait=False): |
1515 | 1527 | instance = client.get(resource_group_name, name) |
1516 | 1528 | subscription_id = get_subscription_id(cmd.cli_ctx) |
| 1529 | + monitoring_addon_key = _get_monitoring_addon_key_custom(instance.addon_profiles) |
1517 | 1530 | 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': |
1522 | 1535 | # remove the DCR association because otherwise the DCR can't be deleted |
1523 | 1536 | ensure_container_insights_for_monitoring( |
1524 | 1537 | cmd, |
1525 | | - instance.addon_profiles[CONST_MONITORING_ADDON_NAME], |
| 1538 | + instance.addon_profiles[monitoring_addon_key], |
1526 | 1539 | subscription_id, |
1527 | 1540 | resource_group_name, |
1528 | 1541 | name, |
@@ -1612,12 +1625,13 @@ def aks_enable_addons(cmd, client, resource_group_name, name, addons, |
1612 | 1625 |
|
1613 | 1626 | if need_pull_for_result: |
1614 | 1627 | 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': |
1617 | 1631 | if msi_auth: |
1618 | 1632 | # create a Data Collection Rule (DCR) and associate it with the cluster |
1619 | 1633 | ensure_container_insights_for_monitoring( |
1620 | | - cmd, instance.addon_profiles[CONST_MONITORING_ADDON_NAME], |
| 1634 | + cmd, instance.addon_profiles[monitoring_addon_key], |
1621 | 1635 | subscription_id, |
1622 | 1636 | resource_group_name, |
1623 | 1637 | name, |
@@ -1648,7 +1662,7 @@ def aks_enable_addons(cmd, client, resource_group_name, name, addons, |
1648 | 1662 | raise ArgumentUsageError( |
1649 | 1663 | "--ampls-resource-id supported only in MSI auth mode.") |
1650 | 1664 | 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) |
1652 | 1666 |
|
1653 | 1667 | # adding a wait here since we rely on the result for role assignment |
1654 | 1668 | result = LongRunningOperation(cmd.cli_ctx)( |
@@ -1741,6 +1755,15 @@ def _update_addons(cmd, instance, subscription_id, resource_group_name, name, ad |
1741 | 1755 | addon_profile.config = { |
1742 | 1756 | CONST_MONITORING_LOG_ANALYTICS_WORKSPACE_RESOURCE_ID: workspace_resource_id} |
1743 | 1757 | 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 |
1744 | 1767 | elif addon == (CONST_VIRTUAL_NODE_ADDON_NAME + os_type): |
1745 | 1768 | if addon_profile.enabled: |
1746 | 1769 | 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): |
4076 | 4099 | break |
4077 | 4100 |
|
4078 | 4101 | 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 |
4081 | 4105 | except Exception as ex: # pylint: disable=broad-except |
4082 | 4106 | logger.debug("failed to check monitoring addon enabled: %s", ex) |
4083 | 4107 | return monitoring_addon_enabled |
0 commit comments