Repository: argoproj-labs/argocd-image-updater

Issue:
helmvalues not working properly
**Describe the bug**
With v1.0.0, when using writeBackConfig.gitConfig.writeBackTarget set to helmvalues, Argo CD Image Updater commits a file containing Argo CD Helm parameters (helm.parameters with forcestring fields) instead of a plain Helm values YAML file. This is a regression: older versions produced a regular values.yaml consumable via Application.spec.sources[n].helm.valueFiles.
Concretely, the committed file looks like this (actual output):

`helm:
  parameters:
  - name: image-updater/api.image.name
    value: api
    forcestring: true
  - name: Module.api.image.tag
    value: main@sha256:fa066ecd309f64f6c821e0342bd1f05b92e23a4e5a640d5bfedc4e618ff9acde
    forcestring: true@argocd-image-updater`

This is not a Helm values file and cannot be referenced from Argo CD as a values file.

**To Reproduce**
Deploy Argo CD Image Updater v1.0.0.
Create an ImageUpdater CR with:
spec.writeBackConfig.method: git
spec.writeBackConfig.gitConfig.writeBackTarget: helmvalues:/abc/versions1.yaml
A Helm application with ManifestTargets (helm name/tag) such as:
name: image-updater/api.image.name
tag: Module.api.image.tag
Ensure a new image is available to trigger an update (e.g., update a digest).
Observe the commit in the target repo: the file contains helm.parameters instead of a plain values.yaml.


**Expected behavior**
When writeBackTarget starts with helmvalues:, the updater should commit a plain Helm values YAML file setting the configured keys, e.g.:
```yaml
image-updater:
  api:
    image:
      name: api
Module:
  api:
    image:
      tag: main@sha256:fa066ecd309f64f6c821e0342bd1f05b92e23a4e5a640d5bfedc4e618ff9acde
```

**Version**
1.0.0



Discussion:
@chengfang: In https://github.com/argoproj-labs/argocd-image-updater/blob/7320a5546db9241590a9e3cedfebdabbeacb3962/pkg/argocd/update.go#L775 , we strip away the leading 'helmvalues:' part and save the target file path as `wbc.Target`. Later when writing to the target in https://github.com/argoproj-labs/argocd-image-updater/blob/7320a5546db9241590a9e3cedfebdabbeacb3962/pkg/argocd/update.go#L382 , we check if the target starts with 'helmvalues' (already removed so will never be true). So the helmvalues writing part is bypassed.@dkarpele: Previously this code line looked like:
```
		if strings.HasPrefix(app.Annotations[common.WriteBackTargetAnnotation], common.HelmPrefix) {
```

Solution patch:
diff --git a/pkg/argocd/argocd.go b/pkg/argocd/argocd.go
index 00b749f..4e67c10 100644
--- a/pkg/argocd/argocd.go
+++ b/pkg/argocd/argocd.go
@@ -890,7 +890,7 @@ func getApplicationType(app *argocdapi.Application, wbc *WriteBackConfig) Applic
 // getApplicationSourceType returns the source type of the application
 func getApplicationSourceType(app *argocdapi.Application, wbc *WriteBackConfig) argocdapi.ApplicationSourceType {
 	if wbc != nil {
-		if target := wbc.Target; strings.HasPrefix(target, common.KustomizationPrefix) {
+		if wbc.KustomizeBase != "" {
 			return argocdapi.ApplicationSourceTypeKustomize
 		}
 	}
diff --git a/pkg/argocd/update.go b/pkg/argocd/update.go
index 17dfe97..90c5d16 100644
--- a/pkg/argocd/update.go
+++ b/pkg/argocd/update.go
@@ -379,7 +379,7 @@ func marshalParamsOverride(ctx context.Context, applicationImages *ApplicationIm
 			return []byte{}, nil
 		}
 
-		if wbc != nil && strings.HasPrefix(wbc.Target, common.HelmPrefix) {
+		if wbc != nil && !strings.HasPrefix(filepath.Base(wbc.Target), common.DefaultTargetFilePrefix) {
 			images := GetImagesAndAliasesFromApplication(applicationImages)
 
 			var helmNewValues yaml.Node
diff --git a/pkg/common/constants.go b/pkg/common/constants.go
index df67011..da3102c 100644
--- a/pkg/common/constants.go
+++ b/pkg/common/constants.go
@@ -18,6 +18,9 @@ const (
 	DefaultHelmImageTag  = "image.tag"
 )
 
+// DefaultTargetFilePrefix the prefix of the default git write-back target
+const DefaultTargetFilePrefix = ".argocd-source-"
+
 // DefaultTargetFilePattern configurations related to the write-back functionality
 const DefaultTargetFilePattern = ".argocd-source-%s_%s.yaml"
 const DefaultTargetFilePatternWithoutNamespace = ".argocd-source-%s.yaml"



Test patch:
diff --git a/pkg/argocd/argocd_test.go b/pkg/argocd/argocd_test.go
index 5cea4ea..a298499 100644
--- a/pkg/argocd/argocd_test.go
+++ b/pkg/argocd/argocd_test.go
@@ -221,7 +221,7 @@ func Test_GetApplicationType(t *testing.T) {
 		}
 		// Create a WriteBackConfig with kustomization target to test the logic
 		wbc := &WriteBackConfig{
-			Target: "kustomization:.",
+			KustomizeBase: ".",
 		}
 		appType := GetApplicationType(application, wbc)
 		assert.Equal(t, ApplicationTypeKustomize, appType)
@@ -302,7 +302,7 @@ func Test_GetApplicationSourceType(t *testing.T) {
 
 		// Create a WriteBackConfig with kustomization target to test the logic
 		wbc := &WriteBackConfig{
-			Target: "kustomization:.",
+			KustomizeBase: ".",
 		}
 
 		appType := GetApplicationSourceType(application, wbc)
diff --git a/pkg/argocd/update_test.go b/pkg/argocd/update_test.go
index 2d05f44..bd38be3 100644
--- a/pkg/argocd/update_test.go
+++ b/pkg/argocd/update_test.go
@@ -1617,7 +1617,7 @@ replicas: 1
 			Application: app,
 			Images:      ImageList{im},
 			WriteBackConfig: &WriteBackConfig{
-				Target: "helmvalues:./test-values.yaml",
+				Target: "./test-values.yaml",
 			},
 		}
 
@@ -1672,7 +1672,7 @@ replicas: 1
 			Application: app,
 			Images:      ImageList{im},
 			WriteBackConfig: &WriteBackConfig{
-				Target: "helmvalues:./test-values.yaml",
+				Target: "./test-values.yaml",
 			},
 		}
 
@@ -1782,7 +1782,7 @@ replicas: 1
 			Application: app,
 			Images:      ImageList{imNginx, imRedis},
 			WriteBackConfig: &WriteBackConfig{
-				Target: "helmvalues:./test-values.yaml",
+				Target: "./test-values.yaml",
 			},
 		}
 
@@ -1913,7 +1913,7 @@ replicas: 1
 			Application: app,
 			Images:      ImageList{imFoo, imBar, imBbb},
 			WriteBackConfig: &WriteBackConfig{
-				Target: "helmvalues:./test-values.yaml",
+				Target: "./test-values.yaml",
 			},
 		}
 
@@ -1981,7 +1981,7 @@ replicas: 1
 			Application: app,
 			Images:      ImageList{im},
 			WriteBackConfig: &WriteBackConfig{
-				Target: "helmvalues:./test-values.yaml",
+				Target: "./test-values.yaml",
 			},
 		}
 
