-
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 fallback to kubectl kustomize if kustomize binary isn't present #4484
Add fallback to kubectl kustomize if kustomize binary isn't present #4484
Conversation
Codecov Report
@@ Coverage Diff @@
## master #4484 +/- ##
==========================================
+ Coverage 71.70% 71.75% +0.04%
==========================================
Files 348 348
Lines 12068 12082 +14
==========================================
+ Hits 8653 8669 +16
+ Misses 2773 2772 -1
+ Partials 642 641 -1
Continue to review full report at Codecov.
|
pkg/skaffold/deploy/kustomize.go
Outdated
var out []byte | ||
var err error | ||
|
||
if k.useKubectl { |
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.
Worth noting that kubectl kustomize
only supports a subset of kustomize
functionality?
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.
yeah, this could manifest through build args being rejected by the binary depending on which version the user thinks they're using - but I think that's ok left up to them to handle? we can't really know which version of kustomize a user is targeting with their arguments without asking them, so I think it's ok to assume that whatever they pass will be compatible with whatever kustomize binary we end up using. this is of course assuming that they can easily know which one we'll select based on good documentation :)
pkg/skaffold/deploy/kustomize.go
Outdated
} | ||
|
||
func NewKustomizeDeployer(runCtx *runcontext.RunContext) *KustomizeDeployer { | ||
// if user has kustomize binary, prioritize that over kubectl kustomize | ||
useKubectl := !kustomizeBinaryCheck() |
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.
Also need to check that kubectl version ≥ 1.14 too
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.
good catch
pkg/skaffold/deploy/kustomize.go
Outdated
var out []byte | ||
var err error | ||
|
||
if k.useKubectl { |
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.
yeah, this could manifest through build args being rejected by the binary depending on which version the user thinks they're using - but I think that's ok left up to them to handle? we can't really know which version of kustomize a user is targeting with their arguments without asking them, so I think it's ok to assume that whatever they pass will be compatible with whatever kustomize binary we end up using. this is of course assuming that they can easily know which one we'll select based on good documentation :)
pkg/skaffold/deploy/kustomize.go
Outdated
} | ||
|
||
func NewKustomizeDeployer(runCtx *runcontext.RunContext) *KustomizeDeployer { | ||
// if user has kustomize binary, prioritize that over kubectl kustomize | ||
useKubectl := !kustomizeBinaryCheck() |
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.
good catch
pkg/skaffold/deploy/kustomize.go
Outdated
return false | ||
} | ||
|
||
return true |
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.
might also be worth logging the version of the binary to the user.
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.
What if they have an old old version of kustomize
?
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 read this PR as if users have kustomize binary use it even if its older version.
Does not matter if they have higher version of kubectl 1.14.
it would be really hard for us to make sure the flags users have specified in the deploy.Kustomize.Flags
config are for kustomize
or kubectl kustomize
@MarlonGamez Can you please rebase and i can take look at this |
@tejal29 I think I need to update my tests. When I last updated this they passed locally but for some reason didn't pass in Travis. I'll try to revisit some time today 👍🏽 |
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.
A few nits
pkg/skaffold/deploy/kustomize.go
Outdated
return false | ||
} | ||
|
||
return true |
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.
What if they have an old old version of kustomize
?
pkg/skaffold/deploy/kustomize.go
Outdated
} | ||
|
||
func NewKustomizeDeployer(runCtx *runcontext.RunContext, labels map[string]string) *KustomizeDeployer { | ||
// if user has kustomize binary, prioritize that over kubectl kustomize | ||
useKubectl := !kustomizeBinaryCheck() && kubectlVersionCheck(runCtx) | ||
|
||
return &KustomizeDeployer{ | ||
KustomizeDeploy: runCtx.Cfg.Deploy.KustomizeDeploy, | ||
kubectl: deploy.CLI{ |
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 seems odd to pass in a kubectl.CLI
if we're not to use kubectl
.
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 think I should rename useKubectl
to useKubectlKustomize
. We still need the kubectl.CLI
as the kustomize deployer still uses kubectl apply
either way
}, | ||
commands: testutil. | ||
CmdRunOut("kubectl version --client -ojson", kubectlVersion118). | ||
AndRunOut("kubectl version --client -ojson", kubectlVersion118). |
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.
Do we really run kubectl version
twice? That seems … suboptimal.
commands util.Command | ||
shouldErr bool | ||
forceDeploy bool | ||
useMockKustomizeCheck bool |
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.
From a reading perspective, it might be more intuitive for this to be kustomizeCmdAbsent
? Or move the mockKustomizeCheck
above with a comment as to its use.
pkg/skaffold/deploy/kustomize.go
Outdated
if err != nil { | ||
return false | ||
} | ||
if gt == 1 { |
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.
if gt == 1 { | |
return gt ==1 |
pkg/skaffold/deploy/kustomize.go
Outdated
return false | ||
} | ||
|
||
return true |
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 read this PR as if users have kustomize binary use it even if its older version.
Does not matter if they have higher version of kubectl 1.14.
it would be really hard for us to make sure the flags users have specified in the deploy.Kustomize.Flags
config are for kustomize
or kubectl kustomize
if test.kustomizeCmdAbsent { | ||
t.Override(&kustomizeBinaryCheck, kustomizeAbsent) | ||
} |
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.
You can rename testKustomizeCmdAbsent to testKustomizeCmdPresent and instead override the function directly here.
if test.kustomizeCmdAbsent { | |
t.Override(&kustomizeBinaryCheck, kustomizeAbsent) | |
} | |
t.Override(&kustomizeBinaryCheck, func () bool { return test.kustomizeCmdPresent} ) |
Addresses #1781, specifically, @nkubala's comment here: #1781 (comment)
Description
Changes the kustomize deployer to prioritize using the user's kustomize binary, and if one doesn't exist in the user's PATH, then use kubectl kustomize.