diff --git a/pkg/argocd/update.go b/pkg/argocd/update.go index 2cb7836f..cfb251b1 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 + log.Debugf("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..97cfe8cf 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{ @@ -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", @@ -1996,7 +1996,7 @@ replicas: 1 Parameters: []v1alpha1.HelmParameter{ { Name: "image.name", - Value: "nginx", + Value: "nginx-other", ForceString: true, }, { @@ -2018,10 +2018,22 @@ 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()) + 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) {