From 808ff30660f265fa2d919475e976e005d6095d90 Mon Sep 17 00:00:00 2001 From: Junwei He Date: Tue, 11 Nov 2025 18:48:20 -0500 Subject: [PATCH 1/3] Adding CLI changes for AGC Scenario --- .../azext_connectedk8s/_precheckutils.py | 4 ++++ src/connectedk8s/azext_connectedk8s/_utils.py | 7 +++++-- src/connectedk8s/azext_connectedk8s/custom.py | 12 ++++++++++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/connectedk8s/azext_connectedk8s/_precheckutils.py b/src/connectedk8s/azext_connectedk8s/_precheckutils.py index 231f2b4c659..ea617d9aa66 100644 --- a/src/connectedk8s/azext_connectedk8s/_precheckutils.py +++ b/src/connectedk8s/azext_connectedk8s/_precheckutils.py @@ -241,6 +241,7 @@ def executing_cluster_diagnostic_checks_job( kube_config, kube_context, helm_client_location, + mcr_url ) # Watching for cluster diagnostic checks container to reach in completed stage @@ -421,6 +422,7 @@ def helm_install_release_cluster_diagnostic_checks( kube_context: str | None, helm_client_location: str, onboarding_timeout: str = "60", + mcr_url: str ) -> None: cmd_helm_install = [ helm_client_location, @@ -437,6 +439,8 @@ def helm_install_release_cluster_diagnostic_checks( # To set some other helm parameters through file cmd_helm_install.extend(["--set", f"global.location={location}"]) cmd_helm_install.extend(["--set", f"global.azureCloud={azure_cloud}"]) + cmd_helm_install.extend(["--set", f"global.mcrRepository={mcr_url}"]) + cmd_helm_install.extend(["--set", f"global.image.registry={mcr_url}"]) if https_proxy: cmd_helm_install.extend(["--set", f"global.httpsProxy={https_proxy}"]) if http_proxy: diff --git a/src/connectedk8s/azext_connectedk8s/_utils.py b/src/connectedk8s/azext_connectedk8s/_utils.py index 15547848469..d287b9aa288 100644 --- a/src/connectedk8s/azext_connectedk8s/_utils.py +++ b/src/connectedk8s/azext_connectedk8s/_utils.py @@ -69,7 +69,7 @@ def get_mcr_path(active_directory_endpoint: str) -> str: mcr_postfix = "com" # special cases for USSec, exclude part of suffix if len(active_directory_array) == 4 and active_directory_array[2] == "microsoft": - mcr_postfix = active_directory_array[3] + mcr_postfix = active_directory_array[3].strip("/") # special case for USNat elif len(active_directory_array) == 5: mcr_postfix = ( @@ -77,7 +77,7 @@ def get_mcr_path(active_directory_endpoint: str) -> str: + "." + active_directory_array[3] + "." - + active_directory_array[4] + + active_directory_array[4].strip("/") ) mcr_url = f"mcr.microsoft.{mcr_postfix}" @@ -244,6 +244,9 @@ def pull_helm_chart( ) base_path = os.path.dirname(chart_url) + # for special case when base_path contains additional /v2 segment + if base_path.endswith("/v2"): + base_path = base_path[:-3] image_name = os.path.basename(chart_url) chart_url = base_path + "/v2/" + image_name diff --git a/src/connectedk8s/azext_connectedk8s/custom.py b/src/connectedk8s/azext_connectedk8s/custom.py index d0e399bcbb2..894b852f484 100644 --- a/src/connectedk8s/azext_connectedk8s/custom.py +++ b/src/connectedk8s/azext_connectedk8s/custom.py @@ -302,8 +302,16 @@ def create_connectedk8s( # Install kubectl and helm try: - kubectl_client_location = install_kubectl_client() - helm_client_location = install_helm_client(cmd) + # Skip kubectl and helm install for AGC + cloud_name = azure_cloud.lower() + if cloud_name == "ussec" or cloud_name == "usnat": + logger.info("Skipping kubectl and helm install for AGC. Expecting them to be pre-installed.") + # Update path manually if needed + kubectl_client_location = "/usr/local/bin/kubectl" + helm_client_location = "/usr/bin/helm" + else: + kubectl_client_location = install_kubectl_client() + helm_client_location = install_helm_client(cmd) except Exception as e: raise CLIInternalError( f"An exception has occured while trying to perform kubectl or helm install: {e}" From ef28cf68aa5bae57804f8d5e064ab1a6b0b073f2 Mon Sep 17 00:00:00 2001 From: Junwei He Date: Wed, 12 Nov 2025 18:48:38 -0500 Subject: [PATCH 2/3] Adding CLI changes for AGC Scenario --- .../azext_connectedk8s/_precheckutils.py | 4 ++-- src/connectedk8s/azext_connectedk8s/_utils.py | 6 +++++- src/connectedk8s/azext_connectedk8s/custom.py | 17 +++++++++++++---- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/connectedk8s/azext_connectedk8s/_precheckutils.py b/src/connectedk8s/azext_connectedk8s/_precheckutils.py index ea617d9aa66..4727b52f72d 100644 --- a/src/connectedk8s/azext_connectedk8s/_precheckutils.py +++ b/src/connectedk8s/azext_connectedk8s/_precheckutils.py @@ -241,7 +241,7 @@ def executing_cluster_diagnostic_checks_job( kube_config, kube_context, helm_client_location, - mcr_url + mcr_url, ) # Watching for cluster diagnostic checks container to reach in completed stage @@ -421,8 +421,8 @@ def helm_install_release_cluster_diagnostic_checks( kube_config: str | None, kube_context: str | None, helm_client_location: str, + mcr_url: str, onboarding_timeout: str = "60", - mcr_url: str ) -> None: cmd_helm_install = [ helm_client_location, diff --git a/src/connectedk8s/azext_connectedk8s/_utils.py b/src/connectedk8s/azext_connectedk8s/_utils.py index d287b9aa288..3959e4a1c92 100644 --- a/src/connectedk8s/azext_connectedk8s/_utils.py +++ b/src/connectedk8s/azext_connectedk8s/_utils.py @@ -1868,6 +1868,8 @@ def add_agc_endpoint_overrides( arm_metadata_endpoint_array[2] + "." + arm_metadata_endpoint_array[3] ) if cloud_name.lower() == "usnat": + if len(arm_metadata_endpoint_array) < 5: + raise CLIInternalError("Unexpected loginEndpoint format for AGC") cloud_suffix = ( arm_metadata_endpoint_array[2] + "." @@ -1886,7 +1888,9 @@ def add_agc_endpoint_overrides( "--set", f"systemDefaultValues.azureArcAgents.config_dp_endpoint_override=https://{location}.dp.kubernetesconfiguration.azure.{endpoint_suffix}", "--set", - f"systemDefaultValues.clusterconnect-agent.notification_dp_endpoint_override=https://guestnotificationservice.azure.{endpoint_suffix}", + f"systemDefaultValues.clusterconnect-agent.connect_dp_endpoint_override=https://{location}.dp.kubernetesconfiguration.azure.{endpoint_suffix}", + "--set", + f"systemDefaultValues.clusterconnect-agent.notification_dp_endpoint_override=https://guestnotificationservice.azure.{endpoint_suffix}/", "--set", f"systemDefaultValues.clusterconnect-agent.relay_endpoint_suffix_override=.servicebus.cloudapi.{endpoint_suffix}", "--set", diff --git a/src/connectedk8s/azext_connectedk8s/custom.py b/src/connectedk8s/azext_connectedk8s/custom.py index 894b852f484..61ea1335822 100644 --- a/src/connectedk8s/azext_connectedk8s/custom.py +++ b/src/connectedk8s/azext_connectedk8s/custom.py @@ -305,10 +305,19 @@ def create_connectedk8s( # Skip kubectl and helm install for AGC cloud_name = azure_cloud.lower() if cloud_name == "ussec" or cloud_name == "usnat": - logger.info("Skipping kubectl and helm install for AGC. Expecting them to be pre-installed.") - # Update path manually if needed - kubectl_client_location = "/usr/local/bin/kubectl" - helm_client_location = "/usr/bin/helm" + logger.info( + "Skipping kubectl and helm install for AGC. Expecting them to be pre-installed." + ) + kubectl_client_location = shutil.which("kubectl") + helm_client_location = shutil.which("helm") + if not kubectl_client_location: + raise CLIInternalError( + "kubectl not found in PATH for AGC environment. Please install it or add to PATH." + ) + if not helm_client_location: + raise CLIInternalError( + "helm not found in PATH for AGC environment. Please install it or add to PATH." + ) else: kubectl_client_location = install_kubectl_client() helm_client_location = install_helm_client(cmd) From 692ceb057a60282ab42932746cc8f108a3593390 Mon Sep 17 00:00:00 2001 From: Junwei He Date: Wed, 19 Nov 2025 09:49:42 -0500 Subject: [PATCH 3/3] remove special case for base_path, false scenario --- src/connectedk8s/azext_connectedk8s/_utils.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/connectedk8s/azext_connectedk8s/_utils.py b/src/connectedk8s/azext_connectedk8s/_utils.py index 3959e4a1c92..b08cd5ba39a 100644 --- a/src/connectedk8s/azext_connectedk8s/_utils.py +++ b/src/connectedk8s/azext_connectedk8s/_utils.py @@ -244,9 +244,6 @@ def pull_helm_chart( ) base_path = os.path.dirname(chart_url) - # for special case when base_path contains additional /v2 segment - if base_path.endswith("/v2"): - base_path = base_path[:-3] image_name = os.path.basename(chart_url) chart_url = base_path + "/v2/" + image_name