-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add CLI option --kube-context
to override the kubecontext in Skaffold
#2447
Add CLI option --kube-context
to override the kubecontext in Skaffold
#2447
Conversation
--kube-context
to override the kubecontext in Skaffold
currentConfigErr error | ||
kubeConfigOnce sync.Once | ||
kubeConfig clientcmd.ClientConfig | ||
kubeContext string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit sad about introducing some global state here. However, I have considered several alternatives and this appeared to be the one with the least head-ache overall. Let me know your thoughts...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it was already a global state, it is fine.
Maybe in the future we can think about how to combine it with RunContext.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was already investigating in that direction. That requires to pass down the RunContext in quite a few places, so I decided against it. But it's a good idea nevertheless.
Codecov Report
|
currentConfigErr error | ||
kubeConfigOnce sync.Once | ||
kubeConfig clientcmd.ClientConfig | ||
kubeContext string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it was already a global state, it is fine.
Maybe in the future we can think about how to combine it with RunContext.
func getCurrentConfig() (clientcmdapi.Config, error) { | ||
currentConfigOnce.Do(func() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why did we change the semantics of the currentConfigOnce
?
Doesn't this open up the possibilities of inconsitencies in a skaffold process that started off version1 of a kubeconfig file but then someone mutated that file and a second read would be of version2?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The once-semantic is now encapsulated in getKubeConfig
. So for the moment we are safe here. However, in the future when the kube-context is also overridden by skaffold.yaml
, we will have to re-read the kubeconfig. This will occur during the skaffold.yaml
parsing/profile phase and should not take very long. Do you think Skaffold should take extra precautions to work with the identical kubeconfig as in the first kubeconfig read?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found a nice way to ensure that Skaffold always uses the kubeconfig from the first read. Note that this has not been the case with respect to the kubernetes REST client so far, and is much more consistent now.
Note that there is still the possibility, that the kubecontext changes due to a change in skaffold.yaml
(via UseKubeContext
). However, that is the desired behavior.
af067a1
to
f756516
Compare
This comment has been minimized.
This comment has been minimized.
I will have a look tomorrow - but as a tip: can you rebase on top of master? Sometimes changes might impact Travis vs local - as Travis does merge master in your branch. It does look odd that test-dev is around, I see you added logs to see if it gets cleaned up from the other test... |
@balopat 🤦♂️ Thanks that gives me a lead as to what is going wrong. You don't have to waste your time, I can debug further now. |
f756516
to
f03f295
Compare
Alright, I found what is going on: I think this is mainly a problem how the EDIT I opened #2496 with more details about this issue. |
f03f295
to
35d3f77
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried out locally with merging with the latest from master and I'm having port forwarding issues.
skaffold dev --default-repo gcr.io/balintp-gcp-lab --rpc-http-port 8080 --port-forward=true
on microservices example times out. Maybe we're missing a kubecontext passed down there somewhere?
yup, we're missing kubecontext here: https://github.com/GoogleContainerTools/skaffold/blob/master/pkg/skaffold/kubernetes/portforward/kubectl_forwarder.go#L54 It could be useful to just do a mechanical search for anything |
Oh no! I wasn't aware that so many places called Thanks for catching this early! |
8c02de9
to
b0c6771
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM after rebase.
6ea807d
to
19a7e44
Compare
Rebase is done. Thanks everyone for reviewing and helping out! |
Signed-off-by: Cornelius Weig <22861411+corneliusweig@users.noreply.github.com>
Many places in the code assume that kubeConfig.CurrentContext is the correct kubeContext to use. In order to avoid passing down the configured value, the cached kubeConfig is modified with the true kubeContext to use. For that, an override kubeContext is configured early on. Signed-off-by: Cornelius Weig <22861411+corneliusweig@users.noreply.github.com>
This ensures that overridden defaults are consistent when using the kubeconfig and the REST client. Signed-off-by: Cornelius Weig <22861411+corneliusweig@users.noreply.github.com>
Signed-off-by: Cornelius Weig <22861411+corneliusweig@users.noreply.github.com>
Signed-off-by: Cornelius Weig <22861411+corneliusweig@users.noreply.github.com>
Signed-off-by: Cornelius Weig <22861411+corneliusweig@users.noreply.github.com>
Signed-off-by: Cornelius Weig <22861411+corneliusweig@users.noreply.github.com>
… kubeconfig Signed-off-by: Cornelius Weig <22861411+corneliusweig@users.noreply.github.com>
Fix gocritic issue
19a7e44
to
090374e
Compare
Looks like another glitch in the CI. I've rebased one more time :) |
Sorry @corneliusweig, we changed from travis-ci.org to premium. We cancelled all jobs in the old free travis and hence you must have seen a failure. |
This PR adds a new CLI option
--kube-context
to Skaffoldrun
,dev
,debug
,delete
,deploy
, andbuild
. It's the frist step in providing several options to override the kubecontext to use in Skaffold.See #2384
Depends on #2509