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

New tagging mechanism #1482

Merged
merged 13 commits into from
Feb 5, 2019
Merged

Conversation

dgageot
Copy link
Contributor

@dgageot dgageot commented Jan 17, 2019

This completely rewrites the image tagging mechanism. Here's how it'll work:

  • Skaffold computes a tag for an image BEFORE it's built. This removes a lot of complexity.
  • Images pushed to registries will always be referenced by name, tag and digest in kubernetes manifests. That is to make sure the wrong image is not used and to remove this complexity from tagger.
  • Images used locally can't be referenced by digest (because we don't have it) or imageID (because k8s doesn't support that). So images used locally will be tagged with their imageID to make sure we produce a unique tag that can be used in kubernetes manifests
  • taggers (git, sha256, envTemplate, datetime) are all modified so that they can't use the image digest/imageID. It makes their code simpler but breaks the envTemplate tagger as it is.

@codecov-io
Copy link

codecov-io commented Jan 17, 2019

Codecov Report

Merging #1482 into master will decrease coverage by 0.03%.
The diff coverage is 41.89%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1482      +/-   ##
==========================================
- Coverage   46.92%   46.88%   -0.04%     
==========================================
  Files         119      118       -1     
  Lines        5072     5042      -30     
==========================================
- Hits         2380     2364      -16     
+ Misses       2458     2446      -12     
+ Partials      234      232       -2
Impacted Files Coverage Δ
pkg/skaffold/build/local/types.go 0% <ø> (ø) ⬆️
pkg/skaffold/build/gcb/cloud_build.go 0% <0%> (ø) ⬆️
pkg/skaffold/deploy/helm.go 61.47% <0%> (-3.37%) ⬇️
pkg/skaffold/build/local/bazel.go 30.3% <0%> (-0.47%) ⬇️
pkg/skaffold/build/kaniko/kaniko.go 0% <0%> (ø) ⬆️
pkg/skaffold/build/kaniko/run.go 0% <0%> (ø) ⬆️
pkg/skaffold/build/local/jib_maven.go 26.66% <0%> (+1.66%) ⬆️
pkg/skaffold/build/local/jib_gradle.go 0% <0%> (ø) ⬆️
pkg/skaffold/build/tag/git_commit.go 79.16% <100%> (-5.21%) ⬇️
pkg/skaffold/build/tag/sha256.go 40% <100%> (-26.67%) ⬇️
... and 9 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 bb700a0...5cee689. Read the comment docs.

@dgageot dgageot force-pushed the new-tagging branch 3 times, most recently from 7c8af68 to d925153 Compare January 24, 2019 05:42
@dgageot dgageot force-pushed the new-tagging branch 7 times, most recently from 151c9d5 to ba3967c Compare January 29, 2019 05:38
Copy link
Contributor

@balopat balopat left a comment

Choose a reason for hiding this comment

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

I'm going to keep reviewing but - as we are in beta, we have to mark DIGEST related functionality as deprecated first, announce it, and then we can remove it in 3 months.

@@ -32,10 +32,21 @@ type envTemplateTagger struct {

// NewEnvTemplateTagger creates a new envTemplateTagger
func NewEnvTemplateTagger(t string) (Tagger, error) {
if strings.Contains(t, "{{.DIGEST}}") {
return nil, errors.New("{{.DIGEST}} is deprecated, image digest will automatically be apppended to image tags")
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
return nil, errors.New("{{.DIGEST}} is deprecated, image digest will automatically be apppended to image tags")
return nil, errors.New("{{.DIGEST}} is deprecated, image digest will automatically be appended to image tags")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This has been fixed

@@ -32,10 +32,21 @@ type envTemplateTagger struct {

// NewEnvTemplateTagger creates a new envTemplateTagger
func NewEnvTemplateTagger(t string) (Tagger, error) {
if strings.Contains(t, "{{.DIGEST}}") {
Copy link
Contributor

Choose a reason for hiding this comment

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

This wouldn't work if it has a space or do we normalize it somewhere? e.g {{ .DIGEST }}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This has been fixed

@balopat
Copy link
Contributor

balopat commented Jan 29, 2019

Otherwise everything looks good.
My recommendation would be to have

DIGEST = DIGEST
DIGEST_ALGO = sha256
DIGEST_HEX= DIGEST

and whenever these template params are used, we would print out a deprecation warning for 3 months.
WDYT?

Copy link
Contributor

@priyawadhwa priyawadhwa left a comment

Choose a reason for hiding this comment

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

For the build plugins to work, I think the tagger would need to be removed entirely from the build interface

Build(ctx context.Context, out io.Writer, tagger tag.Tagger, artifacts []*latest.Artifact) ([]Artifact, error)

would need to be

Build(ctx context.Context, out io.Writer, artifacts []*latest.Artifact) ([]Artifact, error)

where maybe we store a tag in each artifact.

Would it be possible to resolve tagging before Build is called? (I totally realize that this could be a very big refactor so it doesn't have to happen in this PR, but I don't think there's anyway around it in the long run for the plugins).

cc @balopat

@priyawadhwa priyawadhwa added this to the 1.0.0 milestone Jan 30, 2019
@dgageot
Copy link
Contributor Author

dgageot commented Jan 30, 2019

@balopat how do you see the deprecation warning working?

@dgageot dgageot force-pushed the new-tagging branch 3 times, most recently from 515bf63 to d0c29e1 Compare January 31, 2019 06:59
@dgageot dgageot force-pushed the new-tagging branch 2 times, most recently from 4be4ad6 to b77fab4 Compare February 4, 2019 08:57
@dgageot
Copy link
Contributor Author

dgageot commented Feb 4, 2019

@priyawadhwa @balopat {{.DIGEST}} and friends should be handled better now.

  • In cases where it was used as an image name suffix (like for JenkinX), a deprecation warning is printed and this suffix is ignored because it'll be done automatically now.
  • In other cases, an error is printed and can't be recovered.

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.

one small typo but deprecation logic LGTM

case strings.Contains(tag, "[DEPRECATED_DIGEST]") ||
strings.Contains(tag, "[DEPRECATED_DIGEST_ALGO]") ||
strings.Contains(tag, "[DEPRECATED_DIGEST_HEX]"):
return "", errors.New("{{.DIGEST}}, {{.DIGEST_ALGO}} and {{.DIGEST_HEX}} are deprecated, image digest will now automatically be apppended to image tags")
Copy link
Contributor

Choose a reason for hiding this comment

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

s/apppended/appended

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me fix that

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.

I think I'm cool with this, let's monitor for a few days after it gets merged to make sure we're not breaking people in ways we didn't expect

case strings.Contains(tag, "[DEPRECATED_DIGEST]") ||
strings.Contains(tag, "[DEPRECATED_DIGEST_ALGO]") ||
strings.Contains(tag, "[DEPRECATED_DIGEST_HEX]"):
return "", errors.New("{{.DIGEST}}, {{.DIGEST_ALGO}} and {{.DIGEST_HEX}} are deprecated, image digest will now automatically be appended to image tags")
Copy link
Contributor

@balopat balopat Feb 5, 2019

Choose a reason for hiding this comment

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

I feel strongly about not throwing an error here either, we should not break user workflows.

Just a warning is enough, and we can leave DEPRECATED_* (without the brackets) in the image name. A seamless upgrade allows for deferred action on the user's side. Image name uniqueness won't be a problem as we are adding the @digest suffix anyway.

I am okay to take the blame for the messy image names, if they become an issue rather than facing angry users who have to change their skaffold.yaml-s without a notice, even though they were promised a stable beta!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is fixed now

@dgageot dgageot force-pushed the new-tagging branch 2 times, most recently from 57f8005 to 0eb8ae0 Compare February 5, 2019 09:07
@dgageot dgageot removed the wip label Feb 5, 2019
Signed-off-by: David Gageot <david@gageot.net>
Signed-off-by: David Gageot <david@gageot.net>
Actually, we use:
 + imageID when the image is built locally
 + tag@sha256:abcabc when the image was pushed

We assume here that taggers never append the
digest to the tag themselves.
(Which is not true)

Signed-off-by: David Gageot <david@gageot.net>
Signed-off-by: David Gageot <david@gageot.net>
Signed-off-by: David Gageot <david@gageot.net>
Pass the final tag to the builders
and let them build and push that tag
directly.
Signed-off-by: David Gageot <david@gageot.net>
Where digest is not available and imageID can’t
be used in k8s manifests.

Signed-off-by: David Gageot <david@gageot.net>
Fix GoogleContainerTools#1349

Signed-off-by: David Gageot <david@gageot.net>
Signed-off-by: David Gageot <david@gageot.net>
Signed-off-by: David Gageot <david@gageot.net>
Signed-off-by: David Gageot <david@gageot.net>
Signed-off-by: David Gageot <david@gageot.net>
@balopat
Copy link
Contributor

balopat commented Feb 5, 2019

As dicussed let's change the "[" "]" chars to "_" so that the image names are compatible with docker, then we can merge it!

@dgageot
Copy link
Contributor Author

dgageot commented Feb 5, 2019

Woot! All green 💚 🍏 📗
Let's merge!

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.

6 participants