Skip to content

KubernetesClientConfiguration.BuildDefaultConfig() does not populate namespace of the current context #372

@rynowak

Description

@rynowak

I'm using KubernetesClientConfiguration.BuildDefaultConfig() to try and emulate things operations the user could do at the command-line (using their current context).

I noticed that I don't get the namespace populated in the config. In this case I would expect it to be set to blazing-pizza but I get back null.

var config = KubernetesClientConfiguration.BuildDefaultConfig();
Console.WriteLine(config.Namespace); // always null

My contexts:

$ kubectl config get-contexts
CURRENT   NAME           CLUSTER        AUTHINFO                                NAMESPACE
*         rynowak-kubo   rynowak-kubo   <user>                                 blazing-pizza
$ kubectl version
Client Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.4", GitCommit:"8d8aa39598534325ad77120c120a22b3a990b5ea", GitTreeState:"clean", BuildDate:"2020-03-12T23:41:24Z", GoVersion:"go1.14", Compiler:"gc", Platform:"darwin/amd64"}

What I've noticed about this is that I can work around this because it's populated on ContextDetails but not on Context. I haven't been able to find any examples on the net of a case where Context.Namespace would get populated based on the yaml. Might be historical?

image

My (heavily redacted) ~/.kube/config

apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: <cert>
    server: <server>
  name: rynowak-kubo
- cluster:
    certificate-authority-data: <cert>
    server: <server>
  name: rynowak-ndc-demo
contexts:
- context:
    cluster: rynowak-kubo
    namespace: blazing-pizza
    user: <user>
  name: rynowak-kubo
current-context: rynowak-kubo
kind: Config
preferences: {}
users:
- name: <user>
  user:
    client-certificate-data:  <cert>
    client-key-data: <key>
    token: <token>
- name: <user>
  user:
    client-certificate-data: <cert>
    client-key-data: <key>
    token: <token>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions