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
Is your feature request related to a problem?
When
KUBECONFIGis set to multiple files (e.g.,~/.kube/config:/home/user/.kube/other-configon Linux orC:\Users\me\.kube\config;C:\Users\me\.kube\otheron Windows), the only method that correctly merges them isBuildDefaultConfig(). However,BuildDefaultConfig()doesn't accept acurrentContextparameter — 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 singleFileInfowithout 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
kubectlsupports natively via--contextcombined with multi-fileKUBECONFIG.Describe the solution you'd like
A way to build a
KubernetesClientConfigurationthat both merges multiple KUBECONFIG files and allows specifying a context — matching whatkubectlsupports natively withKUBECONFIG=a:b kubectl --context=my-context.Environment
Happy to open an PR if you indicate the preferred approach i.e. add an overload to
BuildDefaultConfig