diff options
| author | jannfis <jann@mistrust.net> | 2020-09-27 18:32:55 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-09-27 18:32:55 +0200 |
| commit | fa95873da285ee00713e4041d117ad37f43d899e (patch) | |
| tree | 54c0854c6b84df057f27e6836a8ae5dacdaa9b74 /pkg | |
| parent | e91e51390bf6e4b78bbad96a39219c16504c9491 (diff) | |
refactor: Introduce allow-tags and deprecate tag-match annotation (#103)
Diffstat (limited to 'pkg')
| -rw-r--r-- | pkg/argocd/update_test.go | 4 | ||||
| -rw-r--r-- | pkg/common/constants.go | 3 | ||||
| -rw-r--r-- | pkg/image/options.go | 15 | ||||
| -rw-r--r-- | pkg/image/options_test.go | 6 |
4 files changed, 19 insertions, 9 deletions
diff --git a/pkg/argocd/update_test.go b/pkg/argocd/update_test.go index d3448bb..05c018d 100644 --- a/pkg/argocd/update_test.go +++ b/pkg/argocd/update_test.go @@ -258,8 +258,8 @@ func Test_UpdateApplication(t *testing.T) { Name: "guestbook", Namespace: "guestbook", Annotations: map[string]string{ - fmt.Sprintf(common.MatchOptionAnnotation, "dummy"): "regexp:^foobar$", - fmt.Sprintf(common.UpdateStrategyAnnotation, "dummy"): "name", + fmt.Sprintf(common.AllowTagsOptionAnnotation, "dummy"): "regexp:^foobar$", + fmt.Sprintf(common.UpdateStrategyAnnotation, "dummy"): "name", }, }, Spec: v1alpha1.ApplicationSpec{ diff --git a/pkg/common/constants.go b/pkg/common/constants.go index 847fe39..ae3d5b8 100644 --- a/pkg/common/constants.go +++ b/pkg/common/constants.go @@ -28,7 +28,8 @@ const ( // Upgrade strategy related annotations const ( - MatchOptionAnnotation = ImageUpdaterAnnotationPrefix + "/%s.tag-match" + OldMatchOptionAnnotation = ImageUpdaterAnnotationPrefix + "/%s.tag-match" // Deprecated and will be removed + AllowTagsOptionAnnotation = ImageUpdaterAnnotationPrefix + "/%s.allow-tags" IgnoreTagsOptionAnnotation = ImageUpdaterAnnotationPrefix + "/%s.ignore-tags" UpdateStrategyAnnotation = ImageUpdaterAnnotationPrefix + "/%s.update-strategy" ) diff --git a/pkg/image/options.go b/pkg/image/options.go index f777cf0..75f9cbd 100644 --- a/pkg/image/options.go +++ b/pkg/image/options.go @@ -83,11 +83,20 @@ func (img *ContainerImage) GetParameterUpdateStrategy(annotations map[string]str // tag names. If an invalid option is found, it returns MatchFuncNone as the // default, to prevent accidental matches. func (img *ContainerImage) GetParameterMatch(annotations map[string]string) (MatchFuncFn, interface{}) { - key := fmt.Sprintf(common.MatchOptionAnnotation, img.normalizedSymbolicName()) + + key := fmt.Sprintf(common.AllowTagsOptionAnnotation, img.normalizedSymbolicName()) val, ok := annotations[key] if !ok { - log.Tracef("No match annotation %s found", key) - return MatchFuncAny, "" + // The old match-tag annotation is deprecated and will be subject to removal + // in a future version. + key = fmt.Sprintf(common.OldMatchOptionAnnotation, img.normalizedSymbolicName()) + val, ok = annotations[key] + if !ok { + log.Tracef("No match annotation %s found", key) + return MatchFuncAny, "" + } else { + log.Warnf("The 'tag-match' annotation is deprecated and subject to removal. Please use 'allow-tags' annotation instead.") + } } // The special value "any" doesn't take any parameter diff --git a/pkg/image/options_test.go b/pkg/image/options_test.go index 182fc02..88a0266 100644 --- a/pkg/image/options_test.go +++ b/pkg/image/options_test.go @@ -123,7 +123,7 @@ func Test_GetMatchOption(t *testing.T) { t.Run("Get regexp match option for configured application", func(t *testing.T) { annotations := map[string]string{ - fmt.Sprintf(common.MatchOptionAnnotation, "dummy"): "regexp:a-z", + fmt.Sprintf(common.AllowTagsOptionAnnotation, "dummy"): "regexp:a-z", } img := NewFromIdentifier("dummy=foo/bar:1.12") matchFunc, matchArgs := img.GetParameterMatch(annotations) @@ -134,7 +134,7 @@ func Test_GetMatchOption(t *testing.T) { t.Run("Get regexp match option for configured application with invalid expression", func(t *testing.T) { annotations := map[string]string{ - fmt.Sprintf(common.MatchOptionAnnotation, "dummy"): `regexp:/foo\`, + fmt.Sprintf(common.AllowTagsOptionAnnotation, "dummy"): `regexp:/foo\`, } img := NewFromIdentifier("dummy=foo/bar:1.12") matchFunc, matchArgs := img.GetParameterMatch(annotations) @@ -144,7 +144,7 @@ func Test_GetMatchOption(t *testing.T) { t.Run("Get invalid match option for configured application", func(t *testing.T) { annotations := map[string]string{ - fmt.Sprintf(common.MatchOptionAnnotation, "dummy"): "invalid", + fmt.Sprintf(common.AllowTagsOptionAnnotation, "dummy"): "invalid", } img := NewFromIdentifier("dummy=foo/bar:1.12") matchFunc, matchArgs := img.GetParameterMatch(annotations) |
