Skip to content

Commit

Permalink
Fixed get_current_namespace for in-cluster configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Bobbins228 authored and openshift-merge-bot[bot] committed May 23, 2024
1 parent 54e90f5 commit 077db18
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/codeflare_sdk/cluster/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,14 +633,29 @@ def get_current_namespace(): # pragma: no cover
print("Unable to find current namespace")
return None
else:
try:
_, active_context = config.list_kube_config_contexts(config_check())
except Exception as e:
return _kube_api_error_handling(e)
try:
return active_context["context"]["namespace"]
except KeyError:
return None
if "KUBERNETES_PORT" in os.environ:
if os.path.isfile(
"/var/run/secrets/kubernetes.io/serviceaccount/namespace"
):
try:
file = open(
"/var/run/secrets/kubernetes.io/serviceaccount/namespace", "r"
)
active_context = file.readline().strip("\n")
return active_context
except Exception as e:
print(
"unable to gather namespace from /var/run/secrets/kubernetes.io/serviceaccount/namespace trying to gather from current context"
)
else:
try:
_, active_context = config.list_kube_config_contexts(config_check())
except Exception as e:
return _kube_api_error_handling(e)
try:
return active_context["context"]["namespace"]
except KeyError:
return None


def get_cluster(
Expand Down

0 comments on commit 077db18

Please sign in to comment.