Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

given multiple kubeconfigs with competing current-context properties, the last defined property is used #6787

Open
adietish opened this issue Jan 14, 2025 · 2 comments
Labels

Comments

@adietish
Copy link
Contributor

adietish commented Jan 14, 2025

follows up on #6240

Describe the bug

Given using several kubeconfig files that all have a current-context property, the client is using the last one. It should use the one in the first file.

The docs in kubernetes specify that the first file to contribute a current-context is used, further files do not override the first file

Preserve the context of the first file to set current-context

Fabric8 Kubernetes Client version

7.0.0

Steps to reproduce

  1. ASSERT: have the env var KUBECONFIG set to use 2 config files
export KUBECONFIG=${HOME}/.kube/config:${HOME}/.kube/minikube.yaml
  1. ASSERT: have current-context set in both files
  • config
current-context: erroneous
  • minikube.yaml
current-context: minikube
  1. EXEC: create a configuration using autoconfigure
Config.autoConfigure(null)
  1. EXEC: check the current context in the config
config.getCurrentContext()

Result

The current context is minikube

Expected behavior

The current context should be erroneous and thus config.getCurrentContext() return null

@adietish
Copy link
Contributor Author

I can contribute a fix if you want me to.

@manusa
Copy link
Member

manusa commented Jan 14, 2025

The context selection is performed here:

final var mergedContexts = mergeContexts(clientConfig, kubeconfigs);
clientConfig.setContexts(new ArrayList<>(mergedContexts.values()));
// Try to load the context requested by the user, otherwise fallback to the one selected in the first .kube/config
NamedContext currentContext = null;
for (String contextName : contextPreference(context, kubeconfigs)) {
if (mergedContexts.containsKey(contextName)) {
currentContext = mergedContexts.get(contextName);
break;
}
}
if (currentContext == null || currentContext.getContext() == null) {
return;
}
clientConfig.setCurrentContext(currentContext);

This code seems fine given a first look.

I can contribute a fix if you want me to.

Please go ahead. I guess you already have a way to reproduce it.

@manusa manusa added the bug label Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants