Skip to content

Commit fa95873

Browse files
authored
refactor: Introduce allow-tags and deprecate tag-match annotation (#103)
1 parent e91e513 commit fa95873

File tree

5 files changed

+23
-13
lines changed

5 files changed

+23
-13
lines changed

docs/configuration/images.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ only consider tags that you are generally interested in.
127127
You can define a tag filter by using the following annotation:
128128

129129
```yaml
130-
argocd-image-updater.argoproj.io/<image_name>.tag-match: <match_func>
130+
argocd-image-updater.argoproj.io/<image_name>.allow-tags: <match_func>
131131
```
132132

133133
The following match functions are currently available:
@@ -292,14 +292,14 @@ some identifier (i.e. the hash of the Git commit) in the tag.
292292
2. Use `latest` as update strategy
293293

294294
3. If you just want to consider a given set of tags, i.e. `v1.0.0-<hash>`, use a
295-
`tag-match` annotation.
295+
`allow-tags` annotation.
296296

297297
Annotations might look like follows:
298298

299299
```yaml
300300
argocd-image-updater.argoproj.io/image-list: yourtool=yourorg/yourimage
301301
argocd-image-updater.argoproj.io/yourtool.update-strategy: latest
302-
argocd-image-updater.argoproj.io/yourtool.tag-match: regexp:^v1.0.0-[0-9a-zA-Z]+$
302+
argocd-image-updater.argoproj.io/yourtool.allow-tags: regexp:^v1.0.0-[0-9a-zA-Z]+$
303303
```
304304

305305
### Multiple images in the same Helm chart
@@ -341,7 +341,7 @@ must be prefixed with `argocd-image-updater.argoproj.io`.
341341
|---------------|-------|-----------|
342342
|`image-list`|*none*|Comma separated list of images to consider for update|
343343
|`<image_alias>.update-strategy`|`semver`|The update strategy to be used for the image|
344-
|`<image_alias>.tag-match`|*any*|A function to match tag names from registry against to be considered for update|
344+
|`<image_alias>.allow-tags`|*any*|A function to match tag names from registry against to be considered for update|
345345
|`<image_alias>.ignore-tags`|*none*|A comma-separated list of glob patterns that when match ignore a certain tag from the registry|
346346
|`<image_alias>.pull-secret`|*none*|A reference to a secret to be used as registry credentials for this image|
347347
|`<image_alias>.helm.image-spec`|*none*|Name of the Helm parameter to specify the canonical name of the image, i.e. holds `image/name:1.0`. If this is set, other Helm parameter related options will be ignored.|

pkg/argocd/update_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,8 @@ func Test_UpdateApplication(t *testing.T) {
258258
Name: "guestbook",
259259
Namespace: "guestbook",
260260
Annotations: map[string]string{
261-
fmt.Sprintf(common.MatchOptionAnnotation, "dummy"): "regexp:^foobar$",
262-
fmt.Sprintf(common.UpdateStrategyAnnotation, "dummy"): "name",
261+
fmt.Sprintf(common.AllowTagsOptionAnnotation, "dummy"): "regexp:^foobar$",
262+
fmt.Sprintf(common.UpdateStrategyAnnotation, "dummy"): "name",
263263
},
264264
},
265265
Spec: v1alpha1.ApplicationSpec{

pkg/common/constants.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ const (
2828

2929
// Upgrade strategy related annotations
3030
const (
31-
MatchOptionAnnotation = ImageUpdaterAnnotationPrefix + "/%s.tag-match"
31+
OldMatchOptionAnnotation = ImageUpdaterAnnotationPrefix + "/%s.tag-match" // Deprecated and will be removed
32+
AllowTagsOptionAnnotation = ImageUpdaterAnnotationPrefix + "/%s.allow-tags"
3233
IgnoreTagsOptionAnnotation = ImageUpdaterAnnotationPrefix + "/%s.ignore-tags"
3334
UpdateStrategyAnnotation = ImageUpdaterAnnotationPrefix + "/%s.update-strategy"
3435
)

pkg/image/options.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,20 @@ func (img *ContainerImage) GetParameterUpdateStrategy(annotations map[string]str
8383
// tag names. If an invalid option is found, it returns MatchFuncNone as the
8484
// default, to prevent accidental matches.
8585
func (img *ContainerImage) GetParameterMatch(annotations map[string]string) (MatchFuncFn, interface{}) {
86-
key := fmt.Sprintf(common.MatchOptionAnnotation, img.normalizedSymbolicName())
86+
87+
key := fmt.Sprintf(common.AllowTagsOptionAnnotation, img.normalizedSymbolicName())
8788
val, ok := annotations[key]
8889
if !ok {
89-
log.Tracef("No match annotation %s found", key)
90-
return MatchFuncAny, ""
90+
// The old match-tag annotation is deprecated and will be subject to removal
91+
// in a future version.
92+
key = fmt.Sprintf(common.OldMatchOptionAnnotation, img.normalizedSymbolicName())
93+
val, ok = annotations[key]
94+
if !ok {
95+
log.Tracef("No match annotation %s found", key)
96+
return MatchFuncAny, ""
97+
} else {
98+
log.Warnf("The 'tag-match' annotation is deprecated and subject to removal. Please use 'allow-tags' annotation instead.")
99+
}
91100
}
92101

93102
// The special value "any" doesn't take any parameter

pkg/image/options_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func Test_GetMatchOption(t *testing.T) {
123123

124124
t.Run("Get regexp match option for configured application", func(t *testing.T) {
125125
annotations := map[string]string{
126-
fmt.Sprintf(common.MatchOptionAnnotation, "dummy"): "regexp:a-z",
126+
fmt.Sprintf(common.AllowTagsOptionAnnotation, "dummy"): "regexp:a-z",
127127
}
128128
img := NewFromIdentifier("dummy=foo/bar:1.12")
129129
matchFunc, matchArgs := img.GetParameterMatch(annotations)
@@ -134,7 +134,7 @@ func Test_GetMatchOption(t *testing.T) {
134134

135135
t.Run("Get regexp match option for configured application with invalid expression", func(t *testing.T) {
136136
annotations := map[string]string{
137-
fmt.Sprintf(common.MatchOptionAnnotation, "dummy"): `regexp:/foo\`,
137+
fmt.Sprintf(common.AllowTagsOptionAnnotation, "dummy"): `regexp:/foo\`,
138138
}
139139
img := NewFromIdentifier("dummy=foo/bar:1.12")
140140
matchFunc, matchArgs := img.GetParameterMatch(annotations)
@@ -144,7 +144,7 @@ func Test_GetMatchOption(t *testing.T) {
144144

145145
t.Run("Get invalid match option for configured application", func(t *testing.T) {
146146
annotations := map[string]string{
147-
fmt.Sprintf(common.MatchOptionAnnotation, "dummy"): "invalid",
147+
fmt.Sprintf(common.AllowTagsOptionAnnotation, "dummy"): "invalid",
148148
}
149149
img := NewFromIdentifier("dummy=foo/bar:1.12")
150150
matchFunc, matchArgs := img.GetParameterMatch(annotations)

0 commit comments

Comments
 (0)