From 7380c9ab70e172d745243e194bddf3a6fa15f6ea Mon Sep 17 00:00:00 2001 From: Steve Kuznetsov Date: Tue, 11 Nov 2025 16:01:01 -0700 Subject: [PATCH] aks bastion: correctly set the contents of the kubeconfig Signed-off-by: Steve Kuznetsov --- src/aks-preview/HISTORY.rst | 4 ++-- src/aks-preview/azext_aks_preview/bastion/bastion.py | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/aks-preview/HISTORY.rst b/src/aks-preview/HISTORY.rst index 24f54943038..96bb687bd00 100644 --- a/src/aks-preview/HISTORY.rst +++ b/src/aks-preview/HISTORY.rst @@ -11,11 +11,11 @@ To release a new version, please select a new version number (usually plus 1 to Pending +++++++ +* `az aks bastion`: Correctly configure `$KUBECONFIG` values for tunneling traffic into a private AKS cluster. 19.0.0b15 +++++++ -* Fix `NoneType` error when performing operations on automatic clusters that have hosted system components enabled. - +* Fix `NoneType` error when performing operations on automatic clusters that have hosted system components enabled 19.0.0b14 +++++++ diff --git a/src/aks-preview/azext_aks_preview/bastion/bastion.py b/src/aks-preview/azext_aks_preview/bastion/bastion.py index b7b7838b0ba..1bd938f980a 100644 --- a/src/aks-preview/azext_aks_preview/bastion/bastion.py +++ b/src/aks-preview/azext_aks_preview/bastion/bastion.py @@ -186,8 +186,13 @@ def aks_bastion_set_kubeconfig(kubeconfig_path, port): with open(kubeconfig_path, "r") as f: data = yaml.load(f, Loader=yaml.SafeLoader) current_context = data["current-context"] + current_cluster = "" + for context in data["contexts"]: + if context["name"] == current_context: + current_cluster = context["context"]["cluster"] + for cluster in data["clusters"]: - if cluster["name"] == current_context: + if cluster["name"] == current_cluster: server = cluster["cluster"]["server"] hostname = urlparse(server).hostname # update the server URL to point to the local port