-
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
Fix setting kubeContext
in skaffold
#6024
Conversation
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.
- Current set kubecontext is always overridden by the flags
--kube-context
and--kubeconfig
and as soon as the command starts.- We no longer treat the value provided in a skaffold config's
Deploy.KubeContext
as an override for the entire process' kubecontext value. Rather it only overrides the kubecontext provided to each deployer only at the time of deployment.
If this is the case, should we even evaluate kubecontext
at the start of the run via congifure.Once?
Could we not just create the runner with kubeContext either from CLI or current config selected by user. Once this is done for all command requiring deploys, skaffold code should only rely on Runcontext.KubeContext
field?
- This allows deploying to different kubecontexts in different skaffold modules (another requested feature)
- This necessitates that the status checker is moved inside the deployer and has a single instance per deployer (another request Skaffold
status-check
should happen after individualdeploy
actions #5774) to handle the different kubecontexts.
// Setup kubeContext and kubeConfig | ||
kubectx.ConfigureKubeConfig(opts.KubeConfig, opts.KubeContext) | ||
|
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 feel this should happen only for dev, run and deploy commands.
Not sure if this is the current behavior.
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.
unfortunately we evaluate the global config for all skaffold commands when we evaluate config.ShouldDisplaySurveyPrompt
. We need to interpret the resolved kubeContext
prior to evaluating the global config. So we need to do this check here also.
if cliKubeContext != "" { | ||
newKubeContext = cliKubeContext | ||
} | ||
func ConfigureKubeConfig(cliKubeConfig, cliKubeContext string) { | ||
configureOnce.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.
In an ideal world, pkg/skaffold
should be treated like a library, and these values should be computed in cmd/skaffold
and provided into the library.
There are also the KUBECONFIG
environment variable that should influencing this decision (and note that it is a PATH
-like variable that can specify multiple files).
Codecov Report
@@ Coverage Diff @@
## master #6024 +/- ##
==========================================
- Coverage 70.25% 70.19% -0.07%
==========================================
Files 473 475 +2
Lines 18110 18147 +37
==========================================
+ Hits 12724 12739 +15
- Misses 4454 4471 +17
- Partials 932 937 +5
Continue to review full report at Codecov.
|
kubeContext
in skaffoldkubeContext
in skaffold
Fixes: #5334, #4347
Description
Skaffold has multiple ways to set the current cluster context and it does not work as intended. The main issues are:
--kube-context
and--kubeconfig
have been processed, and stores a singleton result that doesn't get recomputed ever.runcontext
tries to figure out if the cluster is local or remote heuristically from the kubecontext but even this happens before the flags--kube-context
and--kubeconfig
have been processedkubecontext
from the skaffold config'sDeploy.KubeContext
field.This PR fixes these issues and will result in the following state:
--kube-context
and--kubeconfig
and as soon as the command starts.Deploy.KubeContext
as an override for the entire process' kubecontext value. Rather it only overrides the kubecontext provided to each deployer only at the time of deployment.Follow up work:
kubeContext
in different skaffold configs in a multi-config project is still disallowed with an artificial check as before, since it needs further changes to theLogger
andPortForwarder
constructs.