Skip to content

Commit

Permalink
[SDK] Read namespace from the current context (#2255)
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Velichkevich <[email protected]>
  • Loading branch information
andreyvelich committed Sep 10, 2024
1 parent 2cc5dfe commit ed38c24
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion sdk/python/kubeflow/training/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

from kubeflow.training import models
from kubeflow.training.constants import constants
from kubernetes import config

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -68,7 +69,11 @@ def is_running_in_k8s():

def get_default_target_namespace():
if not is_running_in_k8s():
return constants.DEFAULT_NAMESPACE
try:
_, current_context = config.list_kube_config_contexts()
return current_context["context"]["namespace"]
except Exception:
return constants.DEFAULT_NAMESPACE
with open("/var/run/secrets/kubernetes.io/serviceaccount/namespace", "r") as f:
return f.readline()

Expand Down

0 comments on commit ed38c24

Please sign in to comment.