-
Notifications
You must be signed in to change notification settings - Fork 2k
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
docker context use: modify current kubeconfig #1620
base: master
Are you sure you want to change the base?
Conversation
For contexts with a Kubernetes endpoint, `docker context use` now modifies the current kubeconfig file, to make sure `kubectl` and `docker` CLIs target the same cluster. This can be skipped with `--skip-kubeconfig`. Signed-off-by: Simon Ferquel <[email protected]>
Codecov Report
@@ Coverage Diff @@
## master #1620 +/- ##
==========================================
+ Coverage 55.16% 55.19% +0.03%
==========================================
Files 301 301
Lines 20384 20426 +42
==========================================
+ Hits 11244 11275 +31
- Misses 8335 8342 +7
- Partials 805 809 +4 |
@silvin-lubecki @thaJeztah PTAL |
I'm a bit on the fence for the |
If I want to switch just the context for kubernetes, I can still use the If so, we should think of a way to indicate that |
I think there is a misunderstanding about what skip-kubeconfig does: it still applies the context for both all endpoints. What has changed with this PR is that if the context contains a kubernetes endpoint, docker context use also modified the current kubeconfig file so that kubectl and other tools using kubectl config file (helm, skaffold,...) connect to the same cluster as the docker CLI. When the flag is set, only the docker CLI is impacted by docker context use. |
For now, |
I'm not sure about mutating an existing Kubernetes config file. Could you provide more examples of how your envisage that working? It feels a little action at a distance, and I think we need a longer term view of interactions between the Docker CLI and the Kubernetes API to help decide the best course of action. The primary usecase for the Kubernetes part of context at present is passing the Kubernetes context to |
@garethr an example here:
It also applies to a workflow where I want to use Compose on Kubernetes + Skaffold, or Helm or any tool using |
If we need to further design work, I suggest we close this PR and maybe re-open it when we figure out what the experience should be. |
Perhaps |
@thaJeztah for the docker cli itself, the flag does not change anything (it still applies both docker and kubernetes endpoints configuration). It just impact external tools like The Default behavior before this PR is:
Behavior after this PR:
|
Again, I am completely ok with not merging this if you feel it is confusing to have the docker CLI modify the |
Ah, yes, sorry, brainfart; you explained that above
Yes, definitely something to dig further into;
|
@chris-crone @vdemeester @silvin-lubecki should we continue the discussion on this one? |
The way I imagined it would work (without having thought about it very hard) is that the docker context config wouldn't contain any kube credentials of its own, but only a pointer to a kube current-context. Then docker context switch would automatically switch the kube context too by calling kube config use-context. That avoids cloning the kube credentials, so that it's obvious what is the single source of truth for them. But maybe it doesn't cover some use case I haven't thought about. |
You can always remove entries in your kubeconfig file. So consistency could not be ensured |
- What I did
For contexts with a Kubernetes endpoint,
docker context use
now modifies the current kubeconfig file, to make surekubectl
anddocker
CLIs target the same cluster. This can be skipped with--skip-kubeconfig
.- How I did it
Using the k8s clientcmd package, I parse and modify the ambient kubeconfig file with the configuration stored in the context store
- How to verify it
This is covered by unit tests
- A picture of a cute animal (not mandatory but encouraged)
