bitnami / charts

Bitnami Helm Charts
https://bitnami.com
Other
8.66k stars 9.01k forks source link

[bitnami/common] helm lint fail #27835

Closed yanover closed 1 week ago

yanover commented 2 weeks ago

Name and Version

bitnami/common:2.20.3

What architecture are you using?

arm64

What steps will reproduce the bug?

We use the bitnami/postgresql chart as a subchart in our codebase.

In our CI, we run the command :

 helm lint --strict --with-subcharts --quiet --values values.yaml

This command is executed from the root of the postgresql parent chart.

In your helper :

{{- define "common.images.image" -}}
{{- $registryName := default .imageRoot.registry ((.global).imageRegistry) -}}
{{- $repositoryName := .imageRoot.repository -}}
{{- $separator := ":" -}}
{{- $termination := .imageRoot.tag | toString -}}

{{- if .imageRoot.digest }}
    {{- $separator = "@" -}}
    {{- $termination = .imageRoot.digest | toString -}}
{{- end -}}
{{- if $registryName }}
    {{- printf "%s/%s%s%s" $registryName $repositoryName $separator $termination -}}
{{- else -}}
    {{- printf "%s%s%s" $repositoryName $separator $termination -}}
{{- end -}}
{{- end -}}

As I understand it, when the --with-subcharts flag is used, the parent's values file is passed to the postgresql chart during linting.

This poses a problem because in some of our charts, we also use the image key, but not necessarily the tag key (we refer to the appVersion value in the chart.yaml.

This makes the linting to fail because the tag is empty ..

[ERROR] templates/primary/statefulset.yaml: unable to parse YAML: error converting YAML to JSON: yaml: line 63: mapping values are not allowed in this context

Reproduction of the problem

  1. Create a chart
    • helm create yolo
  2. Download the subchart
    • cd yolo/charts && helm pull oci://registry-1.docker.io/bitnamicharts/postgresql --untar
  3. Run helm lint from the parent
    • cd .. && helm lint --strict --with-subcharts --quiet --values values.yaml

What is the expected behavior?

The helper should not fail if the tag value is empty or unspecified.

The "latest" tag or no tag should be assigned after the registry.

What do you see instead?

[ERROR] templates/primary/statefulset.yaml: unable to parse YAML: error converting YAML to JSON: yaml: line 63: mapping values are not allowed in this context

Additional information

This is how I resolved the problem :

Return the proper image name
{{ include "common.images.image" ( dict "imageRoot" .Values.path.to.the.image "global" .Values.global ) }}
*/}}
{{- define "common.images.image" -}}
{{- $registryName := default .imageRoot.registry ((.global).imageRegistry) -}}
{{- $repositoryName := .imageRoot.repository -}}
{{- $separator := ":" -}}
{{- $termination := .imageRoot.tag | default "latest" | toString -}}         <-- Using default here

{{- if .imageRoot.digest }}
    {{- $separator = "@" -}}
    {{- $termination = .imageRoot.digest | toString -}}
{{- end -}}
{{- if $registryName }}
    {{- printf "%s/%s%s%s" $registryName $repositoryName $separator $termination -}}
{{- else -}}
    {{- printf "%s%s%s"  $repositoryName $separator $termination -}}
{{- end -}}
{{- end -}}

I can propose a fix upstream but first I wanted to share this problem in a dedicated issue and get your opinion.

Thanks in advance.

carrodher commented 1 week ago

Thank you for bringing this issue to our attention. We appreciate your involvement! If you're interested in contributing a solution, we welcome you to create a pull request. The Bitnami team is excited to review your submission and offer feedback. You can find the contributing guidelines here.

Your contribution will greatly benefit the community. Feel free to reach out if you have any questions or need assistance.

fmulero commented 1 week ago

Thanks a lot @yanover for using bitnami/charts !

This helm issue https://github.com/helm/helm/issues/12798 fits with what your are facing. It seems the values are not being evaluated as in the install or template commands. In my opinion this problem should be fixed in the helm side.

As workaround, if you want to run the linter taking care of dependencies, you could use helm template | helm lint.

yanover commented 1 week ago

Thank you for your answers and clarifications !

We also think that this problem stems directly from the helm lint command itself.

For the moment we've fixed the helper locally and we're waiting for the rest from helm.

At the same time, we've added the tool Chart-testing to our CI, which seems to be a good candidate for solving this problem.

Thank you again, I believe we may close this issue 👍