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

implement env variable expansion for kaniko builds #4557

Merged

Conversation

DanielSel
Copy link
Contributor

Adds environment variable expansion for kaniko builds (to address currently inconsistent behaviour between buildArgs and envs).
See #3974

@DanielSel DanielSel requested a review from a team as a code owner July 24, 2020 11:18
@DanielSel DanielSel changed the title Adds environment variable expansion for kaniko builds (to address currently inconsistent behaviour between buildArgs and envs). implement env variable expansion for kaniko builds Jul 24, 2020
@codecov
Copy link

codecov bot commented Jul 24, 2020

Codecov Report

Merging #4557 into master will decrease coverage by 0.00%.
The diff coverage is 79.24%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4557      +/-   ##
==========================================
- Coverage   72.36%   72.36%   -0.01%     
==========================================
  Files         360      360              
  Lines       12474    12527      +53     
==========================================
+ Hits         9027     9065      +38     
- Misses       2789     2800      +11     
- Partials      658      662       +4     
Impacted Files Coverage Δ
pkg/skaffold/schema/latest/config.go 100.00% <ø> (ø)
pkg/skaffold/build/cluster/kaniko.go 27.77% <64.51%> (+27.77%) ⬆️
pkg/skaffold/build/cluster/pod.go 86.95% <100.00%> (+0.38%) ⬆️
pkg/skaffold/docker/image.go 80.61% <100.00%> (+1.27%) ⬆️
pkg/skaffold/docker/reference.go 100.00% <100.00%> (ø)
pkg/skaffold/util/env_template.go 94.73% <0.00%> (-5.27%) ⬇️
pkg/skaffold/build/kaniko/args.go 92.85% <0.00%> (-2.39%) ⬇️

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 12d64a2...2d0bdb7. Read the comment docs.

@DanielSel DanielSel force-pushed the feature/kaniko-env-expansion branch 2 times, most recently from e1271b7 to 9296c71 Compare July 24, 2020 20:26
@DanielSel
Copy link
Contributor Author

@tejal29 @gsquared94 it seems like some of the unit tests are flaky in the CI, but run flawless locally. Took me a few attempts to get the build to pass: https://github.com/GoogleContainerTools/skaffold/runs/907521989

Now I removed the dummy commit via force-push and the build status went from passing to failing without a rebuild. Do you have any ideas what I should do?

@DanielSel DanielSel force-pushed the feature/kaniko-env-expansion branch from 1f537f4 to 9296c71 Compare July 24, 2020 20:34
@DanielSel
Copy link
Contributor Author

The Travis CI build is back to green. Thanks, in case anyone manually triggered the rebuild!

@gsquared94
Copy link
Collaborator

@DanielSel sorry about the long time to reply; was traveling. I'd restarted the failed job manually, travis can be flaky that way sometimes.

@gsquared94 gsquared94 added the kokoro:run runs the kokoro jobs on a PR label Jul 28, 2020
@kokoro-team kokoro-team removed the kokoro:run runs the kokoro jobs on a PR label Jul 28, 2020
@DanielSel DanielSel force-pushed the feature/kaniko-env-expansion branch from 9296c71 to 1d54f66 Compare July 28, 2020 09:08
@DanielSel
Copy link
Contributor Author

I fixed the oversight in parsing image names (forgot the possibility of IP:PORT as registry url) and added a test.
@gsquared94 Could you re-run kokoro?

Thanks!

@gsquared94 gsquared94 added the kokoro:run runs the kokoro jobs on a PR label Jul 28, 2020
@kokoro-team kokoro-team removed the kokoro:run runs the kokoro jobs on a PR label Jul 28, 2020
@DanielSel DanielSel force-pushed the feature/kaniko-env-expansion branch from 1d54f66 to 0f9f51c Compare July 29, 2020 11:30
@DanielSel DanielSel mentioned this pull request Jul 29, 2020
@DanielSel
Copy link
Contributor Author

@gsquared94 one last kokoro run please :)

@briandealwis briandealwis added the kokoro:run runs the kokoro jobs on a PR label Jul 29, 2020
@kokoro-team kokoro-team removed the kokoro:run runs the kokoro jobs on a PR label Jul 29, 2020
return generatedEnvs, nil
}

