Skip to content

Helmfile in combination with transformers will modify JSON formatted strings and breaks the YAML file #2188

@pgmgb

Description

@pgmgb

We use Helmfile to render static YAML files out of Helm charts.
There, we also use transformers to manipulate some things inside the YAML's.

It seems, that Helmfile in combination with transformers somehow manipulates JSON strings inside the YAML's as seen in the example, which is from our side not intended...

Without transformers:

# helmfile.yaml
---
repositories:
  - name: kyverno
    url: https://kyverno.github.io/kyverno

releases:
  - name: "kyverno"
    chart: kyverno/kyverno
    version: 3.3.4

helmfile --file "helmfile.yaml" template --include-crds | yq e 'select(.kind == "ConfigMap" and .metadata.name == "kyverno")' -

(...)
updateRequestThreshold: "1000"
  webhooks: "\n  {\"namespaceSelector\":{\"matchExpressions\":[{\"key\":\"kubernetes.io/metadata.name\",\"operator\":\"NotIn\",\"values\":[\"kube-system\"]},{\"key\":\"kubernetes.io/metadata.name\",\"operator\":\"NotIn\",\"values\":[\"default\"]}],\"matchLabels\":null}}"
  webhookAnnotations: "{\"admissions.enforcer/disabled\":\"true\"}"
(...)

With transformers:

# helmfile.yaml
---
repositories:
  - name: kyverno
    url: https://kyverno.github.io/kyverno

releases:
  - name: "kyverno"
    chart: kyverno/kyverno
    version: 3.3.4
    transformers:
      - apiVersion: builtin
        kind: PatchTransformer
        metadata:
          name: remove-label-helm-sh-chart
        target:
          labelSelector: "helm.sh/chart"
        patch: |-
          - op: remove
            path: "/metadata/labels/helm.sh~1chart"

helmfile --file "helmfile.yaml" template --include-crds | yq e 'select(.kind == "ConfigMap" and .metadata.name == "kyverno")' -

(...)
webhookAnnotations: '{"admissions.enforcer/disabled":"true"}'
  webhooks:2-
      {"namespaceSelector":{"matchExpressions":[{"key":"kubernetes.io/metadata.name","operator":"NotIn","values":["kube-system"]},{"key":"kubernetes.io/metadata.name","operator":"NotIn","values":["default"]}],"matchLabels":null}}
kind: ConfigMap
(...)

As seen, the webhooks will change and breaks the YAML file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions