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: Invalid image reference format when using digest strategy with helm charts #317

Merged
merged 3 commits into from
Dec 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
2 changes: 1 addition & 1 deletion pkg/argocd/argocd.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ func SetHelmImage(app *v1alpha1.Application, newImage *image.ContainerImage) err
mergeParams = append(mergeParams, p)
}
if hpImageTag != "" {
p := v1alpha1.HelmParameter{Name: hpImageTag, Value: newImage.ImageTag.String(), ForceString: true}
p := v1alpha1.HelmParameter{Name: hpImageTag, Value: newImage.GetTagWithDigest(), ForceString: true}
mergeParams = append(mergeParams, p)
}
}
Expand Down
18 changes: 18 additions & 0 deletions pkg/image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,24 @@ func (img *ContainerImage) GetFullNameWithTag() string {
return str
}

// GetTagWithDigest returns tag name along with any tag digest set for the image
func (img *ContainerImage) GetTagWithDigest() string {
str := ""
if img.ImageTag != nil {
if img.ImageTag.TagName != "" {
str += img.ImageTag.TagName
}
if img.ImageTag.TagDigest != "" {
if str == "" {
str += "latest"
}
str += "@"
str += img.ImageTag.TagDigest
}
}
return str
}

func (img *ContainerImage) Original() string {
return img.original
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/image/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,20 @@ func Test_ParseImageTags(t *testing.T) {
require.NotNil(t, image.ImageTag)
assert.Empty(t, image.ImageTag.TagName)
assert.Equal(t, "sha256:abcde", image.ImageTag.TagDigest)
assert.Equal(t, "latest@sha256:abcde", image.GetTagWithDigest())
assert.Equal(t, "gcr.io/jannfis/test-image@sha256:abcde", image.GetFullNameWithTag())
assert.Equal(t, "gcr.io/jannfis/test-image", image.GetFullNameWithoutTag())
})

t.Run("Parse valid image name with tag and digest", func(t *testing.T) {
image := NewFromIdentifier("gcr.io/jannfis/test-image:test-tag@sha256:abcde")
require.NotNil(t, image.ImageTag)
assert.Empty(t, image.ImageTag.TagName)
assert.Equal(t, "sha256:abcde", image.ImageTag.TagDigest)
assert.Equal(t, "latest@sha256:abcde", image.GetTagWithDigest())
assert.Equal(t, "gcr.io/jannfis/test-image:test-tag@sha256:abcde", image.GetFullNameWithTag())
})

t.Run("Parse valid image name with source name and registry info", func(t *testing.T) {
image := NewFromIdentifier("jannfis/orig-image=gcr.io/jannfis/test-image:0.1")
assert.Equal(t, "gcr.io", image.RegistryURL)
Expand Down