Skip to content

Commit 9affc21

Browse files
Replace common constant references (#1011)
Signed-off-by: Ishita Sequeira <[email protected]>
1 parent 10a01f3 commit 9affc21

File tree

7 files changed

+60
-96
lines changed

7 files changed

+60
-96
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.22.0
55
toolchain go1.23.0
66

77
require (
8-
github.com/argoproj-labs/argocd-image-updater/registry-scanner v0.0.0-20250110211602-b1555062f8fc
8+
github.com/argoproj-labs/argocd-image-updater/registry-scanner v0.0.0-20250114144021-10a01f381aa7
99
github.com/argoproj/argo-cd/v2 v2.13.2
1010
github.com/argoproj/gitops-engine v0.7.1-0.20240905010810-bd7681ae3f8b
1111
github.com/argoproj/pkg v0.13.7-0.20230627120311-a4dd357b057e

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ github.com/alicebob/miniredis/v2 v2.33.0/go.mod h1:MhP4a3EU7aENRi9aO+tHfTBZicLqQ
2727
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=
2828
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4=
2929
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
30-
github.com/argoproj-labs/argocd-image-updater/registry-scanner v0.0.0-20250110211602-b1555062f8fc h1:c5AQRytI+RfOIgkes7WAUKywY2A5s00HU7++SsjaIew=
31-
github.com/argoproj-labs/argocd-image-updater/registry-scanner v0.0.0-20250110211602-b1555062f8fc/go.mod h1:gTR08JBkPgrrEJ06a5J6H97EWllbgCNs2nbDSPMKHDo=
30+
github.com/argoproj-labs/argocd-image-updater/registry-scanner v0.0.0-20250114144021-10a01f381aa7 h1:5sujDhwNOHW3X3WMzfamC4e9H52z2LboabQ+WLvDQ14=
31+
github.com/argoproj-labs/argocd-image-updater/registry-scanner v0.0.0-20250114144021-10a01f381aa7/go.mod h1:gTR08JBkPgrrEJ06a5J6H97EWllbgCNs2nbDSPMKHDo=
3232
github.com/argoproj/argo-cd/v2 v2.13.2 h1:eLar0aAqz7AgJiYncRzkPkqEbIxiXl+pUzOuSi47tA0=
3333
github.com/argoproj/argo-cd/v2 v2.13.2/go.mod h1:RC23V2744nhZstZVpLCWTQLT2gR0+IXGC3GTBCI6M+I=
3434
github.com/argoproj/gitops-engine v0.7.1-0.20240905010810-bd7681ae3f8b h1:wOPWJ5MBScQO767WpU55oUJDXObfvPL0EfAYWxogbSw=

pkg/argocd/argocd.go

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/argoproj-labs/argocd-image-updater/pkg/common"
1212
"github.com/argoproj-labs/argocd-image-updater/pkg/kube"
1313
"github.com/argoproj-labs/argocd-image-updater/pkg/metrics"
14+
registryCommon "github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/common"
1415
"github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/env"
1516
"github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/image"
1617
"github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/log"
@@ -232,7 +233,7 @@ func parseImageList(annotations map[string]string) *image.ContainerImageList {
232233
splits := strings.Split(updateImage, ",")
233234
for _, s := range splits {
234235
img := image.NewFromIdentifier(strings.TrimSpace(s))
235-
if kustomizeImage := img.GetParameterKustomizeImageName(annotations); kustomizeImage != "" {
236+
if kustomizeImage := img.GetParameterKustomizeImageName(annotations, common.ImageUpdaterAnnotationPrefix); kustomizeImage != "" {
236237
img.KustomizeImage = image.NewFromIdentifier(kustomizeImage)
237238
}
238239
results = append(results, img)
@@ -314,17 +315,17 @@ func getHelmParamNamesFromAnnotation(annotations map[string]string, img *image.C
314315
var annotationName, helmParamName, helmParamVersion string
315316

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

322-
if param := img.GetParameterHelmImageName(annotations); param != "" {
323+
if param := img.GetParameterHelmImageName(annotations, common.ImageUpdaterAnnotationPrefix); param != "" {
323324
log.Tracef("found annotation %s", annotationName)
324325
helmParamName = param
325326
}
326327

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

385386
var hpImageName, hpImageTag, hpImageSpec string
386387

387-
hpImageSpec = newImage.GetParameterHelmImageSpec(app.Annotations)
388-
hpImageName = newImage.GetParameterHelmImageName(app.Annotations)
389-
hpImageTag = newImage.GetParameterHelmImageTag(app.Annotations)
388+
hpImageSpec = newImage.GetParameterHelmImageSpec(app.Annotations, common.ImageUpdaterAnnotationPrefix)
389+
hpImageName = newImage.GetParameterHelmImageName(app.Annotations, common.ImageUpdaterAnnotationPrefix)
390+
hpImageTag = newImage.GetParameterHelmImageTag(app.Annotations, common.ImageUpdaterAnnotationPrefix)
390391

391392
if hpImageSpec == "" {
392393
if hpImageName == "" {
393-
hpImageName = common.DefaultHelmImageName
394+
hpImageName = registryCommon.DefaultHelmImageName
394395
}
395396
if hpImageTag == "" {
396-
hpImageTag = common.DefaultHelmImageTag
397+
hpImageTag = registryCommon.DefaultHelmImageTag
397398
}
398399
}
399400

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

435436
var hpImageName, hpImageTag, hpImageSpec string
436437

437-
hpImageSpec = newImage.GetParameterHelmImageSpec(app.Annotations)
438-
hpImageName = newImage.GetParameterHelmImageName(app.Annotations)
439-
hpImageTag = newImage.GetParameterHelmImageTag(app.Annotations)
438+
hpImageSpec = newImage.GetParameterHelmImageSpec(app.Annotations, common.ImageUpdaterAnnotationPrefix)
439+
hpImageName = newImage.GetParameterHelmImageName(app.Annotations, common.ImageUpdaterAnnotationPrefix)
440+
hpImageTag = newImage.GetParameterHelmImageTag(app.Annotations, common.ImageUpdaterAnnotationPrefix)
440441

441442
if hpImageSpec == "" {
442443
if hpImageName == "" {
443-
hpImageName = common.DefaultHelmImageName
444+
hpImageName = registryCommon.DefaultHelmImageName
444445
}
445446
if hpImageTag == "" {
446-
hpImageTag = common.DefaultHelmImageTag
447+
hpImageTag = registryCommon.DefaultHelmImageTag
447448
}
448449
}
449450

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

497-
ksImageName := newImage.GetParameterKustomizeImageName(app.Annotations)
498+
ksImageName := newImage.GetParameterKustomizeImageName(app.Annotations, common.ImageUpdaterAnnotationPrefix)
498499

499500
appSource := getApplicationSource(app)
500501

@@ -524,7 +525,7 @@ func SetKustomizeImage(app *v1alpha1.Application, newImage *image.ContainerImage
524525
}
525526

526527
var ksImageParam string
527-
ksImageName := newImage.GetParameterKustomizeImageName(app.Annotations)
528+
ksImageName := newImage.GetParameterKustomizeImageName(app.Annotations, common.ImageUpdaterAnnotationPrefix)
528529
if ksImageName != "" {
529530
ksImageParam = fmt.Sprintf("%s=%s", ksImageName, newImage.GetFullNameWithTag())
530531
} else {
@@ -568,7 +569,7 @@ func GetImagesFromApplication(app *v1alpha1.Application) image.ContainerImageLis
568569
// Check the image list for images with a force-update annotation, and add them if they are not already present.
569570
annotations := app.Annotations
570571
for _, img := range *parseImageList(annotations) {
571-
if img.HasForceUpdateOptionAnnotation(annotations) {
572+
if img.HasForceUpdateOptionAnnotation(annotations, common.ImageUpdaterAnnotationPrefix) {
572573
img.ImageTag = nil // the tag from the image list will be a version constraint, which isn't a valid tag
573574
images = append(images, img)
574575
}

pkg/argocd/argocd_test.go

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/argoproj-labs/argocd-image-updater/pkg/common"
1010
"github.com/argoproj-labs/argocd-image-updater/pkg/kube"
1111

12+
registryCommon "github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/common"
1213
"github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/image"
1314
registryKube "github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/kube"
1415

@@ -66,8 +67,8 @@ func Test_GetImagesFromApplication(t *testing.T) {
6667
Name: "test-app",
6768
Namespace: "argocd",
6869
Annotations: map[string]string{
69-
fmt.Sprintf(common.ForceUpdateOptionAnnotation, "nginx"): "true",
70-
common.ImageUpdaterAnnotation: "nginx=nginx",
70+
fmt.Sprintf(registryCommon.Prefixed(common.ImageUpdaterAnnotationPrefix, registryCommon.ForceUpdateOptionAnnotationSuffix), "nginx"): "true",
71+
common.ImageUpdaterAnnotation: "nginx=nginx",
7172
},
7273
},
7374
Spec: v1alpha1.ApplicationSpec{},
@@ -558,8 +559,8 @@ func Test_FilterApplicationsForUpdate(t *testing.T) {
558559
func Test_GetHelmParamAnnotations(t *testing.T) {
559560
t.Run("Get parameter names without symbolic names", func(t *testing.T) {
560561
annotations := map[string]string{
561-
fmt.Sprintf(common.HelmParamImageSpecAnnotation, "myimg"): "image.blub",
562-
fmt.Sprintf(common.HelmParamImageTagAnnotation, "myimg"): "image.blab",
562+
fmt.Sprintf(registryCommon.Prefixed(common.ImageUpdaterAnnotationPrefix, registryCommon.HelmParamImageSpecAnnotationSuffix), "myimg"): "image.blub",
563+
fmt.Sprintf(registryCommon.Prefixed(common.ImageUpdaterAnnotationPrefix, registryCommon.HelmParamImageTagAnnotationSuffix), "myimg"): "image.blab",
563564
}
564565
name, tag := getHelmParamNamesFromAnnotation(annotations, &image.ContainerImage{
565566
ImageAlias: "",
@@ -570,8 +571,8 @@ func Test_GetHelmParamAnnotations(t *testing.T) {
570571

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

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

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

607608
t.Run("Find existing image tag annotations", func(t *testing.T) {
608609
annotations := map[string]string{
609-
fmt.Sprintf(common.HelmParamImageTagAnnotation, "myimg"): "image.tag",
610+
fmt.Sprintf(registryCommon.Prefixed(common.ImageUpdaterAnnotationPrefix, registryCommon.HelmParamImageTagAnnotationSuffix), "myimg"): "image.tag",
610611
}
611612
name, tag := getHelmParamNamesFromAnnotation(annotations, &image.ContainerImage{
612613
ImageAlias: "myimg",
@@ -795,7 +796,7 @@ func Test_SetKustomizeImage(t *testing.T) {
795796
Name: "test-app",
796797
Namespace: "testns",
797798
Annotations: map[string]string{
798-
fmt.Sprintf(common.KustomizeApplicationNameAnnotation, "foobar"): "foobar",
799+
fmt.Sprintf(registryCommon.Prefixed(common.ImageUpdaterAnnotationPrefix, registryCommon.KustomizeApplicationNameAnnotationSuffix), "foobar"): "foobar",
799800
},
800801
},
801802
Spec: v1alpha1.ApplicationSpec{
@@ -833,8 +834,8 @@ func Test_SetHelmImage(t *testing.T) {
833834
Name: "test-app",
834835
Namespace: "testns",
835836
Annotations: map[string]string{
836-
fmt.Sprintf(common.HelmParamImageNameAnnotation, "foobar"): "image.name",
837-
fmt.Sprintf(common.HelmParamImageTagAnnotation, "foobar"): "image.tag",
837+
fmt.Sprintf(registryCommon.Prefixed(common.ImageUpdaterAnnotationPrefix, registryCommon.HelmParamImageNameAnnotationSuffix), "foobar"): "image.name",
838+
fmt.Sprintf(registryCommon.Prefixed(common.ImageUpdaterAnnotationPrefix, registryCommon.HelmParamImageTagAnnotationSuffix), "foobar"): "image.tag",
838839
},
839840
},
840841
Spec: v1alpha1.ApplicationSpec{
@@ -887,8 +888,8 @@ func Test_SetHelmImage(t *testing.T) {
887888
Name: "test-app",
888889
Namespace: "testns",
889890
Annotations: map[string]string{
890-
fmt.Sprintf(common.HelmParamImageNameAnnotation, "foobar"): "image.name",
891-
fmt.Sprintf(common.HelmParamImageTagAnnotation, "foobar"): "image.tag",
891+
fmt.Sprintf(registryCommon.Prefixed(common.ImageUpdaterAnnotationPrefix, registryCommon.HelmParamImageNameAnnotationSuffix), "foobar"): "image.name",
892+
fmt.Sprintf(registryCommon.Prefixed(common.ImageUpdaterAnnotationPrefix, registryCommon.HelmParamImageTagAnnotationSuffix), "foobar"): "image.tag",
892893
},
893894
},
894895
Spec: v1alpha1.ApplicationSpec{
@@ -930,8 +931,8 @@ func Test_SetHelmImage(t *testing.T) {
930931
Name: "test-app",
931932
Namespace: "testns",
932933
Annotations: map[string]string{
933-
fmt.Sprintf(common.HelmParamImageNameAnnotation, "foobar"): "foobar.image.name",
934-
fmt.Sprintf(common.HelmParamImageTagAnnotation, "foobar"): "foobar.image.tag",
934+
fmt.Sprintf(registryCommon.Prefixed(common.ImageUpdaterAnnotationPrefix, registryCommon.HelmParamImageNameAnnotationSuffix), "foobar"): "foobar.image.name",
935+
fmt.Sprintf(registryCommon.Prefixed(common.ImageUpdaterAnnotationPrefix, registryCommon.HelmParamImageTagAnnotationSuffix), "foobar"): "foobar.image.tag",
935936
},
936937
},
937938
Spec: v1alpha1.ApplicationSpec{
@@ -984,8 +985,8 @@ func Test_SetHelmImage(t *testing.T) {
984985
Name: "test-app",
985986
Namespace: "testns",
986987
Annotations: map[string]string{
987-
fmt.Sprintf(common.HelmParamImageNameAnnotation, "foobar"): "foobar.image.name",
988-
fmt.Sprintf(common.HelmParamImageTagAnnotation, "foobar"): "foobar.image.tag",
988+
fmt.Sprintf(registryCommon.Prefixed(common.ImageUpdaterAnnotationPrefix, registryCommon.HelmParamImageNameAnnotationSuffix), "foobar"): "foobar.image.name",
989+
fmt.Sprintf(registryCommon.Prefixed(common.ImageUpdaterAnnotationPrefix, registryCommon.HelmParamImageTagAnnotationSuffix), "foobar"): "foobar.image.tag",
989990
},
990991
},
991992
Spec: v1alpha1.ApplicationSpec{
@@ -1227,8 +1228,8 @@ func Test_parseImageList(t *testing.T) {
12271228
})
12281229
t.Run("Test kustomize override", func(t *testing.T) {
12291230
imgs := *parseImageList(map[string]string{
1230-
common.ImageUpdaterAnnotation: "foo=bar",
1231-
fmt.Sprintf(common.KustomizeApplicationNameAnnotation, "foo"): "baz",
1231+
common.ImageUpdaterAnnotation: "foo=bar",
1232+
fmt.Sprintf(registryCommon.Prefixed(common.ImageUpdaterAnnotationPrefix, registryCommon.KustomizeApplicationNameAnnotationSuffix), "foo"): "baz",
12321233
})
12331234
assert.Equal(t, "bar", imgs[0].ImageName)
12341235
assert.Equal(t, "baz", imgs[0].KustomizeImage.ImageName)

pkg/argocd/update.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,11 @@ func UpdateApplication(updateConf *UpdateConfiguration, state *SyncIterationStat
206206
imgCtx.Debugf("Using no version constraint when looking for a new tag")
207207
}
208208

209-
vc.Strategy = applicationImage.GetParameterUpdateStrategy(updateConf.UpdateApp.Application.Annotations)
210-
vc.MatchFunc, vc.MatchArgs = applicationImage.GetParameterMatch(updateConf.UpdateApp.Application.Annotations)
211-
vc.IgnoreList = applicationImage.GetParameterIgnoreTags(updateConf.UpdateApp.Application.Annotations)
209+
vc.Strategy = applicationImage.GetParameterUpdateStrategy(updateConf.UpdateApp.Application.Annotations, common.ImageUpdaterAnnotationPrefix)
210+
vc.MatchFunc, vc.MatchArgs = applicationImage.GetParameterMatch(updateConf.UpdateApp.Application.Annotations, common.ImageUpdaterAnnotationPrefix)
211+
vc.IgnoreList = applicationImage.GetParameterIgnoreTags(updateConf.UpdateApp.Application.Annotations, common.ImageUpdaterAnnotationPrefix)
212212
vc.Options = applicationImage.
213-
GetPlatformOptions(updateConf.UpdateApp.Application.Annotations, updateConf.IgnorePlatforms).
213+
GetPlatformOptions(updateConf.UpdateApp.Application.Annotations, updateConf.IgnorePlatforms, common.ImageUpdaterAnnotationPrefix).
214214
WithMetadata(vc.Strategy.NeedsMetadata()).
215215
WithLogger(imgCtx.AddField("application", app))
216216

@@ -228,7 +228,7 @@ func UpdateApplication(updateConf *UpdateConfiguration, state *SyncIterationStat
228228
continue
229229
}
230230

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

0 commit comments

Comments
 (0)