Skip to content

Commit 10a01f3

Browse files
chore: separate Argo specific constants from registry-scanner constants (#1010)
Signed-off-by: Ishita Sequeira <[email protected]>
1 parent 154f51a commit 10a01f3

File tree

8 files changed

+143
-157
lines changed

8 files changed

+143
-157
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-20250110160036-ae473dd84031
8+
github.com/argoproj-labs/argocd-image-updater/registry-scanner v0.0.0-20250110211602-b1555062f8fc
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-20250110160036-ae473dd84031 h1:GqT66PDjz8J8vgG+bQ4UnFgpg16PrcO8lrLL+NlU8pI=
31-
github.com/argoproj-labs/argocd-image-updater/registry-scanner v0.0.0-20250110160036-ae473dd84031/go.mod h1:gTR08JBkPgrrEJ06a5J6H97EWllbgCNs2nbDSPMKHDo=
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=
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_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/argoproj-labs/argocd-image-updater/pkg/common"
1010
"github.com/argoproj-labs/argocd-image-updater/pkg/kube"
11+
1112
"github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/image"
1213
registryKube "github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/kube"
1314

pkg/argocd/update_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
argomock "github.com/argoproj-labs/argocd-image-updater/pkg/argocd/mocks"
1717
"github.com/argoproj-labs/argocd-image-updater/pkg/common"
1818
"github.com/argoproj-labs/argocd-image-updater/pkg/kube"
19+
1920
"github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/image"
2021
registryKube "github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/kube"
2122
"github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/registry"

registry-scanner/pkg/common/constants.go

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@ package common
22

33
// This file contains a list of constants required by other packages
44

5-
const ImageUpdaterAnnotationPrefix = "argocd-image-updater.argoproj.io"
6-
7-
// The annotation on the application resources to indicate the list of images
8-
// allowed for updates.
9-
const ImageUpdaterAnnotation = ImageUpdaterAnnotationPrefix + "/image-list"
10-
115
// Defaults for Helm parameter names
126
const (
137
DefaultHelmImageName = "image.name"
@@ -16,50 +10,32 @@ const (
1610

1711
// Helm related annotations
1812
const (
19-
HelmParamImageNameAnnotation = ImageUpdaterAnnotationPrefix + "/%s.helm.image-name"
20-
HelmParamImageTagAnnotation = ImageUpdaterAnnotationPrefix + "/%s.helm.image-tag"
21-
HelmParamImageSpecAnnotation = ImageUpdaterAnnotationPrefix + "/%s.helm.image-spec"
13+
HelmParamImageNameAnnotationSuffix = "/%s.helm.image-name"
14+
HelmParamImageTagAnnotationSuffix = "/%s.helm.image-tag"
15+
HelmParamImageSpecAnnotationSuffix = "/%s.helm.image-spec"
2216
)
2317

2418
// Kustomize related annotations
2519
const (
26-
KustomizeApplicationNameAnnotation = ImageUpdaterAnnotationPrefix + "/%s.kustomize.image-name"
20+
KustomizeApplicationNameAnnotationSuffix = "/%s.kustomize.image-name"
2721
)
2822

2923
// Image specific configuration annotations
3024
const (
31-
OldMatchOptionAnnotation = ImageUpdaterAnnotationPrefix + "/%s.tag-match" // Deprecated and will be removed
32-
AllowTagsOptionAnnotation = ImageUpdaterAnnotationPrefix + "/%s.allow-tags"
33-
IgnoreTagsOptionAnnotation = ImageUpdaterAnnotationPrefix + "/%s.ignore-tags"
34-
ForceUpdateOptionAnnotation = ImageUpdaterAnnotationPrefix + "/%s.force-update"
35-
UpdateStrategyAnnotation = ImageUpdaterAnnotationPrefix + "/%s.update-strategy"
36-
PullSecretAnnotation = ImageUpdaterAnnotationPrefix + "/%s.pull-secret"
37-
PlatformsAnnotation = ImageUpdaterAnnotationPrefix + "/%s.platforms"
25+
OldMatchOptionAnnotationSuffix = "/%s.tag-match" // Deprecated and will be removed
26+
AllowTagsOptionAnnotationSuffix = "/%s.allow-tags"
27+
IgnoreTagsOptionAnnotationSuffix = "/%s.ignore-tags"
28+
ForceUpdateOptionAnnotationSuffix = "/%s.force-update"
29+
UpdateStrategyAnnotationSuffix = "/%s.update-strategy"
30+
PullSecretAnnotationSuffix = "/%s.pull-secret"
31+
PlatformsAnnotationSuffix = "/%s.platforms"
3832
)
3933

4034
// Application-wide update strategy related annotations
4135
const (
42-
ApplicationWideAllowTagsOptionAnnotation = ImageUpdaterAnnotationPrefix + "/allow-tags"
43-
ApplicationWideIgnoreTagsOptionAnnotation = ImageUpdaterAnnotationPrefix + "/ignore-tags"
44-
ApplicationWideForceUpdateOptionAnnotation = ImageUpdaterAnnotationPrefix + "/force-update"
45-
ApplicationWideUpdateStrategyAnnotation = ImageUpdaterAnnotationPrefix + "/update-strategy"
46-
ApplicationWidePullSecretAnnotation = ImageUpdaterAnnotationPrefix + "/pull-secret"
36+
ApplicationWideAllowTagsOptionAnnotationSuffix = "/allow-tags"
37+
ApplicationWideIgnoreTagsOptionAnnotationSuffix = "/ignore-tags"
38+
ApplicationWideForceUpdateOptionAnnotationSuffix = "/force-update"
39+
ApplicationWideUpdateStrategyAnnotationSuffix = "/update-strategy"
40+
ApplicationWidePullSecretAnnotationSuffix = "/pull-secret"
4741
)
48-
49-
// Application update configuration related annotations
50-
const (
51-
WriteBackMethodAnnotation = ImageUpdaterAnnotationPrefix + "/write-back-method"
52-
GitBranchAnnotation = ImageUpdaterAnnotationPrefix + "/git-branch"
53-
GitRepositoryAnnotation = ImageUpdaterAnnotationPrefix + "/git-repository"
54-
WriteBackTargetAnnotation = ImageUpdaterAnnotationPrefix + "/write-back-target"
55-
KustomizationPrefix = "kustomization"
56-
HelmPrefix = "helmvalues"
57-
)
58-
59-
// The default Git commit message's template
60-
const DefaultGitCommitMessage = `build: automatic update of {{ .AppName }}
61-
62-
{{ range .AppChanges -}}
63-
updates image {{ .Image }} tag '{{ .OldTag }}' to '{{ .NewTag }}'
64-
{{ end -}}
65-
`

registry-scanner/pkg/common/helper.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package common
2+
3+
// This file contains a helper function to retrieve prefixed value of the constants
4+
5+
// Prefixed returns the annotation of the constant prefixed with the given prefix
6+
func Prefixed(prefix string, annotation string) string {
7+
return prefix + annotation
8+
}

registry-scanner/pkg/image/options.go

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import (
1212

1313
// GetParameterHelmImageName gets the value for image-name option for the image
1414
// from a set of annotations
15-
func (img *ContainerImage) GetParameterHelmImageName(annotations map[string]string) string {
16-
key := fmt.Sprintf(common.HelmParamImageNameAnnotation, img.normalizedSymbolicName())
15+
func (img *ContainerImage) GetParameterHelmImageName(annotations map[string]string, annotationPrefix string) string {
16+
key := fmt.Sprintf(common.Prefixed(annotationPrefix, common.HelmParamImageNameAnnotationSuffix), img.normalizedSymbolicName())
1717
val, ok := annotations[key]
1818
if !ok {
1919
return ""
@@ -23,8 +23,8 @@ func (img *ContainerImage) GetParameterHelmImageName(annotations map[string]stri
2323

2424
// GetParameterHelmImageTag gets the value for image-tag option for the image
2525
// from a set of annotations
26-
func (img *ContainerImage) GetParameterHelmImageTag(annotations map[string]string) string {
27-
key := fmt.Sprintf(common.HelmParamImageTagAnnotation, img.normalizedSymbolicName())
26+
func (img *ContainerImage) GetParameterHelmImageTag(annotations map[string]string, annotationPrefix string) string {
27+
key := fmt.Sprintf(common.Prefixed(annotationPrefix, common.HelmParamImageTagAnnotationSuffix), img.normalizedSymbolicName())
2828
val, ok := annotations[key]
2929
if !ok {
3030
return ""
@@ -34,8 +34,8 @@ func (img *ContainerImage) GetParameterHelmImageTag(annotations map[string]strin
3434

3535
// GetParameterHelmImageSpec gets the value for image-spec option for the image
3636
// from a set of annotations
37-
func (img *ContainerImage) GetParameterHelmImageSpec(annotations map[string]string) string {
38-
key := fmt.Sprintf(common.HelmParamImageSpecAnnotation, img.normalizedSymbolicName())
37+
func (img *ContainerImage) GetParameterHelmImageSpec(annotations map[string]string, annotationPrefix string) string {
38+
key := fmt.Sprintf(common.Prefixed(annotationPrefix, common.HelmParamImageSpecAnnotationSuffix), img.normalizedSymbolicName())
3939
val, ok := annotations[key]
4040
if !ok {
4141
return ""
@@ -45,8 +45,8 @@ func (img *ContainerImage) GetParameterHelmImageSpec(annotations map[string]stri
4545

4646
// GetParameterKustomizeImageName gets the value for image-spec option for the
4747
// image from a set of annotations
48-
func (img *ContainerImage) GetParameterKustomizeImageName(annotations map[string]string) string {
49-
key := fmt.Sprintf(common.KustomizeApplicationNameAnnotation, img.normalizedSymbolicName())
48+
func (img *ContainerImage) GetParameterKustomizeImageName(annotations map[string]string, annotationPrefix string) string {
49+
key := fmt.Sprintf(common.Prefixed(annotationPrefix, common.KustomizeApplicationNameAnnotationSuffix), img.normalizedSymbolicName())
5050
val, ok := annotations[key]
5151
if !ok {
5252
return ""
@@ -56,10 +56,10 @@ func (img *ContainerImage) GetParameterKustomizeImageName(annotations map[string
5656

5757
// HasForceUpdateOptionAnnotation gets the value for force-update option for the
5858
// image from a set of annotations
59-
func (img *ContainerImage) HasForceUpdateOptionAnnotation(annotations map[string]string) bool {
59+
func (img *ContainerImage) HasForceUpdateOptionAnnotation(annotations map[string]string, annotationPrefix string) bool {
6060
forceUpdateAnnotations := []string{
61-
fmt.Sprintf(common.ForceUpdateOptionAnnotation, img.normalizedSymbolicName()),
62-
common.ApplicationWideForceUpdateOptionAnnotation,
61+
fmt.Sprintf(common.Prefixed(annotationPrefix, common.ForceUpdateOptionAnnotationSuffix), img.normalizedSymbolicName()),
62+
common.Prefixed(annotationPrefix, common.ApplicationWideForceUpdateOptionAnnotationSuffix),
6363
}
6464
var forceUpdateVal = ""
6565
for _, key := range forceUpdateAnnotations {
@@ -73,10 +73,10 @@ func (img *ContainerImage) HasForceUpdateOptionAnnotation(annotations map[string
7373

7474
// GetParameterSort gets and validates the value for the sort option for the
7575
// image from a set of annotations
76-
func (img *ContainerImage) GetParameterUpdateStrategy(annotations map[string]string) UpdateStrategy {
76+
func (img *ContainerImage) GetParameterUpdateStrategy(annotations map[string]string, annotationPrefix string) UpdateStrategy {
7777
updateStrategyAnnotations := []string{
78-
fmt.Sprintf(common.UpdateStrategyAnnotation, img.normalizedSymbolicName()),
79-
common.ApplicationWideUpdateStrategyAnnotation,
78+
fmt.Sprintf(common.Prefixed(annotationPrefix, common.UpdateStrategyAnnotationSuffix), img.normalizedSymbolicName()),
79+
common.Prefixed(annotationPrefix, common.ApplicationWideUpdateStrategyAnnotationSuffix),
8080
}
8181
var updateStrategyVal = ""
8282
for _, key := range updateStrategyAnnotations {
@@ -121,10 +121,10 @@ func (img *ContainerImage) ParseUpdateStrategy(val string) UpdateStrategy {
121121
// GetParameterMatch returns the match function and pattern to use for matching
122122
// tag names. If an invalid option is found, it returns MatchFuncNone as the
123123
// default, to prevent accidental matches.
124-
func (img *ContainerImage) GetParameterMatch(annotations map[string]string) (MatchFuncFn, interface{}) {
124+
func (img *ContainerImage) GetParameterMatch(annotations map[string]string, annotationPrefix string) (MatchFuncFn, interface{}) {
125125
allowTagsAnnotations := []string{
126-
fmt.Sprintf(common.AllowTagsOptionAnnotation, img.normalizedSymbolicName()),
127-
common.ApplicationWideAllowTagsOptionAnnotation,
126+
fmt.Sprintf(common.Prefixed(annotationPrefix, common.AllowTagsOptionAnnotationSuffix), img.normalizedSymbolicName()),
127+
common.Prefixed(annotationPrefix, common.ApplicationWideAllowTagsOptionAnnotationSuffix),
128128
}
129129
var allowTagsVal = ""
130130
for _, key := range allowTagsAnnotations {
@@ -137,7 +137,7 @@ func (img *ContainerImage) GetParameterMatch(annotations map[string]string) (Mat
137137
if allowTagsVal == "" {
138138
// The old match-tag annotation is deprecated and will be subject to removal
139139
// in a future version.
140-
key := fmt.Sprintf(common.OldMatchOptionAnnotation, img.normalizedSymbolicName())
140+
key := fmt.Sprintf(common.Prefixed(annotationPrefix, common.OldMatchOptionAnnotationSuffix), img.normalizedSymbolicName())
141141
val, ok := annotations[key]
142142
if ok {
143143
logCtx.Warnf("The 'tag-match' annotation is deprecated and subject to removal. Please use 'allow-tags' annotation instead.")
@@ -180,10 +180,10 @@ func (img *ContainerImage) ParseMatchfunc(val string) (MatchFuncFn, interface{})
180180
}
181181

182182
// GetParameterPullSecret retrieves an image's pull secret credentials
183-
func (img *ContainerImage) GetParameterPullSecret(annotations map[string]string) *CredentialSource {
183+
func (img *ContainerImage) GetParameterPullSecret(annotations map[string]string, annotationPrefix string) *CredentialSource {
184184
pullSecretAnnotations := []string{
185-
fmt.Sprintf(common.PullSecretAnnotation, img.normalizedSymbolicName()),
186-
common.ApplicationWidePullSecretAnnotation,
185+
fmt.Sprintf(common.Prefixed(annotationPrefix, common.PullSecretAnnotationSuffix), img.normalizedSymbolicName()),
186+
common.Prefixed(annotationPrefix, common.ApplicationWidePullSecretAnnotationSuffix),
187187
}
188188
var pullSecretVal = ""
189189
for _, key := range pullSecretAnnotations {
@@ -206,10 +206,10 @@ func (img *ContainerImage) GetParameterPullSecret(annotations map[string]string)
206206
}
207207

208208
// GetParameterIgnoreTags retrieves a list of tags to ignore from a comma-separated string
209-
func (img *ContainerImage) GetParameterIgnoreTags(annotations map[string]string) []string {
209+
func (img *ContainerImage) GetParameterIgnoreTags(annotations map[string]string, annotationPrefix string) []string {
210210
ignoreTagsAnnotations := []string{
211-
fmt.Sprintf(common.IgnoreTagsOptionAnnotation, img.normalizedSymbolicName()),
212-
common.ApplicationWideIgnoreTagsOptionAnnotation,
211+
fmt.Sprintf(common.Prefixed(annotationPrefix, common.IgnoreTagsOptionAnnotationSuffix), img.normalizedSymbolicName()),
212+
common.Prefixed(annotationPrefix, common.ApplicationWideIgnoreTagsOptionAnnotationSuffix),
213213
}
214214
var ignoreTagsVal = ""
215215
for _, key := range ignoreTagsAnnotations {
@@ -239,10 +239,10 @@ func (img *ContainerImage) GetParameterIgnoreTags(annotations map[string]string)
239239
// is specified in the annotations, we restrict the platform for images to the
240240
// platform we're executed on unless unrestricted is set to true, in which case
241241
// we do not setup a platform restriction if no platform annotation is found.
242-
func (img *ContainerImage) GetPlatformOptions(annotations map[string]string, unrestricted bool) *options.ManifestOptions {
242+
func (img *ContainerImage) GetPlatformOptions(annotations map[string]string, unrestricted bool, annotationPrefix string) *options.ManifestOptions {
243243
logCtx := img.LogContext()
244244
var opts *options.ManifestOptions = options.NewManifestOptions()
245-
key := fmt.Sprintf(common.PlatformsAnnotation, img.normalizedSymbolicName())
245+
key := fmt.Sprintf(common.Prefixed(annotationPrefix, common.PlatformsAnnotationSuffix), img.normalizedSymbolicName())
246246
val, ok := annotations[key]
247247
if !ok {
248248
if !unrestricted {

0 commit comments

Comments
 (0)