Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • L liquidprompt
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Issues 33
    • Issues 33
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 15
    • Merge requests 15
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Container Registry
    • Terraform modules
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Johann Dreo
  • liquidprompt
  • Merge requests
  • !681

Add Kubernetes context default namespace

  • Review changes

  • Download
  • Patches
  • Plain diff
Merged Johann Dreo requested to merge feature/kube-namespaces into master Aug 12, 2021
  • Overview 3
  • Commits 2
  • Pipelines 0
  • Changes 3

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:

  1. Is this data you want to see? I know it is for me, but do others want it?
  2. Would you want this displayed in a different way?
  3. Should the delimiter (:) be configurable? Especially since kubectl does not limit what characters can be in context names, so a colon could be part of a name.
  4. 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.
Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: feature/kube-namespaces