diff --git a/pkg/argocd/argocd.go b/pkg/argocd/argocd.go index 16fde535..4183c0c7 100644 --- a/pkg/argocd/argocd.go +++ b/pkg/argocd/argocd.go @@ -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) } } diff --git a/pkg/image/image.go b/pkg/image/image.go index 4dcae8ea..24c19f6a 100644 --- a/pkg/image/image.go +++ b/pkg/image/image.go @@ -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 } diff --git a/pkg/image/image_test.go b/pkg/image/image_test.go index 4ffc3688..5d1abbdf 100644 --- a/pkg/image/image_test.go +++ b/pkg/image/image_test.go @@ -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)