Created by: Rycieos
Add data gathering for the configured default namespace of the current kubectl
context. Display that data as a string directly after the context string, separated by a colon.
See Setting the namespace preference in the Kubernetes docs.
Example:
[⎈cluster:my-namespace]
While this is a separate chunk of data from the context, it is actually part of the context definition, and so it makes sense to display it along with the context.
While most Kubernetes objects are subject to the strict DNS name restrictions, kubectl contexts never have their name server-side, and so do not have the same restrictions. This means a context name can include any characters, meaning we have no safe way to parse it out of a data string. I wanted to use:
line=$(kubectl config view --minify --output 'jsonpath={.current-context}{" "}{..namespace}')
IFS=' ' read kubernetes_context kubernetes_namespace <<<"$line"
But since spaces can be in a context name, this would break.
CC: @imsky @mschuett @lyoshenka @ismith
Questions:
- Is this data you want to see? I know it is for me, but do others want it?
- Would you want this displayed in a different way?
- Should the delimiter (
:
) be configurable? Especially sincekubectl
does not limit what characters can be in context names, so a colon could be part of a name. - Can you think of a better way to get this data? I really want to do it in one call instead of two, but I can't find a way to do it safely since a context can contain whatever character we pick for a delimiter.