Skip to content

Commit 5644843

Browse files
will4jchengfang
authored andcommitted
feat: allow empty image-name annotation
Signed-off-by: William Wang <[email protected]>
1 parent cc9f71b commit 5644843

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
@@ -516,7 +516,18 @@ func marshalParamsOverride(app *v1alpha1.Application, originalData []byte) ([]by
516516
helmAnnotationParamName, helmAnnotationParamVersion := getHelmParamNamesFromAnnotation(app.Annotations, c)
517517

518518
if helmAnnotationParamName == "" {
519-
return nil, fmt.Errorf("could not find an image-name annotation for image %s", c.ImageName)
519+
// allow empty image-name
520+
fmt.Sprintf("no image-name annotation found for image %s", c.ImageName)
521+
} else {
522+
helmParamName := getHelmParam(appSource.Helm.Parameters, helmAnnotationParamName)
523+
if helmParamName == nil {
524+
return nil, fmt.Errorf("%s parameter not found", helmAnnotationParamName)
525+
}
526+
527+
err = setHelmValue(&helmNewValues, helmAnnotationParamName, helmParamName.Value)
528+
if err != nil {
529+
return nil, fmt.Errorf("failed to set image parameter name value: %v", err)
530+
}
520531
}
521532
// for image-spec annotation, helmAnnotationParamName holds image-spec annotation value,
522533
// and helmAnnotationParamVersion is empty
@@ -536,16 +547,6 @@ func marshalParamsOverride(app *v1alpha1.Application, originalData []byte) ([]by
536547
return nil, fmt.Errorf("failed to set image parameter version value: %v", err)
537548
}
538549
}
539-
540-
helmParamName := getHelmParam(appSource.Helm.Parameters, helmAnnotationParamName)
541-
if helmParamName == nil {
542-
return nil, fmt.Errorf("%s parameter not found", helmAnnotationParamName)
543-
}
544-
545-
err = setHelmValue(&helmNewValues, helmAnnotationParamName, helmParamName.Value)
546-
if err != nil {
547-
return nil, fmt.Errorf("failed to set image parameter name value: %v", err)
548-
}
549550
}
550551

551552
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)