Skip to content

ServiceMonitor template produces invalid YAML due to indent vs nindent in azure-resourcemanager-exporter v 26.1.0 #114

Description

@leandrohinz

Bug description

Enabling prometheus.monitor.enabled: true on the azure-resourcemanager-exporter chart
(tested with chart 1.3.6, appVersion 26.1.0) makes helm template fail with:

error converting YAML to JSON: yaml: line 6: mapping values are not allowed in this context

Root cause

charts/azure-resourcemanager-exporter/templates/prometheus/servicemonitor.yaml line 8:

labels: {{ include "azure-resourcemanager-exporter.labels" . | indent 4 }}

uses indent 4 instead of nindent 4. Every other template in this same chart
(deployment.yaml, networkpolicy.yaml) correctly uses nindent 4 for the same helper.

This line has actually been broken since 1.2.3 too, but it "accidentally" worked because
_helpers.tpl used to define the label block without trimming the trailing whitespace:

{{- define "azure-resourcemanager-exporter.labels" }}     # chart <= 1.2.3

so the include's output began with a newline, which made indent behave like nindent.

Starting in chart 1.3.0, the define was changed to trim trailing whitespace:

{{- define "azure-resourcemanager-exporter.labels" -}}    # chart >= 1.3.0

which removed that leading newline and exposed the pre-existing indent/nindent bug —
so any chart >= 1.3.0 with prometheus.monitor.enabled: true fails to render.

Steps to reproduce

helm repo add webdevops https://webdevops.github.io/helm-charts/
helm repo update
helm template test webdevops/azure-resourcemanager-exporter \
  --version 1.3.6 \
  --set prometheus.monitor.enabled=true

Expected

Valid YAML manifest for the ServiceMonitor.

Suggested fix

-  labels: {{ include "azure-resourcemanager-exporter.labels" . | indent 4 }}
+  labels: {{- include "azure-resourcemanager-exporter.labels" . | nindent 4 }}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions