Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions pkg/argocd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,10 +485,27 @@ func marshalParamsOverride(app *v1alpha1.Application, originalData []byte) ([]by
if strings.HasPrefix(app.Annotations[common.WriteBackTargetAnnotation], common.HelmPrefix) {
images := GetImagesAndAliasesFromApplication(app)

helmNewValues := yaml.Node{}
err = yaml.Unmarshal(originalData, &helmNewValues)
if err != nil {
return nil, err
var helmNewValues yaml.Node
if len(originalData) == 0 {
// allow non-exists target file
helmNewValues = yaml.Node{
Kind: yaml.DocumentNode,
HeadComment: "auto generated by argocd image updater",
Content: []*yaml.Node{
{
Kind: yaml.MappingNode,
Tag: "!!map",
Content: []*yaml.Node{},
Style: yaml.LiteralStyle,
},
},
}
} else {
helmNewValues = yaml.Node{}
err = yaml.Unmarshal(originalData, &helmNewValues)
if err != nil {
return nil, err
}
}

for _, c := range images {
Expand Down
46 changes: 46 additions & 0 deletions pkg/argocd/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2166,6 +2166,52 @@ replicas: 1
assert.Error(t, err)
})

t.Run("Nil source merge for Helm source with Helm values file", func(t *testing.T) {
app := v1alpha1.Application{
ObjectMeta: v1.ObjectMeta{
Name: "testapp",
Annotations: map[string]string{
"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-tag": "image.tag",
},
},
Spec: v1alpha1.ApplicationSpec{
Source: &v1alpha1.ApplicationSource{
RepoURL: "https://example.com/example",
TargetRevision: "main",
Helm: &v1alpha1.ApplicationSourceHelm{
Parameters: []v1alpha1.HelmParameter{
{
Name: "image.name",
Value: "nginx",
ForceString: true,
},
{
Name: "image.tag",
Value: "v1.0.0",
ForceString: true,
},
},
},
},
},
Status: v1alpha1.ApplicationStatus{
SourceType: v1alpha1.ApplicationSourceTypeHelm,
Summary: v1alpha1.ApplicationSummary{
Images: []string{
"nginx:v0.0.0",
},
},
},
}

_, err := marshalParamsOverride(&app, nil)
assert.NoError(t, err)
})

t.Run("Unknown source", func(t *testing.T) {
app := v1alpha1.Application{
ObjectMeta: v1.ObjectMeta{
Expand Down