kubernetes-client / kubernetes-client/csharp

BuildDefaultConfig should support specifying a context when using multi-file KUBECONFIG

Open
#1,730 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
1.2k
Forks
307
Avg merge
7d 9h
Merged PRs (30d)
6

Description

Is your feature request related to a problem?

When KUBECONFIG is set to multiple files (e.g., ~/.kube/config:/home/user/.kube/other-config on Linux or C:\Users\me\.kube\config;C:\Users\me\.kube\other on Windows), the only method that correctly merges them is BuildDefaultConfig(). However, BuildDefaultConfig() doesn't accept a currentContext parameter — it always uses the current-context from the merged config.

If you need to specify a particular context (common in test harnesses, multi-cluster tools, and CI systems), the only option is BuildConfigFromConfigFile(string kubeconfigPath, string currentContext). But this method wraps the path in a single FileInfo without splitting on the platform delimiter, so it fails with a file-not-found error when given a multi-file KUBECONFIG value.

There's no way to do both, which kubectl supports natively via --context combined with multi-file KUBECONFIG.

Describe the solution you'd like

A way to build a KubernetesClientConfiguration that both merges multiple KUBECONFIG files and allows specifying a context — matching what kubectl supports natively with KUBECONFIG=a:b kubectl --context=my-context.

Environment

  • KubernetesClient NuGet version: 18.x
  • Platform: Windows and Linux
  • Use case: Test harnesses that need to target a specific cluster context in a multi-file KUBECONFIG environment

Happy to open an PR if you indicate the preferred approach i.e. add an overload to BuildDefaultConfig

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the BuildDefaultConfig and BuildConfigFromConfigFile entry points and trace how KUBECONFIG paths and currentContext are handled. Compare the configuration behavior needed for platform-delimited multi-file values with kubectl's context selection. Done means callers can merge multiple KUBECONFIG files while selecting an explicit context on Windows and Linux.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, kubernetes
Domain
api, infrastructure
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.