Skip to content

Commit

Permalink
Replace common constant references (#1011)
Browse files Browse the repository at this point in the history
Signed-off-by: Ishita Sequeira <[email protected]>
  • Loading branch information
ishitasequeira authored Jan 15, 2025
1 parent 10a01f3 commit 9affc21
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 96 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.22.0
toolchain go1.23.0

require (
github.com/argoproj-labs/argocd-image-updater/registry-scanner v0.0.0-20250110211602-b1555062f8fc
github.com/argoproj-labs/argocd-image-updater/registry-scanner v0.0.0-20250114144021-10a01f381aa7
github.com/argoproj/argo-cd/v2 v2.13.2
github.com/argoproj/gitops-engine v0.7.1-0.20240905010810-bd7681ae3f8b
github.com/argoproj/pkg v0.13.7-0.20230627120311-a4dd357b057e
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ github.com/alicebob/miniredis/v2 v2.33.0/go.mod h1:MhP4a3EU7aENRi9aO+tHfTBZicLqQ
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/argoproj-labs/argocd-image-updater/registry-scanner v0.0.0-20250110211602-b1555062f8fc h1:c5AQRytI+RfOIgkes7WAUKywY2A5s00HU7++SsjaIew=
github.com/argoproj-labs/argocd-image-updater/registry-scanner v0.0.0-20250110211602-b1555062f8fc/go.mod h1:gTR08JBkPgrrEJ06a5J6H97EWllbgCNs2nbDSPMKHDo=
github.com/argoproj-labs/argocd-image-updater/registry-scanner v0.0.0-20250114144021-10a01f381aa7 h1:5sujDhwNOHW3X3WMzfamC4e9H52z2LboabQ+WLvDQ14=
github.com/argoproj-labs/argocd-image-updater/registry-scanner v0.0.0-20250114144021-10a01f381aa7/go.mod h1:gTR08JBkPgrrEJ06a5J6H97EWllbgCNs2nbDSPMKHDo=
github.com/argoproj/argo-cd/v2 v2.13.2 h1:eLar0aAqz7AgJiYncRzkPkqEbIxiXl+pUzOuSi47tA0=
github.com/argoproj/argo-cd/v2 v2.13.2/go.mod h1:RC23V2744nhZstZVpLCWTQLT2gR0+IXGC3GTBCI6M+I=
github.com/argoproj/gitops-engine v0.7.1-0.20240905010810-bd7681ae3f8b h1:wOPWJ5MBScQO767WpU55oUJDXObfvPL0EfAYWxogbSw=
Expand Down
35 changes: 18 additions & 17 deletions pkg/argocd/argocd.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/argoproj-labs/argocd-image-updater/pkg/common"
"github.com/argoproj-labs/argocd-image-updater/pkg/kube"
"github.com/argoproj-labs/argocd-image-updater/pkg/metrics"
registryCommon "github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/common"
"github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/env"
"github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/image"
"github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/log"
Expand Down Expand Up @@ -232,7 +233,7 @@ func parseImageList(annotations map[string]string) *image.ContainerImageList {
splits := strings.Split(updateImage, ",")
for _, s := range splits {
img := image.NewFromIdentifier(strings.TrimSpace(s))
if kustomizeImage := img.GetParameterKustomizeImageName(annotations); kustomizeImage != "" {
if kustomizeImage := img.GetParameterKustomizeImageName(annotations, common.ImageUpdaterAnnotationPrefix); kustomizeImage != "" {
img.KustomizeImage = image.NewFromIdentifier(kustomizeImage)
}
results = append(results, img)
Expand Down Expand Up @@ -314,17 +315,17 @@ func getHelmParamNamesFromAnnotation(annotations map[string]string, img *image.C
var annotationName, helmParamName, helmParamVersion string

// Image spec is a full-qualified specifier, if we have it, we return early
if param := img.GetParameterHelmImageSpec(annotations); param != "" {
if param := img.GetParameterHelmImageSpec(annotations, common.ImageUpdaterAnnotationPrefix); param != "" {
log.Tracef("found annotation %s", annotationName)
return strings.TrimSpace(param), ""
}

if param := img.GetParameterHelmImageName(annotations); param != "" {
if param := img.GetParameterHelmImageName(annotations, common.ImageUpdaterAnnotationPrefix); param != "" {
log.Tracef("found annotation %s", annotationName)
helmParamName = param
}

if param := img.GetParameterHelmImageTag(annotations); param != "" {
if param := img.GetParameterHelmImageTag(annotations, common.ImageUpdaterAnnotationPrefix); param != "" {
log.Tracef("found annotation %s", annotationName)
helmParamVersion = param
}
Expand Down Expand Up @@ -384,16 +385,16 @@ func GetHelmImage(app *v1alpha1.Application, newImage *image.ContainerImage) (st

var hpImageName, hpImageTag, hpImageSpec string

hpImageSpec = newImage.GetParameterHelmImageSpec(app.Annotations)
hpImageName = newImage.GetParameterHelmImageName(app.Annotations)
hpImageTag = newImage.GetParameterHelmImageTag(app.Annotations)
hpImageSpec = newImage.GetParameterHelmImageSpec(app.Annotations, common.ImageUpdaterAnnotationPrefix)
hpImageName = newImage.GetParameterHelmImageName(app.Annotations, common.ImageUpdaterAnnotationPrefix)
hpImageTag = newImage.GetParameterHelmImageTag(app.Annotations, common.ImageUpdaterAnnotationPrefix)

if hpImageSpec == "" {
if hpImageName == "" {
hpImageName = common.DefaultHelmImageName
hpImageName = registryCommon.DefaultHelmImageName
}
if hpImageTag == "" {
hpImageTag = common.DefaultHelmImageTag
hpImageTag = registryCommon.DefaultHelmImageTag
}
}

Expand Down Expand Up @@ -434,16 +435,16 @@ func SetHelmImage(app *v1alpha1.Application, newImage *image.ContainerImage) err

var hpImageName, hpImageTag, hpImageSpec string

hpImageSpec = newImage.GetParameterHelmImageSpec(app.Annotations)
hpImageName = newImage.GetParameterHelmImageName(app.Annotations)
hpImageTag = newImage.GetParameterHelmImageTag(app.Annotations)
hpImageSpec = newImage.GetParameterHelmImageSpec(app.Annotations, common.ImageUpdaterAnnotationPrefix)
hpImageName = newImage.GetParameterHelmImageName(app.Annotations, common.ImageUpdaterAnnotationPrefix)
hpImageTag = newImage.GetParameterHelmImageTag(app.Annotations, common.ImageUpdaterAnnotationPrefix)

if hpImageSpec == "" {
if hpImageName == "" {
hpImageName = common.DefaultHelmImageName
hpImageName = registryCommon.DefaultHelmImageName
}
if hpImageTag == "" {
hpImageTag = common.DefaultHelmImageTag
hpImageTag = registryCommon.DefaultHelmImageTag
}
}

Expand Down Expand Up @@ -494,7 +495,7 @@ func GetKustomizeImage(app *v1alpha1.Application, newImage *image.ContainerImage
return "", fmt.Errorf("cannot set Kustomize image on non-Kustomize application")
}

ksImageName := newImage.GetParameterKustomizeImageName(app.Annotations)
ksImageName := newImage.GetParameterKustomizeImageName(app.Annotations, common.ImageUpdaterAnnotationPrefix)

appSource := getApplicationSource(app)

Expand Down Expand Up @@ -524,7 +525,7 @@ func SetKustomizeImage(app *v1alpha1.Application, newImage *image.ContainerImage
}

var ksImageParam string
ksImageName := newImage.GetParameterKustomizeImageName(app.Annotations)
ksImageName := newImage.GetParameterKustomizeImageName(app.Annotations, common.ImageUpdaterAnnotationPrefix)
if ksImageName != "" {
ksImageParam = fmt.Sprintf("%s=%s", ksImageName, newImage.GetFullNameWithTag())
} else {
Expand Down Expand Up @@ -568,7 +569,7 @@ func GetImagesFromApplication(app *v1alpha1.Application) image.ContainerImageLis
// Check the image list for images with a force-update annotation, and add them if they are not already present.
annotations := app.Annotations
for _, img := range *parseImageList(annotations) {
if img.HasForceUpdateOptionAnnotation(annotations) {
if img.HasForceUpdateOptionAnnotation(annotations, common.ImageUpdaterAnnotationPrefix) {
img.ImageTag = nil // the tag from the image list will be a version constraint, which isn't a valid tag
images = append(images, img)
}
Expand Down
45 changes: 23 additions & 22 deletions pkg/argocd/argocd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/argoproj-labs/argocd-image-updater/pkg/common"
"github.com/argoproj-labs/argocd-image-updater/pkg/kube"

registryCommon "github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/common"
"github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/image"
registryKube "github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/kube"

Expand Down Expand Up @@ -66,8 +67,8 @@ func Test_GetImagesFromApplication(t *testing.T) {
Name: "test-app",
Namespace: "argocd",
Annotations: map[string]string{
fmt.Sprintf(common.ForceUpdateOptionAnnotation, "nginx"): "true",
common.ImageUpdaterAnnotation: "nginx=nginx",
fmt.Sprintf(registryCommon.Prefixed(common.ImageUpdaterAnnotationPrefix, registryCommon.ForceUpdateOptionAnnotationSuffix), "nginx"): "true",
common.ImageUpdaterAnnotation: "nginx=nginx",
},
},
Spec: v1alpha1.ApplicationSpec{},
Expand Down Expand Up @@ -558,8 +559,8 @@ func Test_FilterApplicationsForUpdate(t *testing.T) {
func Test_GetHelmParamAnnotations(t *testing.T) {
t.Run("Get parameter names without symbolic names", func(t *testing.T) {
annotations := map[string]string{
fmt.Sprintf(common.HelmParamImageSpecAnnotation, "myimg"): "image.blub",
fmt.Sprintf(common.HelmParamImageTagAnnotation, "myimg"): "image.blab",
fmt.Sprintf(registryCommon.Prefixed(common.ImageUpdaterAnnotationPrefix, registryCommon.HelmParamImageSpecAnnotationSuffix), "myimg"): "image.blub",
fmt.Sprintf(registryCommon.Prefixed(common.ImageUpdaterAnnotationPrefix, registryCommon.HelmParamImageTagAnnotationSuffix), "myimg"): "image.blab",
}
name, tag := getHelmParamNamesFromAnnotation(annotations, &image.ContainerImage{
ImageAlias: "",
Expand All @@ -570,8 +571,8 @@ func Test_GetHelmParamAnnotations(t *testing.T) {

t.Run("Find existing image spec annotation", func(t *testing.T) {
annotations := map[string]string{
fmt.Sprintf(common.HelmParamImageSpecAnnotation, "myimg"): "image.path",
fmt.Sprintf(common.HelmParamImageTagAnnotation, "myimg"): "image.tag",
fmt.Sprintf(registryCommon.Prefixed(common.ImageUpdaterAnnotationPrefix, registryCommon.HelmParamImageSpecAnnotationSuffix), "myimg"): "image.path",
fmt.Sprintf(registryCommon.Prefixed(common.ImageUpdaterAnnotationPrefix, registryCommon.HelmParamImageTagAnnotationSuffix), "myimg"): "image.tag",
}
name, tag := getHelmParamNamesFromAnnotation(annotations, &image.ContainerImage{
ImageAlias: "myimg",
Expand All @@ -582,8 +583,8 @@ func Test_GetHelmParamAnnotations(t *testing.T) {

t.Run("Find existing image name and image tag annotations", func(t *testing.T) {
annotations := map[string]string{
fmt.Sprintf(common.HelmParamImageNameAnnotation, "myimg"): "image.name",
fmt.Sprintf(common.HelmParamImageTagAnnotation, "myimg"): "image.tag",
fmt.Sprintf(registryCommon.Prefixed(common.ImageUpdaterAnnotationPrefix, registryCommon.HelmParamImageNameAnnotationSuffix), "myimg"): "image.name",
fmt.Sprintf(registryCommon.Prefixed(common.ImageUpdaterAnnotationPrefix, registryCommon.HelmParamImageTagAnnotationSuffix), "myimg"): "image.tag",
}
name, tag := getHelmParamNamesFromAnnotation(annotations, &image.ContainerImage{
ImageAlias: "myimg",
Expand All @@ -594,8 +595,8 @@ func Test_GetHelmParamAnnotations(t *testing.T) {

t.Run("Find non-existing image name and image tag annotations", func(t *testing.T) {
annotations := map[string]string{
fmt.Sprintf(common.HelmParamImageNameAnnotation, "otherimg"): "image.name",
fmt.Sprintf(common.HelmParamImageTagAnnotation, "otherimg"): "image.tag",
fmt.Sprintf(registryCommon.Prefixed(common.ImageUpdaterAnnotationPrefix, registryCommon.HelmParamImageNameAnnotationSuffix), "otherimg"): "image.name",
fmt.Sprintf(registryCommon.Prefixed(common.ImageUpdaterAnnotationPrefix, registryCommon.HelmParamImageTagAnnotationSuffix), "otherimg"): "image.tag",
}
name, tag := getHelmParamNamesFromAnnotation(annotations, &image.ContainerImage{
ImageAlias: "myimg",
Expand All @@ -606,7 +607,7 @@ func Test_GetHelmParamAnnotations(t *testing.T) {

t.Run("Find existing image tag annotations", func(t *testing.T) {
annotations := map[string]string{
fmt.Sprintf(common.HelmParamImageTagAnnotation, "myimg"): "image.tag",
fmt.Sprintf(registryCommon.Prefixed(common.ImageUpdaterAnnotationPrefix, registryCommon.HelmParamImageTagAnnotationSuffix), "myimg"): "image.tag",
}
name, tag := getHelmParamNamesFromAnnotation(annotations, &image.ContainerImage{
ImageAlias: "myimg",
Expand Down Expand Up @@ -795,7 +796,7 @@ func Test_SetKustomizeImage(t *testing.T) {
Name: "test-app",
Namespace: "testns",
Annotations: map[string]string{
fmt.Sprintf(common.KustomizeApplicationNameAnnotation, "foobar"): "foobar",
fmt.Sprintf(registryCommon.Prefixed(common.ImageUpdaterAnnotationPrefix, registryCommon.KustomizeApplicationNameAnnotationSuffix), "foobar"): "foobar",
},
},
Spec: v1alpha1.ApplicationSpec{
Expand Down Expand Up @@ -833,8 +834,8 @@ func Test_SetHelmImage(t *testing.T) {
Name: "test-app",
Namespace: "testns",
Annotations: map[string]string{
fmt.Sprintf(common.HelmParamImageNameAnnotation, "foobar"): "image.name",
fmt.Sprintf(common.HelmParamImageTagAnnotation, "foobar"): "image.tag",
fmt.Sprintf(registryCommon.Prefixed(common.ImageUpdaterAnnotationPrefix, registryCommon.HelmParamImageNameAnnotationSuffix), "foobar"): "image.name",
fmt.Sprintf(registryCommon.Prefixed(common.ImageUpdaterAnnotationPrefix, registryCommon.HelmParamImageTagAnnotationSuffix), "foobar"): "image.tag",
},
},
Spec: v1alpha1.ApplicationSpec{
Expand Down Expand Up @@ -887,8 +888,8 @@ func Test_SetHelmImage(t *testing.T) {
Name: "test-app",
Namespace: "testns",
Annotations: map[string]string{
fmt.Sprintf(common.HelmParamImageNameAnnotation, "foobar"): "image.name",
fmt.Sprintf(common.HelmParamImageTagAnnotation, "foobar"): "image.tag",
fmt.Sprintf(registryCommon.Prefixed(common.ImageUpdaterAnnotationPrefix, registryCommon.HelmParamImageNameAnnotationSuffix), "foobar"): "image.name",
fmt.Sprintf(registryCommon.Prefixed(common.ImageUpdaterAnnotationPrefix, registryCommon.HelmParamImageTagAnnotationSuffix), "foobar"): "image.tag",
},
},
Spec: v1alpha1.ApplicationSpec{
Expand Down Expand Up @@ -930,8 +931,8 @@ func Test_SetHelmImage(t *testing.T) {
Name: "test-app",
Namespace: "testns",
Annotations: map[string]string{
fmt.Sprintf(common.HelmParamImageNameAnnotation, "foobar"): "foobar.image.name",
fmt.Sprintf(common.HelmParamImageTagAnnotation, "foobar"): "foobar.image.tag",
fmt.Sprintf(registryCommon.Prefixed(common.ImageUpdaterAnnotationPrefix, registryCommon.HelmParamImageNameAnnotationSuffix), "foobar"): "foobar.image.name",
fmt.Sprintf(registryCommon.Prefixed(common.ImageUpdaterAnnotationPrefix, registryCommon.HelmParamImageTagAnnotationSuffix), "foobar"): "foobar.image.tag",
},
},
Spec: v1alpha1.ApplicationSpec{
Expand Down Expand Up @@ -984,8 +985,8 @@ func Test_SetHelmImage(t *testing.T) {
Name: "test-app",
Namespace: "testns",
Annotations: map[string]string{
fmt.Sprintf(common.HelmParamImageNameAnnotation, "foobar"): "foobar.image.name",
fmt.Sprintf(common.HelmParamImageTagAnnotation, "foobar"): "foobar.image.tag",
fmt.Sprintf(registryCommon.Prefixed(common.ImageUpdaterAnnotationPrefix, registryCommon.HelmParamImageNameAnnotationSuffix), "foobar"): "foobar.image.name",
fmt.Sprintf(registryCommon.Prefixed(common.ImageUpdaterAnnotationPrefix, registryCommon.HelmParamImageTagAnnotationSuffix), "foobar"): "foobar.image.tag",
},
},
Spec: v1alpha1.ApplicationSpec{
Expand Down Expand Up @@ -1227,8 +1228,8 @@ func Test_parseImageList(t *testing.T) {
})
t.Run("Test kustomize override", func(t *testing.T) {
imgs := *parseImageList(map[string]string{
common.ImageUpdaterAnnotation: "foo=bar",
fmt.Sprintf(common.KustomizeApplicationNameAnnotation, "foo"): "baz",
common.ImageUpdaterAnnotation: "foo=bar",
fmt.Sprintf(registryCommon.Prefixed(common.ImageUpdaterAnnotationPrefix, registryCommon.KustomizeApplicationNameAnnotationSuffix), "foo"): "baz",
})
assert.Equal(t, "bar", imgs[0].ImageName)
assert.Equal(t, "baz", imgs[0].KustomizeImage.ImageName)
Expand Down
12 changes: 6 additions & 6 deletions pkg/argocd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,11 @@ func UpdateApplication(updateConf *UpdateConfiguration, state *SyncIterationStat
imgCtx.Debugf("Using no version constraint when looking for a new tag")
}

vc.Strategy = applicationImage.GetParameterUpdateStrategy(updateConf.UpdateApp.Application.Annotations)
vc.MatchFunc, vc.MatchArgs = applicationImage.GetParameterMatch(updateConf.UpdateApp.Application.Annotations)
vc.IgnoreList = applicationImage.GetParameterIgnoreTags(updateConf.UpdateApp.Application.Annotations)
vc.Strategy = applicationImage.GetParameterUpdateStrategy(updateConf.UpdateApp.Application.Annotations, common.ImageUpdaterAnnotationPrefix)
vc.MatchFunc, vc.MatchArgs = applicationImage.GetParameterMatch(updateConf.UpdateApp.Application.Annotations, common.ImageUpdaterAnnotationPrefix)
vc.IgnoreList = applicationImage.GetParameterIgnoreTags(updateConf.UpdateApp.Application.Annotations, common.ImageUpdaterAnnotationPrefix)
vc.Options = applicationImage.
GetPlatformOptions(updateConf.UpdateApp.Application.Annotations, updateConf.IgnorePlatforms).
GetPlatformOptions(updateConf.UpdateApp.Application.Annotations, updateConf.IgnorePlatforms, common.ImageUpdaterAnnotationPrefix).
WithMetadata(vc.Strategy.NeedsMetadata()).
WithLogger(imgCtx.AddField("application", app))

Expand All @@ -228,7 +228,7 @@ func UpdateApplication(updateConf *UpdateConfiguration, state *SyncIterationStat
continue
}

imgCredSrc := applicationImage.GetParameterPullSecret(updateConf.UpdateApp.Application.Annotations)
imgCredSrc := applicationImage.GetParameterPullSecret(updateConf.UpdateApp.Application.Annotations, common.ImageUpdaterAnnotationPrefix)
var creds *image.Credential = &image.Credential{}
if imgCredSrc != nil {
creds, err = imgCredSrc.FetchCredentials(rep.RegistryAPI, updateConf.KubeClient.KubeClient)
Expand Down Expand Up @@ -478,7 +478,7 @@ func marshalParamsOverride(app *v1alpha1.Application, originalData []byte) ([]by
// for image-spec annotation, helmAnnotationParamName holds image-spec annotation value,
// and helmAnnotationParamVersion is empty
if helmAnnotationParamVersion == "" {
if c.GetParameterHelmImageSpec(app.Annotations) == "" {
if c.GetParameterHelmImageSpec(app.Annotations, common.ImageUpdaterAnnotationPrefix) == "" {
// not a full image-spec, so image-tag is required
return nil, fmt.Errorf("could not find an image-tag annotation for image %s", c.ImageName)
}
Expand Down
Loading

0 comments on commit 9affc21

Please sign in to comment.