Skip to content

Commit

Permalink
Produce valid image names
Browse files Browse the repository at this point in the history
Signed-off-by: David Gageot <david@gageot.net>
  • Loading branch information
dgageot committed Feb 5, 2019
1 parent 1f9f4cb commit 5cee689
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
22 changes: 11 additions & 11 deletions pkg/skaffold/build/tag/env_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,25 +67,25 @@ func (t *envTemplateTagger) Labels() map[string]string {
func (t *envTemplateTagger) GenerateFullyQualifiedImageName(workingDir, imageName string) (string, error) {
tag, err := util.ExecuteEnvTemplate(t.Template, map[string]string{
"IMAGE_NAME": imageName,
"DIGEST": "[DEPRECATED_DIGEST]",
"DIGEST_ALGO": "[DEPRECATED_DIGEST_ALGO]",
"DIGEST_HEX": "[DEPRECATED_DIGEST_HEX]",
"DIGEST": "_DEPRECATED_DIGEST_",
"DIGEST_ALGO": "_DEPRECATED_DIGEST_ALGO_",
"DIGEST_HEX": "_DEPRECATED_DIGEST_HEX_",
})
if err != nil {
return "", err
}

if strings.Contains(tag, "[DEPRECATED_DIGEST]") ||
strings.Contains(tag, "[DEPRECATED_DIGEST_ALGO]") ||
strings.Contains(tag, "[DEPRECATED_DIGEST_HEX]") {
warner.Warnf("{{.DIGEST}}, {{.DIGEST_ALGO}} and {{.DIGEST_HEX}} are deprecated, image digest will now automatically be apppended to image tags")
if strings.Contains(tag, "_DEPRECATED_DIGEST_") ||
strings.Contains(tag, "_DEPRECATED_DIGEST_ALGO_") ||
strings.Contains(tag, "_DEPRECATED_DIGEST_HEX_") {
warner.Warnf("{{.DIGEST}}, {{.DIGEST_ALGO}} and {{.DIGEST_HEX}} are deprecated, image digest will now automatically be appended to image tags")

switch {
case strings.HasSuffix(tag, "@[DEPRECATED_DIGEST]"):
tag = strings.TrimSuffix(tag, "@[DEPRECATED_DIGEST]")
case strings.HasSuffix(tag, "@_DEPRECATED_DIGEST_"):
tag = strings.TrimSuffix(tag, "@_DEPRECATED_DIGEST_")

case strings.HasSuffix(tag, "@[DEPRECATED_DIGEST_ALGO]:[DEPRECATED_DIGEST_HEX]"):
tag = strings.TrimSuffix(tag, "@[DEPRECATED_DIGEST_ALGO]:[DEPRECATED_DIGEST_HEX]")
case strings.HasSuffix(tag, "@_DEPRECATED_DIGEST_ALGO_:_DEPRECATED_DIGEST_HEX_"):
tag = strings.TrimSuffix(tag, "@_DEPRECATED_DIGEST_ALGO_:_DEPRECATED_DIGEST_HEX_")
}
}

Expand Down
16 changes: 8 additions & 8 deletions pkg/skaffold/build/tag/env_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,35 +68,35 @@ func TestEnvTemplateTagger_GenerateFullyQualifiedImageName(t *testing.T) {
template: "{{.IMAGE_NAME}}:tag@{{.DIGEST}}",
imageName: "foo",
expected: "foo:tag",
expectedWarnings: []string{"{{.DIGEST}}, {{.DIGEST_ALGO}} and {{.DIGEST_HEX}} are deprecated, image digest will now automatically be apppended to image tags"},
expectedWarnings: []string{"{{.DIGEST}}, {{.DIGEST_ALGO}} and {{.DIGEST_HEX}} are deprecated, image digest will now automatically be appended to image tags"},
},
{
name: "ignore @{{.DIGEST_ALGO}}:{{.DIGEST_HEX}} suffix",
template: "{{.IMAGE_NAME}}:tag@{{.DIGEST_ALGO}}:{{.DIGEST_HEX}}",
imageName: "image_name",
expected: "image_name:tag",
expectedWarnings: []string{"{{.DIGEST}}, {{.DIGEST_ALGO}} and {{.DIGEST_HEX}} are deprecated, image digest will now automatically be apppended to image tags"},
expectedWarnings: []string{"{{.DIGEST}}, {{.DIGEST_ALGO}} and {{.DIGEST_HEX}} are deprecated, image digest will now automatically be appended to image tags"},
},
{
name: "digest is deprecated",
template: "{{.IMAGE_NAME}}:{{.DIGEST}}",
imageName: "foo",
expected: "foo:[DEPRECATED_DIGEST]",
expectedWarnings: []string{"{{.DIGEST}}, {{.DIGEST_ALGO}} and {{.DIGEST_HEX}} are deprecated, image digest will now automatically be apppended to image tags"},
expected: "foo:_DEPRECATED_DIGEST_",
expectedWarnings: []string{"{{.DIGEST}}, {{.DIGEST_ALGO}} and {{.DIGEST_HEX}} are deprecated, image digest will now automatically be appended to image tags"},
},
{
name: "digest algo is deprecated",
template: "{{.IMAGE_NAME}}:{{.DIGEST_ALGO}}",
imageName: "foo",
expected: "foo:[DEPRECATED_DIGEST_ALGO]",
expectedWarnings: []string{"{{.DIGEST}}, {{.DIGEST_ALGO}} and {{.DIGEST_HEX}} are deprecated, image digest will now automatically be apppended to image tags"},
expected: "foo:_DEPRECATED_DIGEST_ALGO_",
expectedWarnings: []string{"{{.DIGEST}}, {{.DIGEST_ALGO}} and {{.DIGEST_HEX}} are deprecated, image digest will now automatically be appended to image tags"},
},
{
name: "digest hex is deprecated",
template: "{{.IMAGE_NAME}}:{{.DIGEST_HEX}}",
imageName: "foo",
expected: "foo:[DEPRECATED_DIGEST_HEX]",
expectedWarnings: []string{"{{.DIGEST}}, {{.DIGEST_ALGO}} and {{.DIGEST_HEX}} are deprecated, image digest will now automatically be apppended to image tags"},
expected: "foo:_DEPRECATED_DIGEST_HEX_",
expectedWarnings: []string{"{{.DIGEST}}, {{.DIGEST_ALGO}} and {{.DIGEST_HEX}} are deprecated, image digest will now automatically be appended to image tags"},
},
}
for _, test := range tests {
Expand Down

0 comments on commit 5cee689

Please sign in to comment.