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(ko): Default repo for pushing ko:// images #7010

Merged
merged 2 commits into from
Jan 13, 2022

Conversation

halvards
Copy link
Contributor

@halvards halvards commented Jan 12, 2022

When using the ko:// scheme prefix for the Skaffold image name, the rest of the image name that follows the prefix, is a Go import path.

This import path maps to the Git repository location (typically), and won't match an image registry name (e.g., ko://github.com/org/repo vs gcr.io/project_id). Currently, the result is a hard-to-understand error resulting from a failed push to the non-existent host called ko (see #6933).

With this change, if all of the following are true, the build results in an error that instructs the user to set the default repo:

  • the image name in skaffold.yaml uses the ko:// prefix; and
  • the Skaffold default repo is not set; and
  • the image is being pushed to a registry (rather than sideloaded to a Docker daemon).

Fixes: #6933
Tracking: #6041

@halvards halvards requested a review from a team as a code owner January 12, 2022 10:31
@codecov
Copy link

codecov bot commented Jan 12, 2022

Codecov Report

Merging #7010 (1d4388a) into main (290280e) will decrease coverage by 1.69%.
The diff coverage is 56.96%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #7010      +/-   ##
==========================================
- Coverage   70.48%   68.79%   -1.70%     
==========================================
  Files         515      554      +39     
  Lines       23150    25695    +2545     
==========================================
+ Hits        16317    17676    +1359     
- Misses       5776     6820    +1044     
- Partials     1057     1199     +142     
Impacted Files Coverage Δ
cmd/skaffold/app/cmd/deploy.go 52.00% <ø> (-1.85%) ⬇️
cmd/skaffold/app/cmd/dev.go 84.61% <0.00%> (ø)
cmd/skaffold/app/cmd/render.go 36.66% <0.00%> (-4.72%) ⬇️
cmd/skaffold/skaffold.go 0.00% <0.00%> (ø)
cmd/skaffold/app/cmd/inspect_tests.go 62.50% <14.28%> (-1.14%) ⬇️
cmd/skaffold/app/cmd/lsp.go 28.12% <28.12%> (ø)
cmd/skaffold/app/cmd/fix.go 68.85% <40.00%> (-7.62%) ⬇️
cmd/skaffold/app/cmd/lint.go 42.85% <42.85%> (ø)
cmd/skaffold/app/cmd/find_configs.go 48.88% <50.00%> (+0.24%) ⬆️
cmd/skaffold/app/skaffold.go 76.19% <70.00%> (-8.43%) ⬇️
... and 181 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 8cd8b69...1d4388a. Read the comment docs.

When using the `ko://` scheme prefix for the Skaffold image name, the
rest of the image name, following the prefix, is a Go import path.

This import path maps to the Git repository (typically), and won't match
an image registry name (e.g., `ko://github.com/org/repo` vs
`gcr.io/project_id`).

With this change, if _all_ of the following are true, the build results
in an error that instructs the user to set the default repo:

- the image name in `skaffold.yaml` uses the `ko://` prefix; and
- the Skaffold default repo is _not_ set; and
- the image is being pushed to a registry (rather than sideloaded to a
  Docker daemon).

Fixes: GoogleContainerTools#6933
Tracking: GoogleContainerTools#6041
@@ -37,6 +37,9 @@ import (
// identifier. The image identifier is the tag or digest for pushed images, or
// the docker image ID for sideloaded images.
func (b *Builder) Build(ctx context.Context, out io.Writer, a *latestV1.Artifact, ref string) (string, error) {
if b.pushImages && strings.HasPrefix(ref, build.StrictScheme) {
return "", fmt.Errorf("default repo must be set when using the 'ko://' prefix and pushing to a registry: %s, see https://skaffold.dev/docs/environment/image-registries/", a.ImageName)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: perhaps this information should be on the docs page as well - eg: NOTE: the ko builder requires using the default repo flag as ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @aaron-prindle, good point. I just pushed another commit to update the docs.

Copy link
Contributor

@aaron-prindle aaron-prindle left a comment

Choose a reason for hiding this comment

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

LGTM

Document that `ko` builder users who use the `ko://` prefix must set the
default repo if pushing images to a registry.

Related: GoogleContainerTools#6933
Tracking: GoogleContainerTools#6041
@halvards halvards added the kokoro:run runs the kokoro jobs on a PR label Jan 12, 2022
@kokoro-team kokoro-team removed the kokoro:run runs the kokoro jobs on a PR label Jan 12, 2022
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.

lgtm. I wonder if in the future it would be better to have this validation be done at the beginning of execution failure sooner for the user

@MarlonGamez MarlonGamez merged commit a8cfc89 into GoogleContainerTools:main Jan 13, 2022
@halvards halvards deleted the fix-6933 branch January 13, 2022 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ko builder doesn't error when no default repo is set
4 participants