Skip to content

Feature/allow empty helm.image-name annotation #1211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
23 changes: 12 additions & 11 deletions pkg/argocd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,18 @@ func marshalParamsOverride(app *v1alpha1.Application, originalData []byte) ([]by
helmAnnotationParamName, helmAnnotationParamVersion := getHelmParamNamesFromAnnotation(app.Annotations, c)

if helmAnnotationParamName == "" {
return nil, fmt.Errorf("could not find an image-name annotation for image %s", c.ImageName)
// allow empty image-name
log.Debugf("no image-name annotation found for image %s", c.ImageName)
} else {
helmParamName := getHelmParam(appSource.Helm.Parameters, helmAnnotationParamName)
if helmParamName == nil {
return nil, fmt.Errorf("%s parameter not found", helmAnnotationParamName)
}

err = setHelmValue(&helmNewValues, helmAnnotationParamName, helmParamName.Value)
if err != nil {
return nil, fmt.Errorf("failed to set image parameter name value: %v", err)
}
}
// for image-spec annotation, helmAnnotationParamName holds image-spec annotation value,
// and helmAnnotationParamVersion is empty
Expand All @@ -536,16 +547,6 @@ func marshalParamsOverride(app *v1alpha1.Application, originalData []byte) ([]by
return nil, fmt.Errorf("failed to set image parameter version value: %v", err)
}
}

helmParamName := getHelmParam(appSource.Helm.Parameters, helmAnnotationParamName)
if helmParamName == nil {
return nil, fmt.Errorf("%s parameter not found", helmAnnotationParamName)
}

err = setHelmValue(&helmNewValues, helmAnnotationParamName, helmParamName.Value)
if err != nil {
return nil, fmt.Errorf("failed to set image parameter name value: %v", err)
}
}

override, err = marshalWithIndent(&helmNewValues, defaultIndent)
Expand Down
30 changes: 21 additions & 9 deletions pkg/argocd/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1691,12 +1691,12 @@ replicas: 1
test-value1: one
nginx:
image:
tag: v1.0.0
name: nginx
tag: v1.0.0
redis:
image:
tag: v1.0.0
name: redis
tag: v1.0.0
`
yaml, err = marshalParamsOverride(&app, originalData)
require.NoError(t, err)
Expand Down Expand Up @@ -1938,7 +1938,7 @@ replicas: 1
"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-name": "dockerimage.name",
},
},
Spec: v1alpha1.ApplicationSpec{
Expand Down Expand Up @@ -1977,7 +1977,7 @@ replicas: 1
assert.Equal(t, "could not find an image-tag annotation for image nginx", err.Error())
})

t.Run("Missing annotation image-name for helmvalues write-back-target", func(t *testing.T) {
t.Run("Allow empty annotation image-name for helmvalues write-back-target", func(t *testing.T) {
app := v1alpha1.Application{
ObjectMeta: v1.ObjectMeta{
Name: "testapp",
Expand All @@ -1996,7 +1996,7 @@ replicas: 1
Parameters: []v1alpha1.HelmParameter{
{
Name: "image.name",
Value: "nginx",
Value: "nginx-other",
ForceString: true,
},
{
Expand All @@ -2018,10 +2018,22 @@ replicas: 1
},
}

originalData := []byte(`random: yaml`)
_, err := marshalParamsOverride(&app, originalData)
assert.Error(t, err)
assert.Equal(t, "could not find an image-name annotation for image nginx", err.Error())
originalData := []byte(`
image:
registry: docker.io
repository: nginx
tag: v0.0.0
`)
expected := `
image:
registry: docker.io
repository: nginx
tag: v1.0.0
`
yaml, err := marshalParamsOverride(&app, originalData)
assert.NoError(t, err)
assert.NotEmpty(t, yaml)
assert.Equal(t, strings.TrimSpace(strings.ReplaceAll(expected, "\t", " ")), strings.TrimSpace(string(yaml)))
})

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