Unverified Commit 1a77f892 authored by Mark Vander Stel's avatar Mark Vander Stel
Browse files

Parse k8s namespace out of one call instead of two

Don't know why I didn't think of this before. While contexts can
contain any character, namespaces are limited to the normal DNS name
rules, and so we can parse on the last instance of a delimiting
character found.
parent b6a1f24c
......@@ -1236,11 +1236,14 @@ _lp_kubernetes_context() {
(( LP_ENABLE_KUBECONTEXT )) || return 2
local kubernetes_context
kubernetes_context=$(kubectl config current-context 2>/dev/null) || return 1
if (( LP_ENABLE_KUBE_NAMESPACE )); then
local kubernetes_namespace
kubernetes_namespace=$(kubectl config view --minify --output 'jsonpath={..namespace}') || return 1
local line kubernetes_namespace
line=$(kubectl config view --minify --output 'jsonpath={.current-context}{"/"}{..namespace}')
kubernetes_context=${line%/*}
kubernetes_namespace=${line##*/}
else
kubernetes_context=$(kubectl config current-context 2>/dev/null) || return 1
fi
if [[ -n "$LP_DELIMITER_KUBECONTEXT_PREFIX" ]]; then
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment