Skip to content

Commit

Permalink
chore: separate Argo specific constants from registry-scanner constan…
Browse files Browse the repository at this point in the history
…ts (#1010)

Signed-off-by: Ishita Sequeira <[email protected]>
  • Loading branch information
ishitasequeira authored Jan 14, 2025
1 parent 154f51a commit 10a01f3
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 157 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
1 change: 1 addition & 0 deletions pkg/argocd/argocd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
1 change: 1 addition & 0 deletions pkg/argocd/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
56 changes: 16 additions & 40 deletions registry-scanner/pkg/common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 -}}
`
8 changes: 8 additions & 0 deletions registry-scanner/pkg/common/helper.go
Original file line number Diff line number Diff line change
@@ -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
}
52 changes: 26 additions & 26 deletions registry-scanner/pkg/image/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand All @@ -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 ""
Expand All @@ -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 ""
Expand All @@ -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 ""
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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.")
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit 10a01f3

Please sign in to comment.