From b27687d48d684f43b3664f5e36295c133fa2cff4 Mon Sep 17 00:00:00 2001 From: Fuming Zhang Date: Wed, 9 Sep 2026 06:05:03 +0000 Subject: [PATCH 1/3] {AKS} Fix live scenario contracts and proxy bootstrap Use supported ALB arguments, verify persisted state after void reimage actions, handle precise capability gates and operation preemption, and replace the unavailable legacy proxy package repository with Ubuntu 24.04 Squid. Require bounded proxy readiness before creating AKS. Validation: 55 tests and 21 subtests passed; 388 scenarios collected. Ubuntu 24.04 container bootstrap returned HTTP 200 through all four HTTP/HTTPS proxy paths. Syntax, style and diff checks passed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../tests/latest/data/setup_proxy.sh | 37 ++-- .../tests/latest/test_aks_commands.py | 116 ++++++++---- .../latest/test_aks_provisioning_retry.py | 178 ++++++++++++++++++ 3 files changed, 273 insertions(+), 58 deletions(-) diff --git a/src/aks-preview/azext_aks_preview/tests/latest/data/setup_proxy.sh b/src/aks-preview/azext_aks_preview/tests/latest/data/setup_proxy.sh index 879a0988688..9d0765970ae 100644 --- a/src/aks-preview/azext_aks_preview/tests/latest/data/setup_proxy.sh +++ b/src/aks-preview/azext_aks_preview/tests/latest/data/setup_proxy.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -set -x +set -euxo pipefail echo "setting up" WORKDIR="${1:-$(mktemp -d)}" @@ -7,22 +7,14 @@ echo "setting up ${WORKDIR}" pushd "$WORKDIR" -apt update -y && apt install -y apt-transport-https curl gnupg make gcc < /dev/null - -# add diladele apt key -wget -qO - https://packages.diladele.com/diladele_pub.asc | apt-key add - - -# add new repo -tee /etc/apt/sources.list.d/squid413-ubuntu20.diladele.com.list < Date: Wed, 9 Sep 2026 06:09:05 +0000 Subject: [PATCH 2/3] {AKS} Keep preview monitoring profiles consistent Apply the canonical Container Insights synchronization fix to aks-preview's separate addon and flow-log implementations. Preserve other Azure Monitor settings and add wire-payload regressions plus a Pending release note. Validation: 69 targeted preview tests and 23 subtests passed across the scenario, custom-command, and flow-log suites; product style and syntax checks passed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/aks-preview/HISTORY.rst | 1 + src/aks-preview/azext_aks_preview/custom.py | 13 ++++ .../managed_cluster_decorator.py | 5 ++ .../tests/latest/test_custom.py | 71 +++++++++++++++++++ 4 files changed, 90 insertions(+) diff --git a/src/aks-preview/HISTORY.rst b/src/aks-preview/HISTORY.rst index fc91075c6a6..c43392f637c 100644 --- a/src/aks-preview/HISTORY.rst +++ b/src/aks-preview/HISTORY.rst @@ -11,6 +11,7 @@ To release a new version, please select a new version number (usually plus 1 to Pending +++++++ +* `az aks enable-addons`, `az aks disable-addons` and `az aks update`: Keep Container Insights monitoring and container network log settings consistent with the legacy monitoring addon when updating clusters. * `az aks machine add`: Add preview `--capacity-reservation-group` support to associate a machine with a Capacity Reservation Group. * Add `az aks alert-config` commands to manage AKS-managed alert configurations. * `az aks create`: Honor `--enable-osdisk-full-caching` for the default agent pool. diff --git a/src/aks-preview/azext_aks_preview/custom.py b/src/aks-preview/azext_aks_preview/custom.py index e14eace7eb1..0566a831259 100644 --- a/src/aks-preview/azext_aks_preview/custom.py +++ b/src/aks-preview/azext_aks_preview/custom.py @@ -4085,6 +4085,19 @@ def _update_addons(cmd, # pylint: disable=too-many-branches,too-many-statements raise CLIError(f"The addon {addon} is not installed.") addon_profiles[addon].config = None addon_profiles[addon].enabled = enable + if addon == CONST_MONITORING_ADDON_NAME: + monitor_profile = getattr(instance, "azure_monitor_profile", None) + if getattr(monitor_profile, "container_insights", None) is not None: + # Reset canonical monitoring values along with the legacy addon config. + ContainerInsights = cmd.get_models( + "ManagedClusterAzureMonitorProfileContainerInsights", + resource_type=CUSTOM_MGMT_AKS_PREVIEW, + operation_group="managed_clusters", + ) + monitor_profile.container_insights = ContainerInsights( + enabled=enable, + log_analytics_workspace_resource_id=workspace_resource_id if enable else None, + ) instance.addon_profiles = addon_profiles diff --git a/src/aks-preview/azext_aks_preview/managed_cluster_decorator.py b/src/aks-preview/azext_aks_preview/managed_cluster_decorator.py index a9a88b3c8e8..7fef93edcb7 100644 --- a/src/aks-preview/azext_aks_preview/managed_cluster_decorator.py +++ b/src/aks-preview/azext_aks_preview/managed_cluster_decorator.py @@ -6662,6 +6662,11 @@ def update_monitoring_profile_flow_logs(self, mc: ManagedCluster) -> ManagedClus config = monitoring_addon_profile.config or {} config["enableRetinaNetworkFlags"] = str(container_network_logs_enabled) mc.addon_profiles[monitoring_addon_key].config = config + container_insights = getattr(mc.azure_monitor_profile, "container_insights", None) + if container_insights is not None: + container_insights.container_network_logs = ( + "Enabled" if container_network_logs_enabled else "Disabled" + ) # When enabling CNL, the DCR must be updated to add the high-scale stream. # Set the postprocessing intermediate so that the update path calls ensure_container_insights. diff --git a/src/aks-preview/azext_aks_preview/tests/latest/test_custom.py b/src/aks-preview/azext_aks_preview/tests/latest/test_custom.py index 8d2e76a7a08..4fb6eba9903 100644 --- a/src/aks-preview/azext_aks_preview/tests/latest/test_custom.py +++ b/src/aks-preview/azext_aks_preview/tests/latest/test_custom.py @@ -2,6 +2,7 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. # -------------------------------------------------------------------------------------------- +import json import unittest from unittest.mock import Mock, patch @@ -231,6 +232,76 @@ def test_aks_enable_addons_virtual_node_with_none_agent_pool_profiles(self): self.assertNotIn("NoneType", str(type(e))) +class TestMonitoringProfileConsistency(unittest.TestCase): + @staticmethod + def _cluster(): + from azext_aks_preview.vendored_sdks.azure_mgmt_preview_aks import models + + return models.ManagedCluster( + location="westus2", + addon_profiles={"omsagent": models.ManagedClusterAddonProfile( + enabled=True, + config={"enableRetinaNetworkFlags": "true", "useAADAuth": "true"}, + )}, + azure_monitor_profile=models.ManagedClusterAzureMonitorProfile( + container_insights=models.ManagedClusterAzureMonitorProfileContainerInsights( + enabled=True, container_network_logs="Enabled", + ), + metrics=models.ManagedClusterAzureMonitorProfileMetrics(enabled=True), + ), + ) + + @staticmethod + def _wire_properties(cluster): + from azext_aks_preview.vendored_sdks.azure_mgmt_preview_aks import ContainerServiceClient + + class RequestCaptured(Exception): + pass + + with ContainerServiceClient(Mock(), "sub") as client: + with patch.object(client._client._pipeline, "run", side_effect=RequestCaptured) as send: + try: + client.managed_clusters.begin_create_or_update("rg", "cluster", cluster) + except RequestCaptured: + return json.loads(send.call_args.args[0].body)["properties"] + raise AssertionError("The preview SDK did not construct the managed cluster PUT") + + def test_disable_and_reenable_monitoring_updates_both_wire_profiles(self): + from azext_aks_preview.custom import _update_addons + + register_aks_preview_resource_type() + cmd = MockCmd(MockCLI()) + cluster = self._cluster() + workspace = "/subscriptions/sub/resourceGroups/rg/providers/Microsoft.OperationalInsights/workspaces/workspace" + for enable in (False, True): + with self.subTest(enable=enable): + _update_addons(cmd, cluster, "sub", "rg", "cluster", "monitoring", enable, + workspace_resource_id=workspace) + payload = self._wire_properties(cluster) + insights = payload["azureMonitorProfile"]["containerInsights"] + self.assertEqual(insights["enabled"], enable) + self.assertEqual(payload["addonProfiles"]["omsagent"]["enabled"], enable) + self.assertNotEqual(insights.get("containerNetworkLogs"), "Enabled") + if enable: + self.assertEqual(insights["logAnalyticsWorkspaceResourceId"], workspace) + self.assertTrue(payload["azureMonitorProfile"]["metrics"]["enabled"]) + + def test_disable_flow_logs_updates_both_wire_profiles(self): + from azext_aks_preview.managed_cluster_decorator import AKSPreviewManagedClusterUpdateDecorator + + register_aks_preview_resource_type() + cluster = self._cluster() + decorator = AKSPreviewManagedClusterUpdateDecorator( + MockCmd(MockCLI()), Mock(), {"disable_container_network_logs": True}, CUSTOM_MGMT_AKS_PREVIEW, + ) + decorator.context.attach_mc(cluster) + decorator.update_monitoring_profile_flow_logs(cluster) + payload = self._wire_properties(cluster) + self.assertEqual(payload["azureMonitorProfile"]["containerInsights"]["containerNetworkLogs"], "Disabled") + self.assertEqual(payload["addonProfiles"]["omsagent"]["config"]["enableRetinaNetworkFlags"].lower(), "false") + self.assertTrue(payload["azureMonitorProfile"]["metrics"]["enabled"]) + + class TestAksAgentPoolGetBootstrapData(unittest.TestCase): def setUp(self): register_aks_preview_resource_type() From b5bbb71a241563f08139143c12de280174a0075c Mon Sep 17 00:00:00 2001 From: Fuming Zhang Date: Wed, 9 Sep 2026 09:23:05 +0000 Subject: [PATCH 3/3] {AKS} Accept service-normalized flow-log flag casing Assert true/false values for legacy string flags without depending on service capitalization. Preserve create, disable, and re-enable checks. Validation: affected test_aks_create_acns_with_flow_logs passed end-to-end LIVE (752.46 seconds). Original True-versus-true failure retained in validation evidence. No unit or mocked run substitutes for this result. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../tests/latest/test_aks_commands.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/aks-preview/azext_aks_preview/tests/latest/test_aks_commands.py b/src/aks-preview/azext_aks_preview/tests/latest/test_aks_commands.py index b09813fdf97..f0c7e8a2860 100644 --- a/src/aks-preview/azext_aks_preview/tests/latest/test_aks_commands.py +++ b/src/aks-preview/azext_aks_preview/tests/latest/test_aks_commands.py @@ -21787,7 +21787,9 @@ def test_aks_create_acns_with_flow_logs( self.check("networkProfile.advancedNetworking.observability.enabled", True), self.check("networkProfile.advancedNetworking.security.enabled", True), self.check("addonProfiles.omsagent.enabled", True), - self.check("addonProfiles.omsagent.config.enableRetinaNetworkFlags", "True"), + self.check( + "contains(['True', 'true'], addonProfiles.omsagent.config.enableRetinaNetworkFlags)", True + ), ], ).get_output_in_json() @@ -21812,7 +21814,9 @@ def test_aks_create_acns_with_flow_logs( disable_cmd, checks=[ self.check("provisioningState", "Succeeded"), - self.check("addonProfiles.omsagent.config.enableRetinaNetworkFlags", "False"), + self.check( + "contains(['False', 'false'], addonProfiles.omsagent.config.enableRetinaNetworkFlags)", True + ), ], ) @@ -21822,7 +21826,9 @@ def test_aks_create_acns_with_flow_logs( enable_cmd_update, checks=[ self.check("provisioningState", "Succeeded"), - self.check("addonProfiles.omsagent.config.enableRetinaNetworkFlags", "True"), + self.check( + "contains(['True', 'true'], addonProfiles.omsagent.config.enableRetinaNetworkFlags)", True + ), ], )