From 10a01f381aa7d55e9806c7e8df75fee78976cebc Mon Sep 17 00:00:00 2001 From: Ishita Sequeira <46771830+ishitasequeira@users.noreply.github.com> Date: Tue, 14 Jan 2025 09:40:21 -0500 Subject: [PATCH] chore: separate Argo specific constants from registry-scanner constants (#1010) Signed-off-by: Ishita Sequeira --- go.mod | 2 +- go.sum | 4 +- pkg/argocd/argocd_test.go | 1 + pkg/argocd/update_test.go | 1 + registry-scanner/pkg/common/constants.go | 56 ++----- registry-scanner/pkg/common/helper.go | 8 + registry-scanner/pkg/image/options.go | 52 +++--- registry-scanner/pkg/image/options_test.go | 176 ++++++++++----------- 8 files changed, 143 insertions(+), 157 deletions(-) create mode 100644 registry-scanner/pkg/common/helper.go diff --git a/go.mod b/go.mod index 0514cf00..20a779bd 100644 --- a/go.mod +++ b/go.mod @@ -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-20250110160036-ae473dd84031 + github.com/argoproj-labs/argocd-image-updater/registry-scanner v0.0.0-20250110211602-b1555062f8fc 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 diff --git a/go.sum b/go.sum index b03469a1..8ce2152f 100644 --- a/go.sum +++ b/go.sum @@ -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-20250110160036-ae473dd84031 h1:GqT66PDjz8J8vgG+bQ4UnFgpg16PrcO8lrLL+NlU8pI= -github.com/argoproj-labs/argocd-image-updater/registry-scanner v0.0.0-20250110160036-ae473dd84031/go.mod h1:gTR08JBkPgrrEJ06a5J6H97EWllbgCNs2nbDSPMKHDo= +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/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= diff --git a/pkg/argocd/argocd_test.go b/pkg/argocd/argocd_test.go index 00660fb2..3876da07 100644 --- a/pkg/argocd/argocd_test.go +++ b/pkg/argocd/argocd_test.go @@ -8,6 +8,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/registry-scanner/pkg/image" registryKube "github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/kube" diff --git a/pkg/argocd/update_test.go b/pkg/argocd/update_test.go index 480f9946..1f3de53a 100644 --- a/pkg/argocd/update_test.go +++ b/pkg/argocd/update_test.go @@ -16,6 +16,7 @@ import ( argomock "github.com/argoproj-labs/argocd-image-updater/pkg/argocd/mocks" "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/registry-scanner/pkg/image" registryKube "github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/kube" "github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/registry" diff --git a/registry-scanner/pkg/common/constants.go b/registry-scanner/pkg/common/constants.go index eeb9ccb8..b2b889bf 100644 --- a/registry-scanner/pkg/common/constants.go +++ b/registry-scanner/pkg/common/constants.go @@ -2,12 +2,6 @@ package common // This file contains a list of constants required by other packages -const ImageUpdaterAnnotationPrefix = "argocd-image-updater.argoproj.io" - -// The annotation on the application resources to indicate the list of images -// allowed for updates. -const ImageUpdaterAnnotation = ImageUpdaterAnnotationPrefix + "/image-list" - // Defaults for Helm parameter names const ( DefaultHelmImageName = "image.name" @@ -16,50 +10,32 @@ const ( // Helm related annotations const ( - HelmParamImageNameAnnotation = ImageUpdaterAnnotationPrefix + "/%s.helm.image-name" - HelmParamImageTagAnnotation = ImageUpdaterAnnotationPrefix + "/%s.helm.image-tag" - HelmParamImageSpecAnnotation = ImageUpdaterAnnotationPrefix + "/%s.helm.image-spec" + HelmParamImageNameAnnotationSuffix = "/%s.helm.image-name" + HelmParamImageTagAnnotationSuffix = "/%s.helm.image-tag" + HelmParamImageSpecAnnotationSuffix = "/%s.helm.image-spec" ) // Kustomize related annotations const ( - KustomizeApplicationNameAnnotation = ImageUpdaterAnnotationPrefix + "/%s.kustomize.image-name" + KustomizeApplicationNameAnnotationSuffix = "/%s.kustomize.image-name" ) // Image specific configuration annotations const ( - OldMatchOptionAnnotation = ImageUpdaterAnnotationPrefix + "/%s.tag-match" // Deprecated and will be removed - AllowTagsOptionAnnotation = ImageUpdaterAnnotationPrefix + "/%s.allow-tags" - IgnoreTagsOptionAnnotation = ImageUpdaterAnnotationPrefix + "/%s.ignore-tags" - ForceUpdateOptionAnnotation = ImageUpdaterAnnotationPrefix + "/%s.force-update" - UpdateStrategyAnnotation = ImageUpdaterAnnotationPrefix + "/%s.update-strategy" - PullSecretAnnotation = ImageUpdaterAnnotationPrefix + "/%s.pull-secret" - PlatformsAnnotation = ImageUpdaterAnnotationPrefix + "/%s.platforms" + OldMatchOptionAnnotationSuffix = "/%s.tag-match" // Deprecated and will be removed + AllowTagsOptionAnnotationSuffix = "/%s.allow-tags" + IgnoreTagsOptionAnnotationSuffix = "/%s.ignore-tags" + ForceUpdateOptionAnnotationSuffix = "/%s.force-update" + UpdateStrategyAnnotationSuffix = "/%s.update-strategy" + PullSecretAnnotationSuffix = "/%s.pull-secret" + PlatformsAnnotationSuffix = "/%s.platforms" ) // Application-wide update strategy related annotations const ( - ApplicationWideAllowTagsOptionAnnotation = ImageUpdaterAnnotationPrefix + "/allow-tags" - ApplicationWideIgnoreTagsOptionAnnotation = ImageUpdaterAnnotationPrefix + "/ignore-tags" - ApplicationWideForceUpdateOptionAnnotation = ImageUpdaterAnnotationPrefix + "/force-update" - ApplicationWideUpdateStrategyAnnotation = ImageUpdaterAnnotationPrefix + "/update-strategy" - ApplicationWidePullSecretAnnotation = ImageUpdaterAnnotationPrefix + "/pull-secret" + ApplicationWideAllowTagsOptionAnnotationSuffix = "/allow-tags" + ApplicationWideIgnoreTagsOptionAnnotationSuffix = "/ignore-tags" + ApplicationWideForceUpdateOptionAnnotationSuffix = "/force-update" + ApplicationWideUpdateStrategyAnnotationSuffix = "/update-strategy" + ApplicationWidePullSecretAnnotationSuffix = "/pull-secret" ) - -// Application update configuration related annotations -const ( - WriteBackMethodAnnotation = ImageUpdaterAnnotationPrefix + "/write-back-method" - GitBranchAnnotation = ImageUpdaterAnnotationPrefix + "/git-branch" - GitRepositoryAnnotation = ImageUpdaterAnnotationPrefix + "/git-repository" - WriteBackTargetAnnotation = ImageUpdaterAnnotationPrefix + "/write-back-target" - KustomizationPrefix = "kustomization" - HelmPrefix = "helmvalues" -) - -// The default Git commit message's template -const DefaultGitCommitMessage = `build: automatic update of {{ .AppName }} - -{{ range .AppChanges -}} -updates image {{ .Image }} tag '{{ .OldTag }}' to '{{ .NewTag }}' -{{ end -}} -` diff --git a/registry-scanner/pkg/common/helper.go b/registry-scanner/pkg/common/helper.go new file mode 100644 index 00000000..f23e7559 --- /dev/null +++ b/registry-scanner/pkg/common/helper.go @@ -0,0 +1,8 @@ +package common + +// This file contains a helper function to retrieve prefixed value of the constants + +// Prefixed returns the annotation of the constant prefixed with the given prefix +func Prefixed(prefix string, annotation string) string { + return prefix + annotation +} diff --git a/registry-scanner/pkg/image/options.go b/registry-scanner/pkg/image/options.go index 3c599dcf..308569c4 100644 --- a/registry-scanner/pkg/image/options.go +++ b/registry-scanner/pkg/image/options.go @@ -12,8 +12,8 @@ import ( // GetParameterHelmImageName gets the value for image-name option for the image // from a set of annotations -func (img *ContainerImage) GetParameterHelmImageName(annotations map[string]string) string { - key := fmt.Sprintf(common.HelmParamImageNameAnnotation, img.normalizedSymbolicName()) +func (img *ContainerImage) GetParameterHelmImageName(annotations map[string]string, annotationPrefix string) string { + key := fmt.Sprintf(common.Prefixed(annotationPrefix, common.HelmParamImageNameAnnotationSuffix), img.normalizedSymbolicName()) val, ok := annotations[key] if !ok { return "" @@ -23,8 +23,8 @@ func (img *ContainerImage) GetParameterHelmImageName(annotations map[string]stri // GetParameterHelmImageTag gets the value for image-tag option for the image // from a set of annotations -func (img *ContainerImage) GetParameterHelmImageTag(annotations map[string]string) string { - key := fmt.Sprintf(common.HelmParamImageTagAnnotation, img.normalizedSymbolicName()) +func (img *ContainerImage) GetParameterHelmImageTag(annotations map[string]string, annotationPrefix string) string { + key := fmt.Sprintf(common.Prefixed(annotationPrefix, common.HelmParamImageTagAnnotationSuffix), img.normalizedSymbolicName()) val, ok := annotations[key] if !ok { return "" @@ -34,8 +34,8 @@ func (img *ContainerImage) GetParameterHelmImageTag(annotations map[string]strin // GetParameterHelmImageSpec gets the value for image-spec option for the image // from a set of annotations -func (img *ContainerImage) GetParameterHelmImageSpec(annotations map[string]string) string { - key := fmt.Sprintf(common.HelmParamImageSpecAnnotation, img.normalizedSymbolicName()) +func (img *ContainerImage) GetParameterHelmImageSpec(annotations map[string]string, annotationPrefix string) string { + key := fmt.Sprintf(common.Prefixed(annotationPrefix, common.HelmParamImageSpecAnnotationSuffix), img.normalizedSymbolicName()) val, ok := annotations[key] if !ok { return "" @@ -45,8 +45,8 @@ func (img *ContainerImage) GetParameterHelmImageSpec(annotations map[string]stri // GetParameterKustomizeImageName gets the value for image-spec option for the // image from a set of annotations -func (img *ContainerImage) GetParameterKustomizeImageName(annotations map[string]string) string { - key := fmt.Sprintf(common.KustomizeApplicationNameAnnotation, img.normalizedSymbolicName()) +func (img *ContainerImage) GetParameterKustomizeImageName(annotations map[string]string, annotationPrefix string) string { + key := fmt.Sprintf(common.Prefixed(annotationPrefix, common.KustomizeApplicationNameAnnotationSuffix), img.normalizedSymbolicName()) val, ok := annotations[key] if !ok { return "" @@ -56,10 +56,10 @@ func (img *ContainerImage) GetParameterKustomizeImageName(annotations map[string // HasForceUpdateOptionAnnotation gets the value for force-update option for the // image from a set of annotations -func (img *ContainerImage) HasForceUpdateOptionAnnotation(annotations map[string]string) bool { +func (img *ContainerImage) HasForceUpdateOptionAnnotation(annotations map[string]string, annotationPrefix string) bool { forceUpdateAnnotations := []string{ - fmt.Sprintf(common.ForceUpdateOptionAnnotation, img.normalizedSymbolicName()), - common.ApplicationWideForceUpdateOptionAnnotation, + fmt.Sprintf(common.Prefixed(annotationPrefix, common.ForceUpdateOptionAnnotationSuffix), img.normalizedSymbolicName()), + common.Prefixed(annotationPrefix, common.ApplicationWideForceUpdateOptionAnnotationSuffix), } var forceUpdateVal = "" for _, key := range forceUpdateAnnotations { @@ -73,10 +73,10 @@ func (img *ContainerImage) HasForceUpdateOptionAnnotation(annotations map[string // GetParameterSort gets and validates the value for the sort option for the // image from a set of annotations -func (img *ContainerImage) GetParameterUpdateStrategy(annotations map[string]string) UpdateStrategy { +func (img *ContainerImage) GetParameterUpdateStrategy(annotations map[string]string, annotationPrefix string) UpdateStrategy { updateStrategyAnnotations := []string{ - fmt.Sprintf(common.UpdateStrategyAnnotation, img.normalizedSymbolicName()), - common.ApplicationWideUpdateStrategyAnnotation, + fmt.Sprintf(common.Prefixed(annotationPrefix, common.UpdateStrategyAnnotationSuffix), img.normalizedSymbolicName()), + common.Prefixed(annotationPrefix, common.ApplicationWideUpdateStrategyAnnotationSuffix), } var updateStrategyVal = "" for _, key := range updateStrategyAnnotations { @@ -121,10 +121,10 @@ func (img *ContainerImage) ParseUpdateStrategy(val string) UpdateStrategy { // GetParameterMatch returns the match function and pattern to use for matching // 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{}) { +func (img *ContainerImage) GetParameterMatch(annotations map[string]string, annotationPrefix string) (MatchFuncFn, interface{}) { allowTagsAnnotations := []string{ - fmt.Sprintf(common.AllowTagsOptionAnnotation, img.normalizedSymbolicName()), - common.ApplicationWideAllowTagsOptionAnnotation, + fmt.Sprintf(common.Prefixed(annotationPrefix, common.AllowTagsOptionAnnotationSuffix), img.normalizedSymbolicName()), + common.Prefixed(annotationPrefix, common.ApplicationWideAllowTagsOptionAnnotationSuffix), } var allowTagsVal = "" for _, key := range allowTagsAnnotations { @@ -137,7 +137,7 @@ func (img *ContainerImage) GetParameterMatch(annotations map[string]string) (Mat if allowTagsVal == "" { // The old match-tag annotation is deprecated and will be subject to removal // in a future version. - key := fmt.Sprintf(common.OldMatchOptionAnnotation, img.normalizedSymbolicName()) + key := fmt.Sprintf(common.Prefixed(annotationPrefix, common.OldMatchOptionAnnotationSuffix), img.normalizedSymbolicName()) val, ok := annotations[key] if ok { 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{}) } // GetParameterPullSecret retrieves an image's pull secret credentials -func (img *ContainerImage) GetParameterPullSecret(annotations map[string]string) *CredentialSource { +func (img *ContainerImage) GetParameterPullSecret(annotations map[string]string, annotationPrefix string) *CredentialSource { pullSecretAnnotations := []string{ - fmt.Sprintf(common.PullSecretAnnotation, img.normalizedSymbolicName()), - common.ApplicationWidePullSecretAnnotation, + fmt.Sprintf(common.Prefixed(annotationPrefix, common.PullSecretAnnotationSuffix), img.normalizedSymbolicName()), + common.Prefixed(annotationPrefix, common.ApplicationWidePullSecretAnnotationSuffix), } var pullSecretVal = "" for _, key := range pullSecretAnnotations { @@ -206,10 +206,10 @@ func (img *ContainerImage) GetParameterPullSecret(annotations map[string]string) } // GetParameterIgnoreTags retrieves a list of tags to ignore from a comma-separated string -func (img *ContainerImage) GetParameterIgnoreTags(annotations map[string]string) []string { +func (img *ContainerImage) GetParameterIgnoreTags(annotations map[string]string, annotationPrefix string) []string { ignoreTagsAnnotations := []string{ - fmt.Sprintf(common.IgnoreTagsOptionAnnotation, img.normalizedSymbolicName()), - common.ApplicationWideIgnoreTagsOptionAnnotation, + fmt.Sprintf(common.Prefixed(annotationPrefix, common.IgnoreTagsOptionAnnotationSuffix), img.normalizedSymbolicName()), + common.Prefixed(annotationPrefix, common.ApplicationWideIgnoreTagsOptionAnnotationSuffix), } var ignoreTagsVal = "" for _, key := range ignoreTagsAnnotations { @@ -239,10 +239,10 @@ func (img *ContainerImage) GetParameterIgnoreTags(annotations map[string]string) // is specified in the annotations, we restrict the platform for images to the // platform we're executed on unless unrestricted is set to true, in which case // we do not setup a platform restriction if no platform annotation is found. -func (img *ContainerImage) GetPlatformOptions(annotations map[string]string, unrestricted bool) *options.ManifestOptions { +func (img *ContainerImage) GetPlatformOptions(annotations map[string]string, unrestricted bool, annotationPrefix string) *options.ManifestOptions { logCtx := img.LogContext() var opts *options.ManifestOptions = options.NewManifestOptions() - key := fmt.Sprintf(common.PlatformsAnnotation, img.normalizedSymbolicName()) + key := fmt.Sprintf(common.Prefixed(annotationPrefix, common.PlatformsAnnotationSuffix), img.normalizedSymbolicName()) val, ok := annotations[key] if !ok { if !unrestricted { diff --git a/registry-scanner/pkg/image/options_test.go b/registry-scanner/pkg/image/options_test.go index c1c76133..123ba510 100644 --- a/registry-scanner/pkg/image/options_test.go +++ b/registry-scanner/pkg/image/options_test.go @@ -17,15 +17,15 @@ import ( func Test_GetHelmOptions(t *testing.T) { t.Run("Get Helm parameter for configured application", func(t *testing.T) { annotations := map[string]string{ - fmt.Sprintf(common.HelmParamImageNameAnnotation, "dummy"): "release.name", - fmt.Sprintf(common.HelmParamImageTagAnnotation, "dummy"): "release.tag", - fmt.Sprintf(common.HelmParamImageSpecAnnotation, "dummy"): "release.image", + fmt.Sprintf(common.Prefixed("", common.HelmParamImageNameAnnotationSuffix), "dummy"): "release.name", + fmt.Sprintf(common.Prefixed("", common.HelmParamImageTagAnnotationSuffix), "dummy"): "release.tag", + fmt.Sprintf(common.Prefixed("", common.HelmParamImageSpecAnnotationSuffix), "dummy"): "release.image", } img := NewFromIdentifier("dummy=foo/bar:1.12") - paramName := img.GetParameterHelmImageName(annotations) - paramTag := img.GetParameterHelmImageTag(annotations) - paramSpec := img.GetParameterHelmImageSpec(annotations) + paramName := img.GetParameterHelmImageName(annotations, "") + paramTag := img.GetParameterHelmImageTag(annotations, "") + paramSpec := img.GetParameterHelmImageSpec(annotations, "") assert.Equal(t, "release.name", paramName) assert.Equal(t, "release.tag", paramTag) assert.Equal(t, "release.image", paramSpec) @@ -33,15 +33,15 @@ func Test_GetHelmOptions(t *testing.T) { t.Run("Get Helm parameter for non-configured application", func(t *testing.T) { annotations := map[string]string{ - fmt.Sprintf(common.HelmParamImageNameAnnotation, "dummy"): "release.name", - fmt.Sprintf(common.HelmParamImageTagAnnotation, "dummy"): "release.tag", - fmt.Sprintf(common.HelmParamImageSpecAnnotation, "dummy"): "release.image", + fmt.Sprintf(common.Prefixed("", common.HelmParamImageNameAnnotationSuffix), "dummy"): "release.name", + fmt.Sprintf(common.Prefixed("", common.HelmParamImageTagAnnotationSuffix), "dummy"): "release.tag", + fmt.Sprintf(common.Prefixed("", common.HelmParamImageSpecAnnotationSuffix), "dummy"): "release.image", } img := NewFromIdentifier("foo=foo/bar:1.12") - paramName := img.GetParameterHelmImageName(annotations) - paramTag := img.GetParameterHelmImageTag(annotations) - paramSpec := img.GetParameterHelmImageSpec(annotations) + paramName := img.GetParameterHelmImageName(annotations, "") + paramTag := img.GetParameterHelmImageTag(annotations, "") + paramSpec := img.GetParameterHelmImageSpec(annotations, "") assert.Equal(t, "", paramName) assert.Equal(t, "", paramTag) assert.Equal(t, "", paramSpec) @@ -49,15 +49,15 @@ func Test_GetHelmOptions(t *testing.T) { t.Run("Get Helm parameter for configured application with normalized name", func(t *testing.T) { annotations := map[string]string{ - fmt.Sprintf(common.HelmParamImageNameAnnotation, "foo_dummy"): "release.name", - fmt.Sprintf(common.HelmParamImageTagAnnotation, "foo_dummy"): "release.tag", - fmt.Sprintf(common.HelmParamImageSpecAnnotation, "foo_dummy"): "release.image", + fmt.Sprintf(common.Prefixed("", common.HelmParamImageNameAnnotationSuffix), "foo_dummy"): "release.name", + fmt.Sprintf(common.Prefixed("", common.HelmParamImageTagAnnotationSuffix), "foo_dummy"): "release.tag", + fmt.Sprintf(common.Prefixed("", common.HelmParamImageSpecAnnotationSuffix), "foo_dummy"): "release.image", } img := NewFromIdentifier("foo/dummy=foo/bar:1.12") - paramName := img.GetParameterHelmImageName(annotations) - paramTag := img.GetParameterHelmImageTag(annotations) - paramSpec := img.GetParameterHelmImageSpec(annotations) + paramName := img.GetParameterHelmImageName(annotations, "") + paramTag := img.GetParameterHelmImageTag(annotations, "") + paramSpec := img.GetParameterHelmImageSpec(annotations, "") assert.Equal(t, "release.name", paramName) assert.Equal(t, "release.tag", paramTag) assert.Equal(t, "release.image", paramSpec) @@ -67,15 +67,15 @@ func Test_GetHelmOptions(t *testing.T) { func Test_GetKustomizeOptions(t *testing.T) { t.Run("Get Kustomize parameter for configured application", func(t *testing.T) { annotations := map[string]string{ - fmt.Sprintf(common.KustomizeApplicationNameAnnotation, "dummy"): "argoproj/argo-cd", + fmt.Sprintf(common.Prefixed("", common.KustomizeApplicationNameAnnotationSuffix), "dummy"): "argoproj/argo-cd", } img := NewFromIdentifier("dummy=foo/bar:1.12") - paramName := img.GetParameterKustomizeImageName(annotations) + paramName := img.GetParameterKustomizeImageName(annotations, "") assert.Equal(t, "argoproj/argo-cd", paramName) img = NewFromIdentifier("dummy2=foo2/bar2:1.12") - paramName = img.GetParameterKustomizeImageName(annotations) + paramName = img.GetParameterKustomizeImageName(annotations, "") assert.Equal(t, "", paramName) }) } @@ -83,90 +83,90 @@ func Test_GetKustomizeOptions(t *testing.T) { func Test_GetSortOption(t *testing.T) { t.Run("Get update strategy semver for configured application", func(t *testing.T) { annotations := map[string]string{ - fmt.Sprintf(common.UpdateStrategyAnnotation, "dummy"): "semver", + fmt.Sprintf(common.UpdateStrategyAnnotationSuffix, "dummy"): "semver", } img := NewFromIdentifier("dummy=foo/bar:1.12") - sortMode := img.GetParameterUpdateStrategy(annotations) + sortMode := img.GetParameterUpdateStrategy(annotations, "") assert.Equal(t, StrategySemVer, sortMode) }) t.Run("Use update strategy newest-build for configured application", func(t *testing.T) { annotations := map[string]string{ - fmt.Sprintf(common.UpdateStrategyAnnotation, "dummy"): "newest-build", + fmt.Sprintf(common.UpdateStrategyAnnotationSuffix, "dummy"): "newest-build", } img := NewFromIdentifier("dummy=foo/bar:1.12") - sortMode := img.GetParameterUpdateStrategy(annotations) + sortMode := img.GetParameterUpdateStrategy(annotations, "") assert.Equal(t, StrategyNewestBuild, sortMode) }) t.Run("Get update strategy date for configured application", func(t *testing.T) { annotations := map[string]string{ - fmt.Sprintf(common.UpdateStrategyAnnotation, "dummy"): "latest", + fmt.Sprintf(common.UpdateStrategyAnnotationSuffix, "dummy"): "latest", } img := NewFromIdentifier("dummy=foo/bar:1.12") - sortMode := img.GetParameterUpdateStrategy(annotations) + sortMode := img.GetParameterUpdateStrategy(annotations, "") assert.Equal(t, StrategyNewestBuild, sortMode) }) t.Run("Get update strategy name for configured application", func(t *testing.T) { annotations := map[string]string{ - fmt.Sprintf(common.UpdateStrategyAnnotation, "dummy"): "name", + fmt.Sprintf(common.UpdateStrategyAnnotationSuffix, "dummy"): "name", } img := NewFromIdentifier("dummy=foo/bar:1.12") - sortMode := img.GetParameterUpdateStrategy(annotations) + sortMode := img.GetParameterUpdateStrategy(annotations, "") assert.Equal(t, StrategyAlphabetical, sortMode) }) t.Run("Use update strategy alphabetical for configured application", func(t *testing.T) { annotations := map[string]string{ - fmt.Sprintf(common.UpdateStrategyAnnotation, "dummy"): "alphabetical", + fmt.Sprintf(common.UpdateStrategyAnnotationSuffix, "dummy"): "alphabetical", } img := NewFromIdentifier("dummy=foo/bar:1.12") - sortMode := img.GetParameterUpdateStrategy(annotations) + sortMode := img.GetParameterUpdateStrategy(annotations, "") assert.Equal(t, StrategyAlphabetical, sortMode) }) t.Run("Get update strategy option configured application because of invalid option", func(t *testing.T) { annotations := map[string]string{ - fmt.Sprintf(common.UpdateStrategyAnnotation, "dummy"): "invalid", + fmt.Sprintf(common.UpdateStrategyAnnotationSuffix, "dummy"): "invalid", } img := NewFromIdentifier("dummy=foo/bar:1.12") - sortMode := img.GetParameterUpdateStrategy(annotations) + sortMode := img.GetParameterUpdateStrategy(annotations, "") assert.Equal(t, StrategySemVer, sortMode) }) t.Run("Get update strategy option configured application because of option not set", func(t *testing.T) { annotations := map[string]string{} img := NewFromIdentifier("dummy=foo/bar:1.12") - sortMode := img.GetParameterUpdateStrategy(annotations) + sortMode := img.GetParameterUpdateStrategy(annotations, "") assert.Equal(t, StrategySemVer, sortMode) }) t.Run("Prefer update strategy option from image-specific annotation", func(t *testing.T) { annotations := map[string]string{ - fmt.Sprintf(common.UpdateStrategyAnnotation, "dummy"): "alphabetical", - common.ApplicationWideUpdateStrategyAnnotation: "newest-build", + fmt.Sprintf(common.UpdateStrategyAnnotationSuffix, "dummy"): "alphabetical", + common.ApplicationWideUpdateStrategyAnnotationSuffix: "newest-build", } img := NewFromIdentifier("dummy=foo/bar:1.12") - sortMode := img.GetParameterUpdateStrategy(annotations) + sortMode := img.GetParameterUpdateStrategy(annotations, "") assert.Equal(t, StrategyAlphabetical, sortMode) }) t.Run("Get update strategy option from application-wide annotation", func(t *testing.T) { annotations := map[string]string{ - common.ApplicationWideUpdateStrategyAnnotation: "newest-build", + common.ApplicationWideUpdateStrategyAnnotationSuffix: "newest-build", } img := NewFromIdentifier("dummy=foo/bar:1.12") - sortMode := img.GetParameterUpdateStrategy(annotations) + sortMode := img.GetParameterUpdateStrategy(annotations, "") assert.Equal(t, StrategyNewestBuild, sortMode) }) t.Run("Get update strategy option digest from application-wide annotation", func(t *testing.T) { annotations := map[string]string{ - common.ApplicationWideUpdateStrategyAnnotation: "digest", + common.ApplicationWideUpdateStrategyAnnotationSuffix: "digest", } img := NewFromIdentifier("dummy=foo/bar:1.12") - sortMode := img.GetParameterUpdateStrategy(annotations) + sortMode := img.GetParameterUpdateStrategy(annotations, "") assert.Equal(t, StrategyDigest, sortMode) }) } @@ -174,10 +174,10 @@ func Test_GetSortOption(t *testing.T) { 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.AllowTagsOptionAnnotation, "dummy"): "regexp:a-z", + fmt.Sprintf(common.AllowTagsOptionAnnotationSuffix, "dummy"): "regexp:a-z", } img := NewFromIdentifier("dummy=foo/bar:1.12") - matchFunc, matchArgs := img.GetParameterMatch(annotations) + matchFunc, matchArgs := img.GetParameterMatch(annotations, "") require.NotNil(t, matchFunc) require.NotNil(t, matchArgs) assert.IsType(t, ®exp.Regexp{}, matchArgs) @@ -185,20 +185,20 @@ 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.AllowTagsOptionAnnotation, "dummy"): `regexp:/foo\`, + fmt.Sprintf(common.AllowTagsOptionAnnotationSuffix, "dummy"): `regexp:/foo\`, } img := NewFromIdentifier("dummy=foo/bar:1.12") - matchFunc, matchArgs := img.GetParameterMatch(annotations) + matchFunc, matchArgs := img.GetParameterMatch(annotations, "") require.NotNil(t, matchFunc) require.Nil(t, matchArgs) }) t.Run("Get invalid match option for configured application", func(t *testing.T) { annotations := map[string]string{ - fmt.Sprintf(common.AllowTagsOptionAnnotation, "dummy"): "invalid", + fmt.Sprintf(common.AllowTagsOptionAnnotationSuffix, "dummy"): "invalid", } img := NewFromIdentifier("dummy=foo/bar:1.12") - matchFunc, matchArgs := img.GetParameterMatch(annotations) + matchFunc, matchArgs := img.GetParameterMatch(annotations, "") require.NotNil(t, matchFunc) require.Equal(t, false, matchFunc("", nil)) assert.Nil(t, matchArgs) @@ -207,7 +207,7 @@ func Test_GetMatchOption(t *testing.T) { t.Run("No match option for configured application", func(t *testing.T) { annotations := map[string]string{} img := NewFromIdentifier("dummy=foo/bar:1.12") - matchFunc, matchArgs := img.GetParameterMatch(annotations) + matchFunc, matchArgs := img.GetParameterMatch(annotations, "") require.NotNil(t, matchFunc) require.Equal(t, true, matchFunc("", nil)) assert.Equal(t, "", matchArgs) @@ -215,11 +215,11 @@ func Test_GetMatchOption(t *testing.T) { t.Run("Prefer match option from image-specific annotation", func(t *testing.T) { annotations := map[string]string{ - fmt.Sprintf(common.AllowTagsOptionAnnotation, "dummy"): "regexp:^[0-9]", - common.ApplicationWideAllowTagsOptionAnnotation: "regexp:^v", + fmt.Sprintf(common.AllowTagsOptionAnnotationSuffix, "dummy"): "regexp:^[0-9]", + common.ApplicationWideAllowTagsOptionAnnotationSuffix: "regexp:^v", } img := NewFromIdentifier("dummy=foo/bar:1.12") - matchFunc, matchArgs := img.GetParameterMatch(annotations) + matchFunc, matchArgs := img.GetParameterMatch(annotations, "") require.NotNil(t, matchFunc) require.NotNil(t, matchArgs) assert.IsType(t, ®exp.Regexp{}, matchArgs) @@ -229,10 +229,10 @@ func Test_GetMatchOption(t *testing.T) { t.Run("Get match option from application-wide annotation", func(t *testing.T) { annotations := map[string]string{ - common.ApplicationWideAllowTagsOptionAnnotation: "regexp:^v", + common.ApplicationWideAllowTagsOptionAnnotationSuffix: "regexp:^v", } img := NewFromIdentifier("dummy=foo/bar:1.12") - matchFunc, matchArgs := img.GetParameterMatch(annotations) + matchFunc, matchArgs := img.GetParameterMatch(annotations, "") require.NotNil(t, matchFunc) require.NotNil(t, matchArgs) assert.IsType(t, ®exp.Regexp{}, matchArgs) @@ -244,10 +244,10 @@ func Test_GetMatchOption(t *testing.T) { func Test_GetSecretOption(t *testing.T) { t.Run("Get cred source from annotation", func(t *testing.T) { annotations := map[string]string{ - fmt.Sprintf(common.PullSecretAnnotation, "dummy"): "pullsecret:foo/bar", + fmt.Sprintf(common.PullSecretAnnotationSuffix, "dummy"): "pullsecret:foo/bar", } img := NewFromIdentifier("dummy=foo/bar:1.12") - credSrc := img.GetParameterPullSecret(annotations) + credSrc := img.GetParameterPullSecret(annotations, "") require.NotNil(t, credSrc) assert.Equal(t, CredentialSourcePullSecret, credSrc.Type) assert.Equal(t, "foo", credSrc.SecretNamespace) @@ -257,27 +257,27 @@ func Test_GetSecretOption(t *testing.T) { t.Run("Invalid reference in annotation", func(t *testing.T) { annotations := map[string]string{ - fmt.Sprintf(common.PullSecretAnnotation, "dummy"): "foo/bar", + fmt.Sprintf(common.PullSecretAnnotationSuffix, "dummy"): "foo/bar", } img := NewFromIdentifier("dummy=foo/bar:1.12") - credSrc := img.GetParameterPullSecret(annotations) + credSrc := img.GetParameterPullSecret(annotations, "") require.Nil(t, credSrc) }) t.Run("Missing pull secret in annotation", func(t *testing.T) { annotations := map[string]string{} img := NewFromIdentifier("dummy=foo/bar:1.12") - credSrc := img.GetParameterPullSecret(annotations) + credSrc := img.GetParameterPullSecret(annotations, "") require.Nil(t, credSrc) }) t.Run("Prefer cred source from image-specific annotation", func(t *testing.T) { annotations := map[string]string{ - fmt.Sprintf(common.PullSecretAnnotation, "dummy"): "pullsecret:image/specific", - common.ApplicationWidePullSecretAnnotation: "pullsecret:app/wide", + fmt.Sprintf(common.PullSecretAnnotationSuffix, "dummy"): "pullsecret:image/specific", + common.ApplicationWidePullSecretAnnotationSuffix: "pullsecret:app/wide", } img := NewFromIdentifier("dummy=foo/bar:1.12") - credSrc := img.GetParameterPullSecret(annotations) + credSrc := img.GetParameterPullSecret(annotations, "") require.NotNil(t, credSrc) assert.Equal(t, CredentialSourcePullSecret, credSrc.Type) assert.Equal(t, "image", credSrc.SecretNamespace) @@ -287,10 +287,10 @@ func Test_GetSecretOption(t *testing.T) { t.Run("Get cred source from application-wide annotation", func(t *testing.T) { annotations := map[string]string{ - common.ApplicationWidePullSecretAnnotation: "pullsecret:app/wide", + common.ApplicationWidePullSecretAnnotationSuffix: "pullsecret:app/wide", } img := NewFromIdentifier("dummy=foo/bar:1.12") - credSrc := img.GetParameterPullSecret(annotations) + credSrc := img.GetParameterPullSecret(annotations, "") require.NotNil(t, credSrc) assert.Equal(t, CredentialSourcePullSecret, credSrc.Type) assert.Equal(t, "app", credSrc.SecretNamespace) @@ -302,10 +302,10 @@ func Test_GetSecretOption(t *testing.T) { func Test_GetIgnoreTags(t *testing.T) { t.Run("Get list of tags to ignore from image-specific annotation", func(t *testing.T) { annotations := map[string]string{ - fmt.Sprintf(common.IgnoreTagsOptionAnnotation, "dummy"): "tag1, ,tag2, tag3 , tag4", + fmt.Sprintf(common.IgnoreTagsOptionAnnotationSuffix, "dummy"): "tag1, ,tag2, tag3 , tag4", } img := NewFromIdentifier("dummy=foo/bar:1.12") - tags := img.GetParameterIgnoreTags(annotations) + tags := img.GetParameterIgnoreTags(annotations, "") require.Len(t, tags, 4) assert.Equal(t, "tag1", tags[0]) assert.Equal(t, "tag2", tags[1]) @@ -316,17 +316,17 @@ func Test_GetIgnoreTags(t *testing.T) { t.Run("No tags to ignore from image-specific annotation", func(t *testing.T) { annotations := map[string]string{} img := NewFromIdentifier("dummy=foo/bar:1.12") - tags := img.GetParameterIgnoreTags(annotations) + tags := img.GetParameterIgnoreTags(annotations, "") require.Nil(t, tags) }) t.Run("Prefer list of tags to ignore from image-specific annotation", func(t *testing.T) { annotations := map[string]string{ - fmt.Sprintf(common.IgnoreTagsOptionAnnotation, "dummy"): "tag1, tag2", - common.ApplicationWideIgnoreTagsOptionAnnotation: "tag3, tag4", + fmt.Sprintf(common.IgnoreTagsOptionAnnotationSuffix, "dummy"): "tag1, tag2", + common.ApplicationWideIgnoreTagsOptionAnnotationSuffix: "tag3, tag4", } img := NewFromIdentifier("dummy=foo/bar:1.12") - tags := img.GetParameterIgnoreTags(annotations) + tags := img.GetParameterIgnoreTags(annotations, "") require.Len(t, tags, 2) assert.Equal(t, "tag1", tags[0]) assert.Equal(t, "tag2", tags[1]) @@ -334,10 +334,10 @@ func Test_GetIgnoreTags(t *testing.T) { t.Run("Get list of tags to ignore from application-wide annotation", func(t *testing.T) { annotations := map[string]string{ - common.ApplicationWideIgnoreTagsOptionAnnotation: "tag3, tag4", + common.ApplicationWideIgnoreTagsOptionAnnotationSuffix: "tag3, tag4", } img := NewFromIdentifier("dummy=foo/bar:1.12") - tags := img.GetParameterIgnoreTags(annotations) + tags := img.GetParameterIgnoreTags(annotations, "") require.Len(t, tags, 2) assert.Equal(t, "tag3", tags[0]) assert.Equal(t, "tag4", tags[1]) @@ -347,29 +347,29 @@ func Test_GetIgnoreTags(t *testing.T) { func Test_HasForceUpdateOptionAnnotation(t *testing.T) { t.Run("Get force-update option from image-specific annotation", func(t *testing.T) { annotations := map[string]string{ - fmt.Sprintf(common.ForceUpdateOptionAnnotation, "dummy"): "true", + fmt.Sprintf(common.ForceUpdateOptionAnnotationSuffix, "dummy"): "true", } img := NewFromIdentifier("dummy=foo/bar:1.12") - forceUpdate := img.HasForceUpdateOptionAnnotation(annotations) + forceUpdate := img.HasForceUpdateOptionAnnotation(annotations, "") assert.True(t, forceUpdate) }) t.Run("Prefer force-update option from image-specific annotation", func(t *testing.T) { annotations := map[string]string{ - fmt.Sprintf(common.ForceUpdateOptionAnnotation, "dummy"): "true", - common.ApplicationWideForceUpdateOptionAnnotation: "false", + fmt.Sprintf(common.ForceUpdateOptionAnnotationSuffix, "dummy"): "true", + common.ApplicationWideForceUpdateOptionAnnotationSuffix: "false", } img := NewFromIdentifier("dummy=foo/bar:1.12") - forceUpdate := img.HasForceUpdateOptionAnnotation(annotations) + forceUpdate := img.HasForceUpdateOptionAnnotation(annotations, "") assert.True(t, forceUpdate) }) t.Run("Get force-update option from application-wide annotation", func(t *testing.T) { annotations := map[string]string{ - common.ApplicationWideForceUpdateOptionAnnotation: "false", + common.ApplicationWideForceUpdateOptionAnnotationSuffix: "false", } img := NewFromIdentifier("dummy=foo/bar:1.12") - forceUpdate := img.HasForceUpdateOptionAnnotation(annotations) + forceUpdate := img.HasForceUpdateOptionAnnotation(annotations, "") assert.False(t, forceUpdate) }) } @@ -378,7 +378,7 @@ func Test_GetPlatformOptions(t *testing.T) { t.Run("Empty platform options with restriction", func(t *testing.T) { annotations := map[string]string{} img := NewFromIdentifier("dummy=foo/bar:1.12") - opts := img.GetPlatformOptions(annotations, false) + opts := img.GetPlatformOptions(annotations, false, "") os := runtime.GOOS arch := runtime.GOARCH platform := opts.Platforms()[0] @@ -396,7 +396,7 @@ func Test_GetPlatformOptions(t *testing.T) { t.Run("Empty platform options without restriction", func(t *testing.T) { annotations := map[string]string{} img := NewFromIdentifier("dummy=foo/bar:1.12") - opts := img.GetPlatformOptions(annotations, true) + opts := img.GetPlatformOptions(annotations, true, "") os := runtime.GOOS arch := runtime.GOARCH assert.True(t, opts.WantsPlatform(os, arch, "")) @@ -408,10 +408,10 @@ func Test_GetPlatformOptions(t *testing.T) { arch := "arm64" variant := "v8" annotations := map[string]string{ - fmt.Sprintf(common.PlatformsAnnotation, "dummy"): options.PlatformKey(os, arch, variant), + fmt.Sprintf(common.PlatformsAnnotationSuffix, "dummy"): options.PlatformKey(os, arch, variant), } img := NewFromIdentifier("dummy=foo/bar:1.12") - opts := img.GetPlatformOptions(annotations, false) + opts := img.GetPlatformOptions(annotations, false, "") assert.True(t, opts.WantsPlatform(os, arch, variant)) assert.False(t, opts.WantsPlatform(os, arch, "invalid")) }) @@ -420,10 +420,10 @@ func Test_GetPlatformOptions(t *testing.T) { arch := "arm" variant := "v6" annotations := map[string]string{ - fmt.Sprintf(common.PlatformsAnnotation, "dummy"): options.PlatformKey(os, arch, variant), + fmt.Sprintf(common.PlatformsAnnotationSuffix, "dummy"): options.PlatformKey(os, arch, variant), } img := NewFromIdentifier("dummy=foo/bar:1.12") - opts := img.GetPlatformOptions(annotations, false) + opts := img.GetPlatformOptions(annotations, false, "") assert.True(t, opts.WantsPlatform(os, arch, variant)) assert.False(t, opts.WantsPlatform(os, arch, "")) assert.False(t, opts.WantsPlatform(runtime.GOOS, runtime.GOARCH, "")) @@ -434,10 +434,10 @@ func Test_GetPlatformOptions(t *testing.T) { arch := "arm" variant := "v6" annotations := map[string]string{ - fmt.Sprintf(common.PlatformsAnnotation, "dummy"): options.PlatformKey(os, arch, variant) + ", " + options.PlatformKey(runtime.GOOS, runtime.GOARCH, ""), + fmt.Sprintf(common.PlatformsAnnotationSuffix, "dummy"): options.PlatformKey(os, arch, variant) + ", " + options.PlatformKey(runtime.GOOS, runtime.GOARCH, ""), } img := NewFromIdentifier("dummy=foo/bar:1.12") - opts := img.GetPlatformOptions(annotations, false) + opts := img.GetPlatformOptions(annotations, false, "") assert.True(t, opts.WantsPlatform(os, arch, variant)) assert.True(t, opts.WantsPlatform(runtime.GOOS, runtime.GOARCH, "")) assert.False(t, opts.WantsPlatform(os, arch, "")) @@ -448,10 +448,10 @@ func Test_GetPlatformOptions(t *testing.T) { arch := "arm" variant := "v6" annotations := map[string]string{ - fmt.Sprintf(common.PlatformsAnnotation, "dummy"): "invalid", + fmt.Sprintf(common.PlatformsAnnotationSuffix, "dummy"): "invalid", } img := NewFromIdentifier("dummy=foo/bar:1.12") - opts := img.GetPlatformOptions(annotations, false) + opts := img.GetPlatformOptions(annotations, false, "") assert.False(t, opts.WantsPlatform(os, arch, variant)) assert.False(t, opts.WantsPlatform(runtime.GOOS, runtime.GOARCH, "")) assert.False(t, opts.WantsPlatform(os, arch, ""))