func parseImageParts(imageStr string) (string, string, string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you should be able to use docker.ParseReference here instead. we do this a few other places in the code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's how I started out until I realized that docker.ParseReference can't split out the image name from the repo path, which we need for our CI setup.

I could replace part of the function code with a call to docker.ParseReference and only leave the code to split IMAGE_NAME from IMAGE_REPO if you prefer.

What do you think @nkubala ?

Copy link
Contributor

Choose a reason for hiding this comment

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

sorry I totally missed this one. I was actually wrong on my original comment, we're using docker's (reference.Parse)[https://godoc.org/github.com/docker/distribution/reference#Parse] in skaffold. we finesse that into a ImageReference struct which should be able to split image name and repo path (we call it Domain) right?

if it isn't doing everything you need, I think that code should live somewhere near here so we can embed those pieces into the ImageReference struct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nkubala no worries. I'm not sure that it would make sense to refactor the ImageReference to change the way it splits image FQDN's since I assume there was a reason for this specific split.

However, I refactored my code to use docker.ParseReference (which returns the ImageReference you pointed out) instead of implementing it from scratch. Was that what you had in mind?

Copy link
Contributor

Choose a reason for hiding this comment

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

hey @DanielSel, I dug in a little more into ParseReference and how it creates the ImageReference. take the image gcr.io/k8s-skaffold/skaffold:foo as an example:

BaseName -> gcr.io/k8s-skaffold/skaffold
Domain -> gcr.io
Path -> k8s-skaffold/skaffold

the part you're interested in here is the "Repo", which would be gcr.io/k8s-skaffold. I think part of the confusion is that our terminology is not quite right here: BaseName is really "Unqualified Image Name" (to me at least), which is also "Repo" + "Image Name" (both of which are missing from this struct).

I propose that you take your logic here to split the image parts (which seems mostly fine to me as is) and move it into docker.ParseReference, and then embed "Repo" and "Image Name" into the ImageReference struct we already have. this won't change the existing usage of the struct around the codebase, but could be used later on if we wanted to, and is easier to find if we ever want to make changes to it. this isn't kaniko-specific logic, so it doesn't really belong in the kaniko package. WDYT?

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 got you now :)
Code updated.

@DanielSel
Copy link
Contributor Author

@tejal29 I took the freedom to rebase, I hope that's ok.

Could somebody trigger another kokoro run and make a decision about the requested changes please? This pull request is starting to gather dust :)

@nkubala nkubala self-assigned this Sep 17, 2020
@briandealwis briandealwis added the kokoro:force-run forces a kokoro re-run on a PR label Sep 17, 2020
@kokoro-team kokoro-team removed the kokoro:force-run forces a kokoro re-run on a PR label Sep 17, 2020
Copy link
Contributor

@nkubala nkubala left a comment

Choose a reason for hiding this comment

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

@DanielSel thank you so much for sticking with us here, this is very close but I just want to make sure we put the code in the right place the first time so we don't have to move it later :)

pkg/skaffold/build/cluster/kaniko_test.go Show resolved Hide resolved
return generatedEnvs, nil
}

func parseImageParts(imageStr string) (string, string, string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

hey @DanielSel, I dug in a little more into ParseReference and how it creates the ImageReference. take the image gcr.io/k8s-skaffold/skaffold:foo as an example:

BaseName -> gcr.io/k8s-skaffold/skaffold
Domain -> gcr.io
Path -> k8s-skaffold/skaffold

the part you're interested in here is the "Repo", which would be gcr.io/k8s-skaffold. I think part of the confusion is that our terminology is not quite right here: BaseName is really "Unqualified Image Name" (to me at least), which is also "Repo" + "Image Name" (both of which are missing from this struct).

I propose that you take your logic here to split the image parts (which seems mostly fine to me as is) and move it into docker.ParseReference, and then embed "Repo" and "Image Name" into the ImageReference struct we already have. this won't change the existing usage of the struct around the codebase, but could be used later on if we wanted to, and is easier to find if we ever want to make changes to it. this isn't kaniko-specific logic, so it doesn't really belong in the kaniko package. WDYT?

@nkubala
Copy link
Contributor

nkubala commented Sep 18, 2020

@DanielSel yep this is more what I was thinking! looks like the error you introduced in ParseReference is causing test failures though - maybe because this is being called before the default-repo is substituted on the image? I don't think we want to error here either way, probably just leave the field unpopulated. it should still give you the result you want when you're using Repo.

@DanielSel DanielSel force-pushed the feature/kaniko-env-expansion branch 2 times, most recently from 0393706 to acdcf5f Compare September 18, 2020 22:17
@DanielSel
Copy link
Contributor Author

@nkubala Sorry, my mistake. Fixed now.

@MarlonGamez
Copy link
Contributor

Hey @DanielSel, Thanks for continuously working on this! If you get the chance, would you be able to rebase and fix file conflicts? We should be able to merge this in after that :)

@google-cla
Copy link

google-cla bot commented Oct 22, 2020

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added cla: no and removed cla: yes labels Oct 22, 2020
@googlebot
Copy link

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@tejal29
Copy link
Member

tejal29 commented Oct 22, 2020

@googlebot I consent

@google-cla
Copy link

google-cla bot commented Oct 22, 2020

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added cla: yes and removed cla: no labels Oct 22, 2020
@DanielSel
Copy link
Contributor Author

DanielSel commented Oct 23, 2020

Hey @DanielSel, Thanks for continuously working on this! If you get the chance, would you be able to rebase and fix file conflicts? We should be able to merge this in after that :)

Done! @MarlonGamez

Copy link
Contributor

@nkubala nkubala left a comment

Choose a reason for hiding this comment

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

@DanielSel thanks for all your hard work on this PR, and sticking with us to see it through!

@nkubala nkubala merged commit 0ebebdf into GoogleContainerTools:master Oct 23, 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.

8 participants