Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[k8s] Fix in-cluster auth namespace fetching #4420

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions sky/provision/kubernetes/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1045,11 +1045,15 @@ 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. 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):
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()
Expand Down