@@ -2046,7 +2046,7 @@ replicas: 1
 			Application: app,
 			Images:      ImageList{im},
 			WriteBackConfig: &WriteBackConfig{
-				Target: "helmvalues:./test-values.yaml",
+				Target: "./test-values.yaml",
 			},
 		}
 
@@ -2100,7 +2100,7 @@ replicas: 1
 			Application: app,
 			Images:      ImageList{im},
 			WriteBackConfig: &WriteBackConfig{
-				Target: "helmvalues:./test-values.yaml",
+				Target: "./test-values.yaml",
 			},
 		}
 
@@ -2152,7 +2152,7 @@ replicas: 1
 			Application: app,
 			Images:      ImageList{im},
 			WriteBackConfig: &WriteBackConfig{
-				Target: "helmvalues:./test-values.yaml",
+				Target: "./test-values.yaml",
 			},
 		}
 
@@ -2205,7 +2205,7 @@ replicas: 1
 			Application: app,
 			Images:      ImageList{im},
 			WriteBackConfig: &WriteBackConfig{
-				Target: "helmvalues:./test-values.yaml",
+				Target: "./test-values.yaml",
 			},
 		}
 
@@ -2257,7 +2257,7 @@ replicas: 1
 			Application: app,
 			Images:      ImageList{im},
 			WriteBackConfig: &WriteBackConfig{
-				Target: "helmvalues:./test-values.yaml",
+				Target: "./test-values.yaml",
 			},
 		}
 
@@ -2311,7 +2311,7 @@ replicas: 1
 			Images:      ImageList{im},
 			WriteBackConfig: &WriteBackConfig{
 				Method: WriteBackGit,
-				Target: "helmvalues:./test-values.yaml",
+				Target: "./test-values.yaml",
 			},
 		}
 
@@ -2362,7 +2362,7 @@ replicas: 1
 			Images:      ImageList{im},
 			WriteBackConfig: &WriteBackConfig{
 				Method: WriteBackGit,
-				Target: "helmvalues:./test-values.yaml",
+				Target: "./test-values.yaml",
 			},
 		}
 		_, err := marshalParamsOverride(context.Background(), applicationImages, nil)
@@ -2469,7 +2469,7 @@ nginx:
 			Application: app,
 			Images:      ImageList{im},
 			WriteBackConfig: &WriteBackConfig{
-				Target: "helmvalues:./test-values.yaml",
+				Target: "./test-values.yaml",
 			},
 		}
 		yaml, err := marshalParamsOverride(context.Background(), applicationImages, originalData)
@@ -2537,7 +2537,7 @@ replicas: 1
 			Images:      ImageList{im},
 			WriteBackConfig: &WriteBackConfig{
 				Method: WriteBackGit,
-				Target: "helmvalues:./test-values.yaml",
+				Target: "./test-values.yaml",
 			},
 		}
 
@@ -2604,7 +2604,7 @@ replicas: 1
 			Images:      ImageList{im},
 			WriteBackConfig: &WriteBackConfig{
 				Method: WriteBackGit,
-				Target: "helmvalues:./test-values.yaml",
+				Target: "./test-values.yaml",
 			},
 		}
 
@@ -2673,7 +2673,7 @@ replicas: 1
 			Images:      ImageList{im},
 			WriteBackConfig: &WriteBackConfig{
 				Method: WriteBackGit,
-				Target: "helmvalues:./test-values.yaml",
+				Target: "./test-values.yaml",
 			},
 		}