Skip to content

Commit cc9f71b

Browse files
authored
Feature/allow no exists helmvalues file (#1212)
Signed-off-by: William Wang <[email protected]>
1 parent e6c82f2 commit cc9f71b

File tree

2 files changed

+67
-4
lines changed

2 files changed

+67
-4
lines changed

pkg/argocd/update.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -485,10 +485,27 @@ func marshalParamsOverride(app *v1alpha1.Application, originalData []byte) ([]by
485485
if strings.HasPrefix(app.Annotations[common.WriteBackTargetAnnotation], common.HelmPrefix) {
486486
images := GetImagesAndAliasesFromApplication(app)
487487

488-
helmNewValues := yaml.Node{}
489-
err = yaml.Unmarshal(originalData, &helmNewValues)
490-
if err != nil {
491-
return nil, err
488+
var helmNewValues yaml.Node
489+
if len(originalData) == 0 {
490+
// allow non-exists target file
491+
helmNewValues = yaml.Node{
492+
Kind: yaml.DocumentNode,
493+
HeadComment: "auto generated by argocd image updater",
494+
Content: []*yaml.Node{
495+
{
496+
Kind: yaml.MappingNode,
497+
Tag: "!!map",
498+
Content: []*yaml.Node{},
499+
Style: yaml.LiteralStyle,
500+
},
501+
},
502+
}
503+
} else {
504+
helmNewValues = yaml.Node{}
505+
err = yaml.Unmarshal(originalData, &helmNewValues)
506+
if err != nil {
507+
return nil, err
508+
}
492509
}
493510

494511
for _, c := range images {

pkg/argocd/update_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2166,6 +2166,52 @@ replicas: 1
21662166
assert.Error(t, err)
21672167
})
21682168

2169+
t.Run("Nil source merge for Helm source with Helm values file", func(t *testing.T) {
2170+
app := v1alpha1.Application{
2171+
ObjectMeta: v1.ObjectMeta{
2172+
Name: "testapp",
2173+
Annotations: map[string]string{
2174+
"argocd-image-updater.argoproj.io/image-list": "nginx",
2175+
"argocd-image-updater.argoproj.io/write-back-method": "git",
2176+
"argocd-image-updater.argoproj.io/write-back-target": "helmvalues:./test-values.yaml",
2177+
"argocd-image-updater.argoproj.io/nginx.helm.image-name": "image.name",
2178+
"argocd-image-updater.argoproj.io/nginx.helm.image-tag": "image.tag",
2179+
},
2180+
},
2181+
Spec: v1alpha1.ApplicationSpec{
2182+
Source: &v1alpha1.ApplicationSource{
2183+
RepoURL: "https://example.com/example",
2184+
TargetRevision: "main",
2185+
Helm: &v1alpha1.ApplicationSourceHelm{
2186+
Parameters: []v1alpha1.HelmParameter{
2187+
{
2188+
Name: "image.name",
2189+
Value: "nginx",
2190+
ForceString: true,
2191+
},
2192+
{
2193+
Name: "image.tag",
2194+
Value: "v1.0.0",
2195+
ForceString: true,
2196+
},
2197+
},
2198+
},
2199+
},
2200+
},
2201+
Status: v1alpha1.ApplicationStatus{
2202+
SourceType: v1alpha1.ApplicationSourceTypeHelm,
2203+
Summary: v1alpha1.ApplicationSummary{
2204+
Images: []string{
2205+
"nginx:v0.0.0",
2206+
},
2207+
},
2208+
},
2209+
}
2210+
2211+
_, err := marshalParamsOverride(&app, nil)
2212+
assert.NoError(t, err)
2213+
})
2214+
21692215
t.Run("Unknown source", func(t *testing.T) {
21702216
app := v1alpha1.Application{
21712217
ObjectMeta: v1.ObjectMeta{

0 commit comments

Comments
 (0)