Get the default namespace from the active kubectl context
(ns=None)
| 458 | |
| 459 | # IF ns is not None, then return it, otherwise lookup the current namespace context |
| 460 | def get_namespace(ns=None): |
| 461 | """Get the default namespace from the active kubectl context""" |
| 462 | if ns != None: |
| 463 | return ns |
| 464 | get_context() # Ensure k8s context is set/exists |
| 465 | _, ctx_namespace, _ = run('kubectl', 'config view --minify --output=jsonpath={..namespace}', cstdout=True) |
| 466 | return ctx_namespace.decode('ascii') if ctx_namespace else 'default' |
| 467 | |
| 468 | def get_context(): |
| 469 | """Get the active kubectl context name""" |
nothing calls this directly
no test coverage detected