Skip to content

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

Description

@thejuan

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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