Skip to content

Commit d42bcb9

Browse files
committed
feat: allow empty image-name annotation
Signed-off-by: William Wang <[email protected]>
1 parent e816c49 commit d42bcb9

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

pkg/argocd/update.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,18 @@ func marshalParamsOverride(app *v1alpha1.Application, originalData []byte) ([]by
499499
helmAnnotationParamName, helmAnnotationParamVersion := getHelmParamNamesFromAnnotation(app.Annotations, c)
500500

501501
if helmAnnotationParamName == "" {
502-
return nil, fmt.Errorf("could not find an image-name annotation for image %s", c.ImageName)
502+
// allow empty image-name
503+
fmt.Sprintf("no image-name annotation found for image %s", c.ImageName)
504+
} else {
505+
helmParamName := getHelmParam(appSource.Helm.Parameters, helmAnnotationParamName)
506+
if helmParamName == nil {
507+
return nil, fmt.Errorf("%s parameter not found", helmAnnotationParamName)
508+
}
509+
510+
err = setHelmValue(&helmNewValues, helmAnnotationParamName, helmParamName.Value)
511+
if err != nil {
512+
return nil, fmt.Errorf("failed to set image parameter name value: %v", err)
513+
}
503514
}
504515
// for image-spec annotation, helmAnnotationParamName holds image-spec annotation value,
505516
// and helmAnnotationParamVersion is empty
@@ -519,16 +530,6 @@ func marshalParamsOverride(app *v1alpha1.Application, originalData []byte) ([]by
519530
return nil, fmt.Errorf("failed to set image parameter version value: %v", err)
520531
}
521532
}
522-
523-
helmParamName := getHelmParam(appSource.Helm.Parameters, helmAnnotationParamName)
524-
if helmParamName == nil {
525-
return nil, fmt.Errorf("%s parameter not found", helmAnnotationParamName)
526-
}
527-
528-
err = setHelmValue(&helmNewValues, helmAnnotationParamName, helmParamName.Value)
529-
if err != nil {
530-
return nil, fmt.Errorf("failed to set image parameter name value: %v", err)
531-
}
532533
}
533534

534535
override, err = marshalWithIndent(&helmNewValues, defaultIndent)

pkg/argocd/update_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,7 +1977,7 @@ replicas: 1
19771977
assert.Equal(t, "could not find an image-tag annotation for image nginx", err.Error())
19781978
})
19791979

1980-
t.Run("Missing annotation image-name for helmvalues write-back-target", func(t *testing.T) {
1980+
t.Run("Allow empty annotation image-name for helmvalues write-back-target", func(t *testing.T) {
19811981
app := v1alpha1.Application{
19821982
ObjectMeta: v1.ObjectMeta{
19831983
Name: "testapp",
@@ -2020,8 +2020,7 @@ replicas: 1
20202020

20212021
originalData := []byte(`random: yaml`)
20222022
_, err := marshalParamsOverride(&app, originalData)
2023-
assert.Error(t, err)
2024-
assert.Equal(t, "could not find an image-name annotation for image nginx", err.Error())
2023+
assert.NoError(t, err)
20252024
})
20262025

20272026
t.Run("Image-name annotation value not found in Helm source parameters list", func(t *testing.T) {

0 commit comments

Comments
 (0)