From 0838d955167af02b5eb2c1f75affed757563b8fd Mon Sep 17 00:00:00 2001 From: Romil Bhardwaj Date: Tue, 26 Nov 2024 11:51:04 -0800 Subject: [PATCH 1/2] Fix incluster auth namespace fetching --- sky/provision/kubernetes/utils.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/sky/provision/kubernetes/utils.py b/sky/provision/kubernetes/utils.py index 9a1de4e9036..a0096ccddd7 100644 --- a/sky/provision/kubernetes/utils.py +++ b/sky/provision/kubernetes/utils.py @@ -1045,11 +1045,14 @@ def get_kube_config_context_namespace( the default namespace. """ k8s = kubernetes.kubernetes - # Get namespace if using in-cluster config ns_path = '/var/run/secrets/kubernetes.io/serviceaccount/namespace' - if os.path.exists(ns_path): - with open(ns_path, encoding='utf-8') as f: - return f.read().strip() + # If using in-cluster context, get the namespace from the service account + # namespace file. + if (context_name == kubernetes.in_cluster_context_name() or + context_name is None): + if os.path.exists(ns_path): + with open(ns_path, encoding='utf-8') as f: + return f.read().strip() # If not in-cluster, get the namespace from kubeconfig try: contexts, current_context = k8s.config.list_kube_config_contexts() From e46e3ab374db4c6b400841266ace34f0fdbc4984 Mon Sep 17 00:00:00 2001 From: Romil Bhardwaj Date: Tue, 26 Nov 2024 11:57:09 -0800 Subject: [PATCH 2/2] Fixes --- sky/provision/kubernetes/utils.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sky/provision/kubernetes/utils.py b/sky/provision/kubernetes/utils.py index a0096ccddd7..7442c9be7a6 100644 --- a/sky/provision/kubernetes/utils.py +++ b/sky/provision/kubernetes/utils.py @@ -1047,7 +1047,8 @@ def get_kube_config_context_namespace( k8s = kubernetes.kubernetes ns_path = '/var/run/secrets/kubernetes.io/serviceaccount/namespace' # If using in-cluster context, get the namespace from the service account - # namespace file. + # namespace file. Uses the same logic as adaptors.kubernetes._load_config() + # to stay consistent with in-cluster config loading. if (context_name == kubernetes.in_cluster_context_name() or context_name is None): if os.path.exists(ns_path):