From b40e984c531c528befb218e2e6a54ffda81e6b4e Mon Sep 17 00:00:00 2001 From: Pasha Kostohrys Date: Wed, 15 May 2024 10:54:39 +0300 Subject: Release v0.13.0 Signed-off-by: Pasha Kostohrys --- VERSION | 2 +- manifests/base/kustomization.yaml | 2 +- manifests/install.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/VERSION b/VERSION index ae31da1..54d1a4f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -99.9.9 +0.13.0 diff --git a/manifests/base/kustomization.yaml b/manifests/base/kustomization.yaml index e362df0..63ce2fb 100644 --- a/manifests/base/kustomization.yaml +++ b/manifests/base/kustomization.yaml @@ -3,7 +3,7 @@ kind: Kustomization images: - name: quay.io/argoprojlabs/argocd-image-updater - newTag: latest + newTag: v0.13.0 resources: - ./config diff --git a/manifests/install.yaml b/manifests/install.yaml index b65b12b..58535e4 100644 --- a/manifests/install.yaml +++ b/manifests/install.yaml @@ -164,7 +164,7 @@ spec: key: kube.events name: argocd-image-updater-config optional: true - image: quay.io/argoprojlabs/argocd-image-updater:latest + image: quay.io/argoprojlabs/argocd-image-updater:v0.13.0 imagePullPolicy: Always livenessProbe: httpGet: -- cgit v1.2.3 From 00ce8a7f857308b9e17fdadfb429056b8f1fed8b Mon Sep 17 00:00:00 2001 From: David Vidal Villamide Date: Mon, 27 May 2024 15:31:11 +0200 Subject: add: GetImagesAndAliasesFromApplication to retrieve images with aliases fix: now using alias to retrieve annotations when updating Helm type app Signed-off-by: David Vidal Villamide --- pkg/argocd/argocd.go | 18 +++++++++++++++ pkg/argocd/argocd_test.go | 59 +++++++++++++++++++++++++++++++++++++++++++++++ pkg/argocd/update.go | 10 ++++---- 3 files changed, 83 insertions(+), 4 deletions(-) diff --git a/pkg/argocd/argocd.go b/pkg/argocd/argocd.go index 4584dbe..e3f7063 100644 --- a/pkg/argocd/argocd.go +++ b/pkg/argocd/argocd.go @@ -503,6 +503,24 @@ func GetImagesFromApplication(app *v1alpha1.Application) image.ContainerImageLis return images } +// GetImagesFromApplicationImagesAnnotation returns the list of known images for the given application from the images annotation +func GetImagesAndAliasesFromApplication(app *v1alpha1.Application) image.ContainerImageList { + images := GetImagesFromApplication(app) + + // We update the ImageAlias field of the Images found in the app.Status.Summary.Images list. + for _, img := range *parseImageList(app.Annotations) { + if image := images.ContainsImage(img, false); image != nil { + if img.ImageAlias == "" { + image.ImageAlias = img.ImageName + } else { + image.ImageAlias = img.ImageAlias + } + } + } + + return images +} + // GetApplicationTypeByName first retrieves application with given appName and // returns its application type func GetApplicationTypeByName(client ArgoCD, appName string) (ApplicationType, error) { diff --git a/pkg/argocd/argocd_test.go b/pkg/argocd/argocd_test.go index 9555357..84df479 100644 --- a/pkg/argocd/argocd_test.go +++ b/pkg/argocd/argocd_test.go @@ -79,6 +79,65 @@ func Test_GetImagesFromApplication(t *testing.T) { }) } +func Test_GetImagesAndAliasesFromApplication(t *testing.T) { + t.Run("Get list of images from application", func(t *testing.T) { + application := &v1alpha1.Application{ + ObjectMeta: v1.ObjectMeta{ + Name: "test-app", + Namespace: "argocd", + }, + Spec: v1alpha1.ApplicationSpec{}, + Status: v1alpha1.ApplicationStatus{ + Summary: v1alpha1.ApplicationSummary{ + Images: []string{"nginx:1.12.2", "that/image", "quay.io/dexidp/dex:v1.23.0"}, + }, + }, + } + imageList := GetImagesAndAliasesFromApplication(application) + require.Len(t, imageList, 3) + assert.Equal(t, "nginx", imageList[0].ImageName) + assert.Equal(t, "that/image", imageList[1].ImageName) + assert.Equal(t, "dexidp/dex", imageList[2].ImageName) + }) + + t.Run("Get list of images and image aliases from application that has no images", func(t *testing.T) { + application := &v1alpha1.Application{ + ObjectMeta: v1.ObjectMeta{ + Name: "test-app", + Namespace: "argocd", + }, + Spec: v1alpha1.ApplicationSpec{}, + Status: v1alpha1.ApplicationStatus{ + Summary: v1alpha1.ApplicationSummary{}, + }, + } + imageList := GetImagesAndAliasesFromApplication(application) + assert.Empty(t, imageList) + }) + + t.Run("Get list of images and aliases from application annotations", func(t *testing.T) { + application := &v1alpha1.Application{ + ObjectMeta: v1.ObjectMeta{ + Name: "test-app", + Namespace: "argocd", + Annotations: map[string]string{ + common.ImageUpdaterAnnotation: "webserver=nginx", + }, + }, + Spec: v1alpha1.ApplicationSpec{}, + Status: v1alpha1.ApplicationStatus{ + Summary: v1alpha1.ApplicationSummary{ + Images: []string{"nginx:1.12.2"}, + }, + }, + } + imageList := GetImagesAndAliasesFromApplication(application) + require.Len(t, imageList, 1) + assert.Equal(t, "nginx", imageList[0].ImageName) + assert.Equal(t, "webserver", imageList[0].ImageAlias) + }) +} + func Test_GetApplicationType(t *testing.T) { t.Run("Get application of type Helm", func(t *testing.T) { application := &v1alpha1.Application{ diff --git a/pkg/argocd/update.go b/pkg/argocd/update.go index fd1463e..8447466 100644 --- a/pkg/argocd/update.go +++ b/pkg/argocd/update.go @@ -416,15 +416,17 @@ func marshalParamsOverride(app *v1alpha1.Application, originalData []byte) ([]by } if strings.HasPrefix(app.Annotations[common.WriteBackTargetAnnotation], common.HelmPrefix) { - images := GetImagesFromApplication(app) + images := GetImagesAndAliasesFromApplication(app) for _, c := range images { - helmAnnotationParamName, helmAnnotationParamVersion := getHelmParamNamesFromAnnotation(app.Annotations, c.ImageName) + helmAnnotationParamName := c.GetParameterHelmImageName(app.Annotations) + helmAnnotationParamVersion := c.GetParameterHelmImageTag(app.Annotations) + if helmAnnotationParamName == "" { - return nil, fmt.Errorf("could not find an image-name annotation for image %s", c.ImageName) + return nil, fmt.Errorf("could not find an image-name annotation for image %s", c.ImageAlias) } if helmAnnotationParamVersion == "" { - return nil, fmt.Errorf("could not find an image-tag annotation for image %s", c.ImageName) + return nil, fmt.Errorf("could not find an image-tag annotation for image %s", c.ImageAlias) } helmParamName := getHelmParam(appSource.Helm.Parameters, helmAnnotationParamName) -- cgit v1.2.3 From 43afe2333cd82ff286e222e89d4125c433a380c3 Mon Sep 17 00:00:00 2001 From: David Vidal Villamide Date: Mon, 27 May 2024 18:39:20 +0200 Subject: changed: image version value to avoid issues with integration tests Signed-off-by: David Vidal Villamide --- manifests/base/kustomization.yaml | 2 +- manifests/install.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/manifests/base/kustomization.yaml b/manifests/base/kustomization.yaml index 63ce2fb..e362df0 100644 --- a/manifests/base/kustomization.yaml +++ b/manifests/base/kustomization.yaml @@ -3,7 +3,7 @@ kind: Kustomization images: - name: quay.io/argoprojlabs/argocd-image-updater - newTag: v0.13.0 + newTag: latest resources: - ./config diff --git a/manifests/install.yaml b/manifests/install.yaml index 58535e4..b65b12b 100644 --- a/manifests/install.yaml +++ b/manifests/install.yaml @@ -164,7 +164,7 @@ spec: key: kube.events name: argocd-image-updater-config optional: true - image: quay.io/argoprojlabs/argocd-image-updater:v0.13.0 + image: quay.io/argoprojlabs/argocd-image-updater:latest imagePullPolicy: Always livenessProbe: httpGet: -- cgit v1.2.3 From efec2b00bcca901bedc071ecb3a0b39a85cd017d Mon Sep 17 00:00:00 2001 From: David Vidal Villamide Date: Wed, 29 May 2024 13:12:06 +0200 Subject: fix: revert back version Signed-off-by: David Vidal Villamide --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 54d1a4f..ae31da1 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.13.0 +99.9.9 -- cgit v1.2.3 From 26bf144a7e976d97249842f5ae16625c002103da Mon Sep 17 00:00:00 2001 From: David Vidal Villamide Date: Wed, 29 May 2024 16:08:11 +0200 Subject: change: make NormalizedSymbolicName() method public fix: use NormalizedSymbolicName() to retrieve name and version from annotations for Helm app types Signed-off-by: David Vidal Villamide --- pkg/argocd/update.go | 3 +-- pkg/image/options.go | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/pkg/argocd/update.go b/pkg/argocd/update.go index 8447466..a2c5c25 100644 --- a/pkg/argocd/update.go +++ b/pkg/argocd/update.go @@ -419,8 +419,7 @@ func marshalParamsOverride(app *v1alpha1.Application, originalData []byte) ([]by images := GetImagesAndAliasesFromApplication(app) for _, c := range images { - helmAnnotationParamName := c.GetParameterHelmImageName(app.Annotations) - helmAnnotationParamVersion := c.GetParameterHelmImageTag(app.Annotations) + helmAnnotationParamName, helmAnnotationParamVersion := getHelmParamNamesFromAnnotation(app.Annotations, c.NormalizedSymbolicName()) if helmAnnotationParamName == "" { return nil, fmt.Errorf("could not find an image-name annotation for image %s", c.ImageAlias) diff --git a/pkg/image/options.go b/pkg/image/options.go index af6d12a..21aae15 100644 --- a/pkg/image/options.go +++ b/pkg/image/options.go @@ -13,7 +13,7 @@ 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()) + key := fmt.Sprintf(common.HelmParamImageNameAnnotation, img.NormalizedSymbolicName()) val, ok := annotations[key] if !ok { return "" @@ -24,7 +24,7 @@ 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()) + key := fmt.Sprintf(common.HelmParamImageTagAnnotation, img.NormalizedSymbolicName()) val, ok := annotations[key] if !ok { return "" @@ -35,7 +35,7 @@ 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()) + key := fmt.Sprintf(common.HelmParamImageSpecAnnotation, img.NormalizedSymbolicName()) val, ok := annotations[key] if !ok { return "" @@ -46,7 +46,7 @@ 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()) + key := fmt.Sprintf(common.KustomizeApplicationNameAnnotation, img.NormalizedSymbolicName()) val, ok := annotations[key] if !ok { return "" @@ -58,7 +58,7 @@ func (img *ContainerImage) GetParameterKustomizeImageName(annotations map[string // image from a set of annotations func (img *ContainerImage) HasForceUpdateOptionAnnotation(annotations map[string]string) bool { forceUpdateAnnotations := []string{ - fmt.Sprintf(common.ForceUpdateOptionAnnotation, img.normalizedSymbolicName()), + fmt.Sprintf(common.ForceUpdateOptionAnnotation, img.NormalizedSymbolicName()), common.ApplicationWideForceUpdateOptionAnnotation, } var forceUpdateVal = "" @@ -75,7 +75,7 @@ func (img *ContainerImage) HasForceUpdateOptionAnnotation(annotations map[string // image from a set of annotations func (img *ContainerImage) GetParameterUpdateStrategy(annotations map[string]string) UpdateStrategy { updateStrategyAnnotations := []string{ - fmt.Sprintf(common.UpdateStrategyAnnotation, img.normalizedSymbolicName()), + fmt.Sprintf(common.UpdateStrategyAnnotation, img.NormalizedSymbolicName()), common.ApplicationWideUpdateStrategyAnnotation, } var updateStrategyVal = "" @@ -123,7 +123,7 @@ func (img *ContainerImage) ParseUpdateStrategy(val string) UpdateStrategy { // default, to prevent accidental matches. func (img *ContainerImage) GetParameterMatch(annotations map[string]string) (MatchFuncFn, interface{}) { allowTagsAnnotations := []string{ - fmt.Sprintf(common.AllowTagsOptionAnnotation, img.normalizedSymbolicName()), + fmt.Sprintf(common.AllowTagsOptionAnnotation, img.NormalizedSymbolicName()), common.ApplicationWideAllowTagsOptionAnnotation, } var allowTagsVal = "" @@ -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.OldMatchOptionAnnotation, 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.") @@ -182,7 +182,7 @@ 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 { pullSecretAnnotations := []string{ - fmt.Sprintf(common.PullSecretAnnotation, img.normalizedSymbolicName()), + fmt.Sprintf(common.PullSecretAnnotation, img.NormalizedSymbolicName()), common.ApplicationWidePullSecretAnnotation, } var pullSecretVal = "" @@ -208,7 +208,7 @@ 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 { ignoreTagsAnnotations := []string{ - fmt.Sprintf(common.IgnoreTagsOptionAnnotation, img.normalizedSymbolicName()), + fmt.Sprintf(common.IgnoreTagsOptionAnnotation, img.NormalizedSymbolicName()), common.ApplicationWideIgnoreTagsOptionAnnotation, } var ignoreTagsVal = "" @@ -242,7 +242,7 @@ func (img *ContainerImage) GetParameterIgnoreTags(annotations map[string]string) func (img *ContainerImage) GetPlatformOptions(annotations map[string]string, unrestricted bool) *options.ManifestOptions { logCtx := img.LogContext() var opts *options.ManifestOptions = options.NewManifestOptions() - key := fmt.Sprintf(common.PlatformsAnnotation, img.normalizedSymbolicName()) + key := fmt.Sprintf(common.PlatformsAnnotation, img.NormalizedSymbolicName()) val, ok := annotations[key] if !ok { if !unrestricted { @@ -291,6 +291,6 @@ func ParsePlatform(platformID string) (string, string, string, error) { return os, arch, variant, nil } -func (img *ContainerImage) normalizedSymbolicName() string { +func (img *ContainerImage) NormalizedSymbolicName() string { return strings.ReplaceAll(img.ImageAlias, "/", "_") } -- cgit v1.2.3 From bdcecc1bd09adab329e47750edb108371ca30cd1 Mon Sep 17 00:00:00 2001 From: Pasha Kostohrys Date: Wed, 29 May 2024 18:02:44 +0300 Subject: fix: getHelmParamNamesFromAnnotation should take info from container image for prevent code duplication Signed-off-by: Pasha Kostohrys --- pkg/argocd/argocd.go | 16 ++++++++-------- pkg/argocd/argocd_test.go | 24 ++++++++++++++++++------ pkg/argocd/update.go | 2 +- pkg/image/options.go | 24 ++++++++++++------------ 4 files changed, 39 insertions(+), 27 deletions(-) diff --git a/pkg/argocd/argocd.go b/pkg/argocd/argocd.go index e3f7063..1a389e3 100644 --- a/pkg/argocd/argocd.go +++ b/pkg/argocd/argocd.go @@ -309,29 +309,29 @@ func (client *argoCD) UpdateSpec(ctx context.Context, in *application.Applicatio // getHelmParamNamesFromAnnotation inspects the given annotations for whether // the annotations for specifying Helm parameter names are being set and // returns their values. -func getHelmParamNamesFromAnnotation(annotations map[string]string, symbolicName string) (string, string) { +func getHelmParamNamesFromAnnotation(annotations map[string]string, img *image.ContainerImage) (string, string) { // Return default values without symbolic name given - if symbolicName == "" { + if img.ImageAlias == "" { return "image.name", "image.tag" } var annotationName, helmParamName, helmParamVersion string // Image spec is a full-qualified specifier, if we have it, we return early - annotationName = fmt.Sprintf(common.HelmParamImageSpecAnnotation, symbolicName) - if param, ok := annotations[annotationName]; ok { + param := img.GetParameterHelmImageSpec(annotations) + if param != "" { log.Tracef("found annotation %s", annotationName) return strings.TrimSpace(param), "" } - annotationName = fmt.Sprintf(common.HelmParamImageNameAnnotation, symbolicName) - if param, ok := annotations[annotationName]; ok { + param = img.GetParameterHelmImageName(annotations) + if param != "" { log.Tracef("found annotation %s", annotationName) helmParamName = param } - annotationName = fmt.Sprintf(common.HelmParamImageTagAnnotation, symbolicName) - if param, ok := annotations[annotationName]; ok { + param = img.GetParameterHelmImageTag(annotations) + if param != "" { log.Tracef("found annotation %s", annotationName) helmParamVersion = param } diff --git a/pkg/argocd/argocd_test.go b/pkg/argocd/argocd_test.go index 84df479..cbe5b07 100644 --- a/pkg/argocd/argocd_test.go +++ b/pkg/argocd/argocd_test.go @@ -600,7 +600,9 @@ func Test_GetHelmParamAnnotations(t *testing.T) { fmt.Sprintf(common.HelmParamImageSpecAnnotation, "myimg"): "image.blub", fmt.Sprintf(common.HelmParamImageTagAnnotation, "myimg"): "image.blab", } - name, tag := getHelmParamNamesFromAnnotation(annotations, "") + name, tag := getHelmParamNamesFromAnnotation(annotations, &image.ContainerImage{ + ImageAlias: "", + }) assert.Equal(t, "image.name", name) assert.Equal(t, "image.tag", tag) }) @@ -610,7 +612,9 @@ func Test_GetHelmParamAnnotations(t *testing.T) { fmt.Sprintf(common.HelmParamImageSpecAnnotation, "myimg"): "image.path", fmt.Sprintf(common.HelmParamImageTagAnnotation, "myimg"): "image.tag", } - name, tag := getHelmParamNamesFromAnnotation(annotations, "myimg") + name, tag := getHelmParamNamesFromAnnotation(annotations, &image.ContainerImage{ + ImageAlias: "myimg", + }) assert.Equal(t, "image.path", name) assert.Empty(t, tag) }) @@ -620,7 +624,9 @@ func Test_GetHelmParamAnnotations(t *testing.T) { fmt.Sprintf(common.HelmParamImageNameAnnotation, "myimg"): "image.name", fmt.Sprintf(common.HelmParamImageTagAnnotation, "myimg"): "image.tag", } - name, tag := getHelmParamNamesFromAnnotation(annotations, "myimg") + name, tag := getHelmParamNamesFromAnnotation(annotations, &image.ContainerImage{ + ImageAlias: "myimg", + }) assert.Equal(t, "image.name", name) assert.Equal(t, "image.tag", tag) }) @@ -630,7 +636,9 @@ func Test_GetHelmParamAnnotations(t *testing.T) { fmt.Sprintf(common.HelmParamImageNameAnnotation, "otherimg"): "image.name", fmt.Sprintf(common.HelmParamImageTagAnnotation, "otherimg"): "image.tag", } - name, tag := getHelmParamNamesFromAnnotation(annotations, "myimg") + name, tag := getHelmParamNamesFromAnnotation(annotations, &image.ContainerImage{ + ImageAlias: "myimg", + }) assert.Empty(t, name) assert.Empty(t, tag) }) @@ -639,14 +647,18 @@ func Test_GetHelmParamAnnotations(t *testing.T) { annotations := map[string]string{ fmt.Sprintf(common.HelmParamImageTagAnnotation, "myimg"): "image.tag", } - name, tag := getHelmParamNamesFromAnnotation(annotations, "myimg") + name, tag := getHelmParamNamesFromAnnotation(annotations, &image.ContainerImage{ + ImageAlias: "myimg", + }) assert.Empty(t, name) assert.Equal(t, "image.tag", tag) }) t.Run("No suitable annotations found", func(t *testing.T) { annotations := map[string]string{} - name, tag := getHelmParamNamesFromAnnotation(annotations, "myimg") + name, tag := getHelmParamNamesFromAnnotation(annotations, &image.ContainerImage{ + ImageAlias: "myimg", + }) assert.Empty(t, name) assert.Empty(t, tag) }) diff --git a/pkg/argocd/update.go b/pkg/argocd/update.go index a2c5c25..85dee36 100644 --- a/pkg/argocd/update.go +++ b/pkg/argocd/update.go @@ -419,7 +419,7 @@ func marshalParamsOverride(app *v1alpha1.Application, originalData []byte) ([]by images := GetImagesAndAliasesFromApplication(app) for _, c := range images { - helmAnnotationParamName, helmAnnotationParamVersion := getHelmParamNamesFromAnnotation(app.Annotations, c.NormalizedSymbolicName()) + helmAnnotationParamName, helmAnnotationParamVersion := getHelmParamNamesFromAnnotation(app.Annotations, c) if helmAnnotationParamName == "" { return nil, fmt.Errorf("could not find an image-name annotation for image %s", c.ImageAlias) diff --git a/pkg/image/options.go b/pkg/image/options.go index 21aae15..af6d12a 100644 --- a/pkg/image/options.go +++ b/pkg/image/options.go @@ -13,7 +13,7 @@ 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()) + key := fmt.Sprintf(common.HelmParamImageNameAnnotation, img.normalizedSymbolicName()) val, ok := annotations[key] if !ok { return "" @@ -24,7 +24,7 @@ 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()) + key := fmt.Sprintf(common.HelmParamImageTagAnnotation, img.normalizedSymbolicName()) val, ok := annotations[key] if !ok { return "" @@ -35,7 +35,7 @@ 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()) + key := fmt.Sprintf(common.HelmParamImageSpecAnnotation, img.normalizedSymbolicName()) val, ok := annotations[key] if !ok { return "" @@ -46,7 +46,7 @@ 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()) + key := fmt.Sprintf(common.KustomizeApplicationNameAnnotation, img.normalizedSymbolicName()) val, ok := annotations[key] if !ok { return "" @@ -58,7 +58,7 @@ func (img *ContainerImage) GetParameterKustomizeImageName(annotations map[string // image from a set of annotations func (img *ContainerImage) HasForceUpdateOptionAnnotation(annotations map[string]string) bool { forceUpdateAnnotations := []string{ - fmt.Sprintf(common.ForceUpdateOptionAnnotation, img.NormalizedSymbolicName()), + fmt.Sprintf(common.ForceUpdateOptionAnnotation, img.normalizedSymbolicName()), common.ApplicationWideForceUpdateOptionAnnotation, } var forceUpdateVal = "" @@ -75,7 +75,7 @@ func (img *ContainerImage) HasForceUpdateOptionAnnotation(annotations map[string // image from a set of annotations func (img *ContainerImage) GetParameterUpdateStrategy(annotations map[string]string) UpdateStrategy { updateStrategyAnnotations := []string{ - fmt.Sprintf(common.UpdateStrategyAnnotation, img.NormalizedSymbolicName()), + fmt.Sprintf(common.UpdateStrategyAnnotation, img.normalizedSymbolicName()), common.ApplicationWideUpdateStrategyAnnotation, } var updateStrategyVal = "" @@ -123,7 +123,7 @@ func (img *ContainerImage) ParseUpdateStrategy(val string) UpdateStrategy { // default, to prevent accidental matches. func (img *ContainerImage) GetParameterMatch(annotations map[string]string) (MatchFuncFn, interface{}) { allowTagsAnnotations := []string{ - fmt.Sprintf(common.AllowTagsOptionAnnotation, img.NormalizedSymbolicName()), + fmt.Sprintf(common.AllowTagsOptionAnnotation, img.normalizedSymbolicName()), common.ApplicationWideAllowTagsOptionAnnotation, } var allowTagsVal = "" @@ -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.OldMatchOptionAnnotation, 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.") @@ -182,7 +182,7 @@ 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 { pullSecretAnnotations := []string{ - fmt.Sprintf(common.PullSecretAnnotation, img.NormalizedSymbolicName()), + fmt.Sprintf(common.PullSecretAnnotation, img.normalizedSymbolicName()), common.ApplicationWidePullSecretAnnotation, } var pullSecretVal = "" @@ -208,7 +208,7 @@ 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 { ignoreTagsAnnotations := []string{ - fmt.Sprintf(common.IgnoreTagsOptionAnnotation, img.NormalizedSymbolicName()), + fmt.Sprintf(common.IgnoreTagsOptionAnnotation, img.normalizedSymbolicName()), common.ApplicationWideIgnoreTagsOptionAnnotation, } var ignoreTagsVal = "" @@ -242,7 +242,7 @@ func (img *ContainerImage) GetParameterIgnoreTags(annotations map[string]string) func (img *ContainerImage) GetPlatformOptions(annotations map[string]string, unrestricted bool) *options.ManifestOptions { logCtx := img.LogContext() var opts *options.ManifestOptions = options.NewManifestOptions() - key := fmt.Sprintf(common.PlatformsAnnotation, img.NormalizedSymbolicName()) + key := fmt.Sprintf(common.PlatformsAnnotation, img.normalizedSymbolicName()) val, ok := annotations[key] if !ok { if !unrestricted { @@ -291,6 +291,6 @@ func ParsePlatform(platformID string) (string, string, string, error) { return os, arch, variant, nil } -func (img *ContainerImage) NormalizedSymbolicName() string { +func (img *ContainerImage) normalizedSymbolicName() string { return strings.ReplaceAll(img.ImageAlias, "/", "_") } -- cgit v1.2.3 From 4a08ed6c733a7fa8c7809419e3301200771a4a96 Mon Sep 17 00:00:00 2001 From: Pasha Kostohrys Date: Wed, 29 May 2024 18:14:00 +0300 Subject: optimize code Signed-off-by: Pasha Kostohrys --- pkg/argocd/argocd.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/pkg/argocd/argocd.go b/pkg/argocd/argocd.go index 1a389e3..2603903 100644 --- a/pkg/argocd/argocd.go +++ b/pkg/argocd/argocd.go @@ -318,20 +318,17 @@ func getHelmParamNamesFromAnnotation(annotations map[string]string, img *image.C var annotationName, helmParamName, helmParamVersion string // Image spec is a full-qualified specifier, if we have it, we return early - param := img.GetParameterHelmImageSpec(annotations) - if param != "" { + if param := img.GetParameterHelmImageSpec(annotations); param != "" { log.Tracef("found annotation %s", annotationName) return strings.TrimSpace(param), "" } - param = img.GetParameterHelmImageName(annotations) - if param != "" { + if param := img.GetParameterHelmImageName(annotations); param != "" { log.Tracef("found annotation %s", annotationName) helmParamName = param } - param = img.GetParameterHelmImageTag(annotations) - if param != "" { + if param := img.GetParameterHelmImageTag(annotations); param != "" { log.Tracef("found annotation %s", annotationName) helmParamVersion = param } -- cgit v1.2.3 From f282927d72f890111297fd75eb64b53409c0223a Mon Sep 17 00:00:00 2001 From: Pasha Kostohrys Date: Wed, 29 May 2024 19:09:35 +0300 Subject: check if alias exist Signed-off-by: Pasha Kostohrys --- pkg/argocd/update.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/argocd/update.go b/pkg/argocd/update.go index 85dee36..0f1cab2 100644 --- a/pkg/argocd/update.go +++ b/pkg/argocd/update.go @@ -419,13 +419,18 @@ func marshalParamsOverride(app *v1alpha1.Application, originalData []byte) ([]by images := GetImagesAndAliasesFromApplication(app) for _, c := range images { + + if c.ImageAlias == "" { + continue + } + helmAnnotationParamName, helmAnnotationParamVersion := getHelmParamNamesFromAnnotation(app.Annotations, c) if helmAnnotationParamName == "" { - return nil, fmt.Errorf("could not find an image-name annotation for image %s", c.ImageAlias) + return nil, fmt.Errorf("could not find an image-name annotation for image %s", c.ImageName) } if helmAnnotationParamVersion == "" { - return nil, fmt.Errorf("could not find an image-tag annotation for image %s", c.ImageAlias) + return nil, fmt.Errorf("could not find an image-tag annotation for image %s", c.ImageName) } helmParamName := getHelmParam(appSource.Helm.Parameters, helmAnnotationParamName) -- cgit v1.2.3