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

Add fallback to kubectl kustomize if kustomize binary isn't present #4484

Merged
merged 11 commits into from
Sep 21, 2020

Conversation

MarlonGamez
Copy link
Contributor

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.

@codecov
Copy link

codecov bot commented Jul 16, 2020

Codecov Report

Merging #4484 into master will increase coverage by 0.04%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
pkg/skaffold/deploy/kpt.go 84.61% <100.00%> (ø)
pkg/skaffold/deploy/kubectl/cli.go 87.50% <100.00%> (+0.15%) ⬆️
pkg/skaffold/deploy/kustomize.go 78.12% <100.00%> (+1.93%) ⬆️
pkg/skaffold/util/cmd.go 51.42% <0.00%> (+5.71%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9ba0e85...8706968. Read the comment docs.

@MarlonGamez MarlonGamez marked this pull request as ready for review July 16, 2020 20:28
@MarlonGamez MarlonGamez requested a review from a team as a code owner July 16, 2020 20:28
@MarlonGamez MarlonGamez requested a review from balopat July 16, 2020 20:28
pkg/skaffold/deploy/kustomize.go Outdated Show resolved Hide resolved
var out []byte
var err error

if k.useKubectl {
Copy link
Member

@briandealwis briandealwis Jul 17, 2020

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?

Copy link
Contributor

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 :)

}

func NewKustomizeDeployer(runCtx *runcontext.RunContext) *KustomizeDeployer {
// if user has kustomize binary, prioritize that over kubectl kustomize
useKubectl := !kustomizeBinaryCheck()
Copy link
Member

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

var out []byte
var err error

if k.useKubectl {
Copy link
Contributor

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 :)

}

func NewKustomizeDeployer(runCtx *runcontext.RunContext) *KustomizeDeployer {
// if user has kustomize binary, prioritize that over kubectl kustomize
useKubectl := !kustomizeBinaryCheck()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

return false
}

return true
Copy link
Contributor

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.

Copy link
Member

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?

Copy link
Contributor

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

@tejal29
Copy link
Contributor

tejal29 commented Aug 24, 2020

@MarlonGamez Can you please rebase and i can take look at this

@MarlonGamez
Copy link
Contributor Author

@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 👍🏽

Copy link
Member

@briandealwis briandealwis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few nits

return false
}

return true
Copy link
Member

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?

}

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{
Copy link
Member

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.

Copy link
Contributor Author

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).
Copy link
Member

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
Copy link
Member

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.

@MarlonGamez MarlonGamez requested a review from yuwenma as a code owner September 9, 2020 19:39
if err != nil {
return false
}
if gt == 1 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if gt == 1 {
return gt ==1

return false
}

return true
Copy link
Contributor

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

Comment on lines 131 to 133
if test.kustomizeCmdAbsent {
t.Override(&kustomizeBinaryCheck, kustomizeAbsent)
}
Copy link
Contributor

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.

Suggested change
if test.kustomizeCmdAbsent {
t.Override(&kustomizeBinaryCheck, kustomizeAbsent)
}
t.Override(&kustomizeBinaryCheck, func () bool { return test.kustomizeCmdPresent} )

@MarlonGamez MarlonGamez merged commit 35cee15 into GoogleContainerTools:master Sep 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants