diff --git a/pkg/kustomize/kustomize.go b/pkg/kustomize/kustomize.go index 8780a33fe..e154ecbd0 100644 --- a/pkg/kustomize/kustomize.go +++ b/pkg/kustomize/kustomize.go @@ -70,12 +70,15 @@ func componentImageFor(component v1.ComponentKind) types.Image { } image := os.Getenv(envVarFor[component]) if image != "" { - if len(strings.Split(image, "@")) != 2 { - panic(envVarFor[component] + " must use manifest digest reference") + if len(strings.Split(image, "@")) == 2 { + imageOverride.NewName = strings.Split(image, "@")[0] + imageOverride.Digest = strings.Split(image, "@")[1] + } else if len(strings.Split(image, ":")) == 2 { + imageOverride.NewName = strings.Split(image, ":")[0] + imageOverride.NewTag = strings.Split(image, ":")[1] + } else { + panic("image override must be reference by tag or manifest digest: " + image) } - - imageOverride.NewName = strings.Split(image, "@")[0] - imageOverride.Digest = strings.Split(image, "@")[1] } return imageOverride @@ -315,9 +318,8 @@ func KustomizationFor(ctx *quaycontext.QuayRegistryContext, quay *v1.QuayRegistr images := []types.Image{} for _, component := range append(quay.Spec.Components, v1.Component{Kind: "base", Managed: true}) { if component.Managed { - imageOverride := componentImageFor(component.Kind) - if imageOverride.Digest != "" { - images = append(images, imageOverride) + if image := componentImageFor(component.Kind); image.NewName != "" || image.Digest != "" { + images = append(images, componentImageFor(component.Kind)) } } } diff --git a/pkg/kustomize/kustomize_test.go b/pkg/kustomize/kustomize_test.go index e2acc3ca3..87e31368a 100644 --- a/pkg/kustomize/kustomize_test.go +++ b/pkg/kustomize/kustomize_test.go @@ -99,6 +99,39 @@ var kustomizationForTests = []struct { }, "", }, + { + "ComponentImageOverridesWithTag", + &v1.QuayRegistry{ + Spec: v1.QuayRegistrySpec{ + Components: []v1.Component{ + {Kind: "postgres", Managed: true}, + {Kind: "clair", Managed: true}, + {Kind: "redis", Managed: true}, + }, + }, + }, + quaycontext.QuayRegistryContext{}, + &types.Kustomization{ + TypeMeta: types.TypeMeta{ + APIVersion: types.KustomizationVersion, + Kind: types.KustomizationKind, + }, + Resources: []string{}, + Components: []string{ + "../components/postgres", + "../components/clair", + "../components/redis", + }, + Images: []types.Image{ + {Name: "quay.io/projectquay/quay", NewName: "quay", NewTag: "latest"}, + {Name: "quay.io/projectquay/clair", NewName: "clair", NewTag: "alpine"}, + {Name: "centos/redis-32-centos7", NewName: "redis", NewTag: "buster"}, + {Name: "centos/postgresql-10-centos7", NewName: "postgres", NewTag: "latest"}, + }, + SecretGenerator: []types.SecretArgs{}, + }, + "", + }, } func TestKustomizationFor(t *testing.T) { @@ -107,7 +140,11 @@ func TestKustomizationFor(t *testing.T) { for _, test := range kustomizationForTests { if test.expected != nil { for _, img := range test.expected.Images { - os.Setenv("RELATED_IMAGE_COMPONENT_"+strings.ToUpper(img.NewName), img.NewName+"@"+img.Digest) + if len(img.Digest) != 0 { + os.Setenv("RELATED_IMAGE_COMPONENT_"+strings.ToUpper(img.NewName), img.NewName+"@"+img.Digest) + } else { + os.Setenv("RELATED_IMAGE_COMPONENT_"+strings.ToUpper(img.NewName), img.NewName+":"+img.NewTag) + } } }