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

Fix issue where default-repo wasn't being added to artifact tags (#5341) #5397

Merged

Conversation

dan-j
Copy link
Contributor

@dan-j dan-j commented Feb 13, 2021

Fixes: #5341, #5463

Description
Using the --default-repo option on deploy commands wasn't being honoured and the default tag was being deployed.

It's a simple bug... The for-loop in getBuildArtifactsAndSetTags is correctly prefixing the tag with the --default-repo option but was setting it on the for-loop variable (which is a pointer re-used in each loop), and not updating the actual buildArtifacts slice.

I haven't added any tests, this is my first contribution and not sure how to get a runner.Runner in a test environment. If you want tests adding for this change could somebody give me a point in the right direction 🙂

@dan-j dan-j requested a review from a team as a code owner February 13, 2021 22:20
@google-cla google-cla bot added the cla: yes label Feb 13, 2021
@codecov
Copy link

codecov bot commented Feb 13, 2021

Codecov Report

Merging #5397 (a202f68) into master (4b3c30f) will decrease coverage by 0.10%.
The diff coverage is 50.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5397      +/-   ##
==========================================
- Coverage   71.60%   71.49%   -0.11%     
==========================================
  Files         397      398       +1     
  Lines       14434    14642     +208     
==========================================
+ Hits        10335    10468     +133     
- Misses       3333     3398      +65     
- Partials      766      776      +10     
Impacted Files Coverage Δ
cmd/skaffold/app/cmd/deploy.go 56.52% <0.00%> (ø)
cmd/skaffold/app/cmd/test.go 46.66% <0.00%> (ø)
cmd/skaffold/app/cmd/util.go 77.77% <75.00%> (+12.06%) ⬆️
pkg/skaffold/test/structure/structure.go 87.50% <0.00%> (-12.50%) ⬇️
pkg/skaffold/runner/new.go 67.58% <0.00%> (-1.70%) ⬇️
pkg/skaffold/docker/parse.go 82.16% <0.00%> (-0.81%) ⬇️
pkg/skaffold/util/config.go 77.77% <0.00%> (ø)
pkg/skaffold/errors/errors.go 87.23% <0.00%> (ø)
pkg/skaffold/runner/runner.go 0.00% <0.00%> (ø)
cmd/skaffold/app/cmd/runner.go 60.00% <0.00%> (ø)
... and 25 more

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 4b3c30f...a202f68. Read the comment docs.

for _, artifact := range buildArtifacts {
tag, err := r.ApplyDefaultRepo(artifact.Tag)
for i := range buildArtifacts {
updatedTag, err := r.ApplyDefaultRepo(buildArtifacts[i].Tag)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed the variable because it was colliding with the tag package.

@gsquared94
Copy link
Collaborator

Thanks for your contribution @dan-j

I haven't added any tests, this is my first contribution and not sure how to get a runner.Runner in a test environment. If you want tests adding for this change could somebody give me a point in the right direction 🙂

You can modify the function signature to:

func getBuildArtifactsAndSetTags(artifacts []*latest.Artifact, applyDefaultRepo func(string)(string, error)) ([]build.Artifact, error) {
  ...

and all non-test references look like:

buildArtifacts, err := getBuildArtifactsAndSetTags(artifacts, r.ApplyDefaultRepo)

That removes the pkg/skaffold/runner dependency from this file.

@dan-j
Copy link
Contributor Author

dan-j commented Feb 22, 2021

Oops, I had forgotten about this and then just ran into the problem this solves 😬

I got halfway through the tests but then sidetracked, will finish this off this week at some point

@MarlonGamez
Copy link
Contributor

hey @dan-j, have you had any time to work on this? Not meaning to pressure, just want to make sure that you have bandwith to finish this :) If not, I'm sure someone on the team could pick it up

@dan-j
Copy link
Contributor Author

dan-j commented Mar 8, 2021

Hey! Yeah I got completely sidetracked by other stuff and forgot, until I've just hit the exact same issue again when running a manual deployment 😅

I was already halfway through the tests, will try finish them tonight, if not it will be this week.

@dan-j
Copy link
Contributor Author

dan-j commented Mar 8, 2021

OK, I've added some tests.

The change @gsquared94 suggested wasn't completely straight forward because that function also uses the global flags for merging build artifacts. I've refactored the problematic code into a new function and have added tests for this new function.

@gsquared94 gsquared94 added the kokoro:force-run forces a kokoro re-run on a PR label Mar 9, 2021
@kokoro-team kokoro-team removed the kokoro:force-run forces a kokoro re-run on a PR label Mar 9, 2021
Copy link
Contributor

@MarlonGamez MarlonGamez left a comment

Choose a reason for hiding this comment

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

looks good to me! Thanks @dan-j for this :)

@gsquared94 gsquared94 merged commit 802ef8a into GoogleContainerTools:master Mar 10, 2021
@dan-j dan-j deleted the 5341-deploy-default-repo branch March 10, 2021 10:27
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.

skaffold deploy does not honour --default-repo flag
4 participants