From 5644843a8172dc863fcfcf34f4863ac714aa1238 Mon Sep 17 00:00:00 2001 From: William Wang Date: Thu, 7 Aug 2025 21:09:06 +0800 Subject: [PATCH 1/4] feat: allow empty image-name annotation Signed-off-by: William Wang --- pkg/argocd/update.go | 23 ++++++++++++----------- pkg/argocd/update_test.go | 5 ++--- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/pkg/argocd/update.go b/pkg/argocd/update.go index 2cb7836f..12c5cbf3 100644 --- a/pkg/argocd/update.go +++ b/pkg/argocd/update.go @@ -516,7 +516,18 @@ func marshalParamsOverride(app *v1alpha1.Application, originalData []byte) ([]by helmAnnotationParamName, helmAnnotationParamVersion := getHelmParamNamesFromAnnotation(app.Annotations, c) if helmAnnotationParamName == "" { - return nil, fmt.Errorf("could not find an image-name annotation for image %s", c.ImageName) + // allow empty image-name + fmt.Sprintf("no image-name annotation found for image %s", c.ImageName) + } else { + helmParamName := getHelmParam(appSource.Helm.Parameters, helmAnnotationParamName) + if helmParamName == nil { + return nil, fmt.Errorf("%s parameter not found", helmAnnotationParamName) + } + + err = setHelmValue(&helmNewValues, helmAnnotationParamName, helmParamName.Value) + if err != nil { + return nil, fmt.Errorf("failed to set image parameter name value: %v", err) + } } // for image-spec annotation, helmAnnotationParamName holds image-spec annotation value, // and helmAnnotationParamVersion is empty @@ -536,16 +547,6 @@ func marshalParamsOverride(app *v1alpha1.Application, originalData []byte) ([]by return nil, fmt.Errorf("failed to set image parameter version value: %v", err) } } - - helmParamName := getHelmParam(appSource.Helm.Parameters, helmAnnotationParamName) - if helmParamName == nil { - return nil, fmt.Errorf("%s parameter not found", helmAnnotationParamName) - } - - err = setHelmValue(&helmNewValues, helmAnnotationParamName, helmParamName.Value) - if err != nil { - return nil, fmt.Errorf("failed to set image parameter name value: %v", err) - } } override, err = marshalWithIndent(&helmNewValues, defaultIndent) diff --git a/pkg/argocd/update_test.go b/pkg/argocd/update_test.go index bc565876..27d647e8 100644 --- a/pkg/argocd/update_test.go +++ b/pkg/argocd/update_test.go @@ -1977,7 +1977,7 @@ replicas: 1 assert.Equal(t, "could not find an image-tag annotation for image nginx", err.Error()) }) - t.Run("Missing annotation image-name for helmvalues write-back-target", func(t *testing.T) { + t.Run("Allow empty annotation image-name for helmvalues write-back-target", func(t *testing.T) { app := v1alpha1.Application{ ObjectMeta: v1.ObjectMeta{ Name: "testapp", @@ -2020,8 +2020,7 @@ replicas: 1 originalData := []byte(`random: yaml`) _, err := marshalParamsOverride(&app, originalData) - assert.Error(t, err) - assert.Equal(t, "could not find an image-name annotation for image nginx", err.Error()) + assert.NoError(t, err) }) t.Run("Image-name annotation value not found in Helm source parameters list", func(t *testing.T) { From b73da1b74e24d870e66b1adea2dec0b5858d5a70 Mon Sep 17 00:00:00 2001 From: William Wang Date: Sat, 9 Aug 2025 10:49:19 +0800 Subject: [PATCH 2/4] feat: use log instead of print Signed-off-by: William Wang --- pkg/argocd/update.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/argocd/update.go b/pkg/argocd/update.go index 12c5cbf3..cfb251b1 100644 --- a/pkg/argocd/update.go +++ b/pkg/argocd/update.go @@ -517,7 +517,7 @@ func marshalParamsOverride(app *v1alpha1.Application, originalData []byte) ([]by if helmAnnotationParamName == "" { // allow empty image-name - fmt.Sprintf("no image-name annotation found for image %s", c.ImageName) + log.Debugf("no image-name annotation found for image %s", c.ImageName) } else { helmParamName := getHelmParam(appSource.Helm.Parameters, helmAnnotationParamName) if helmParamName == nil { From 80ceba2f7cad0cfba23f1117df7cbb9f3c52cd68 Mon Sep 17 00:00:00 2001 From: William Wang Date: Sat, 9 Aug 2025 11:35:05 +0800 Subject: [PATCH 3/4] test: fix unstable unit tests Signed-off-by: William Wang --- pkg/argocd/update_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/argocd/update_test.go b/pkg/argocd/update_test.go index 27d647e8..408fbf0d 100644 --- a/pkg/argocd/update_test.go +++ b/pkg/argocd/update_test.go @@ -1691,12 +1691,12 @@ replicas: 1 test-value1: one nginx: image: - tag: v1.0.0 name: nginx + tag: v1.0.0 redis: image: - tag: v1.0.0 name: redis + tag: v1.0.0 ` yaml, err = marshalParamsOverride(&app, originalData) require.NoError(t, err) @@ -1938,7 +1938,7 @@ replicas: 1 "argocd-image-updater.argoproj.io/image-list": "nginx", "argocd-image-updater.argoproj.io/write-back-method": "git", "argocd-image-updater.argoproj.io/write-back-target": "helmvalues:./test-values.yaml", - "argocd-image-updater.argoproj.io/nginx.helm.image-name": "image.name", + "argocd-image-updater.argoproj.io/nginx.helm.image-name": "dockerimage.name", }, }, Spec: v1alpha1.ApplicationSpec{ From 334f57530d08960d6734c23cd95887542bbc6511 Mon Sep 17 00:00:00 2001 From: William Wang Date: Fri, 15 Aug 2025 17:02:58 +0800 Subject: [PATCH 4/4] test: compare content of helm values without image-name annotation Signed-off-by: William Wang --- pkg/argocd/update_test.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/pkg/argocd/update_test.go b/pkg/argocd/update_test.go index 408fbf0d..97cfe8cf 100644 --- a/pkg/argocd/update_test.go +++ b/pkg/argocd/update_test.go @@ -1996,7 +1996,7 @@ replicas: 1 Parameters: []v1alpha1.HelmParameter{ { Name: "image.name", - Value: "nginx", + Value: "nginx-other", ForceString: true, }, { @@ -2018,9 +2018,22 @@ replicas: 1 }, } - originalData := []byte(`random: yaml`) - _, err := marshalParamsOverride(&app, originalData) + originalData := []byte(` +image: + registry: docker.io + repository: nginx + tag: v0.0.0 +`) + expected := ` +image: + registry: docker.io + repository: nginx + tag: v1.0.0 +` + yaml, err := marshalParamsOverride(&app, originalData) assert.NoError(t, err) + assert.NotEmpty(t, yaml) + assert.Equal(t, strings.TrimSpace(strings.ReplaceAll(expected, "\t", " ")), strings.TrimSpace(string(yaml))) }) t.Run("Image-name annotation value not found in Helm source parameters list", func(t *testing.T) {