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

feature: Allow image tags to be used in place of digest (PROJQUAY-1890) #436

Merged
merged 1 commit into from
Apr 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions pkg/kustomize/kustomize.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
jonathankingfc marked this conversation as resolved.
Show resolved Hide resolved
} else {
jonathankingfc marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down Expand Up @@ -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))
}
}
}
Expand Down
39 changes: 38 additions & 1 deletion pkg/kustomize/kustomize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}
}
}

Expand Down