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

Cluster/context selection and multi-file KUBECONFIG #123

Closed
thomas-riccardi opened this issue Apr 2, 2021 · 6 comments
Closed

Cluster/context selection and multi-file KUBECONFIG #123

thomas-riccardi opened this issue Apr 2, 2021 · 6 comments
Labels
bug Something isn't working
Milestone

Comments

@thomas-riccardi
Copy link

I have access to multiple k8s clusters, they are defined in multiple config files, all pointed-to by the KUBECONFIG env var, separated with ::

$ echo $KUBECONFIG
/home/foo/.kube/config:/home/foo/.minikube/kubeconfig

kubent doesn't support context selection, it seems to use the default context on the first config file, and if it points to a context defined in another file it fails: ERR Failed to initialize collector: <nil> error="invalid configuration: [context was not found for specified context: bar-context, cluster has no server defined]"

Currently I workaround that by setting the current context and edit KUBECONFIG, that's not ideal.

Ideally:

  • kubent supports multi-file KUBECONFIG
  • kubent supports context selection (technically as an indirect selector for cluster) with --context (alas the standard -c is already used for something else)
@stepanstipl
Copy link
Contributor

Hi @thomas-riccardi, thanks for opening this issue. I assume the "cross-file" context selection is something that works out of the box with kubectl, correct? I will have to check how that is implemented, but the idea is to behave in the same way, so it sounds like something we can look into.

Context selection makes sense. I think kubectl supports this via --context, but also --cluster and --user, flags. So probably something we can add (or at least context for a start).

@thomas-riccardi
Copy link
Author

Hi @stepanstipl

I assume the "cross-file" context selection is something that works out of the box with kubectl, correct?

Yes; that's indeed a little bit surprising for k8s tools developers but it works transparently on kubectl.
It probably merges all yaml files into one config object (concat all arrays (clusters, contexts, users) (with dedup? error on conflict?) except current-context, which seems to be taken from the first file), then work from that as usual.
kubectl config view shows the parsed/merged config.

Context selection makes sense. I think kubectl supports this via --context, but also --cluster and --user, flags. So probably something we can add (or at least context for a start).

Personally I only use --context as --cluster probably also requires --user: slower to type. So starting with --context would be perfect for me :), and hopefully not just me.

@stepanstipl stepanstipl added this to the Next Minor (0.5.0?) milestone Apr 9, 2021
@ryan-dyer-sp
Copy link

Just stumbled across this tool as something to investigate, but we also have the same issue; multiple kubeconfig files.

@stepanstipl stepanstipl added the bug Something isn't working label Jun 23, 2021
stepanstipl added a commit that referenced this issue Jul 15, 2021
Addresses multi-file part of #123
stepanstipl added a commit that referenced this issue Jul 16, 2021
Addresses multi-file part of #123
@stepanstipl
Copy link
Contributor

@thomas-riccardi @ryan-dyer-sp Support for both multiple kubeconfig files and selecting context has now been added and is part of the latest 0.5.0 release. Please give it a go and let me know if there are any issues. Cheers 👍

@ryan-dyer-sp
Copy link

@stepanstipl Can confirm it works. Thanks!

@thomas-riccardi
Copy link
Author

@stepanstipl I confirm this works in our setup, great with kubectx and explicit --context option, thx!

(though 0.5.0 broke --additional-kind: #204)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants