roboll / helmfile

Deploy Kubernetes Helm Charts
MIT License
4.05k stars 565 forks source link

`indent` indents only the first line if there's no newline before it #1811

Open Temikus opened 3 years ago

Temikus commented 3 years ago

I'm not entirely sure why this occurs but I do want to understand what's happening here. It seems that the readFile macro is not working the same way depending on file content.

Observe the following release:

releases:
  - name: falcosidekick
    namespace: falco
    chart: falcosecurity/falcosidekick
    version: 0.3.3
    values:
      - podAnnotations:
        {{ readFile "templates/datadog_annotations.yaml" | indent 10 }}
      - replicaCount: 3
      - webui:
          enabled: true

With this template, everything works fine (with comment at the top, it can also be a simple space):

# Autodiscovery identifies containers by name, NOT image. It tries to match the id to .spec.containers[0].name
ad.datadoghq.com/falcosidekick.check_names: >-
  ["prometheus"]
ad.datadoghq.com/falcosidekick.init_configs: >-
  [{}]
ad.datadoghq.com/falcosidekick.instances: >-
  [
    {
      "prometheus_url": "http://%%host%%:2801/metrics",
      "namespace": "falco",
      "max_returned_metrics": 5000,
      "metrics": [{
        "falco_events": "events",
        "falcosidekick_inputs": "sidekick.inputs"
      }]
    }
  ]

If I remove the first comment, i.e.:

ad.datadoghq.com/falcosidekick.check_names: >-
  ["prometheus"]
ad.datadoghq.com/falcosidekick.init_configs: >-
  [{}]
ad.datadoghq.com/falcosidekick.instances: >-
  [
    {
      "prometheus_url": "http://%%host%%:2801/metrics",
      "namespace": "falco",
      "max_returned_metrics": 5000,
      "metrics": [{
        "falco_events": "events",
        "falcosidekick_inputs": "sidekick.inputs"
      }]
    }
  ]

, the template no longer builds:

λ helmfile diff                                                                                                                                                 (1)
in ./helmfile.yaml: failed to read helmfile.yaml: reading document at index 1: yaml: line 36: did not find expected key

Why could this happen? Is there a way to troubleshoot it somehow to understand what template it tries to build?

Thank you!

mumoshu commented 3 years ago

@Temikus Hey! Try nindent instead of indent. Also, running helmfile with --debug like helmfile --debug whatever would print the rendered helmfile.yaml, which should help you understand why your use of indent breaks when you have two or more annotations.

Temikus commented 3 years ago

It worked! Thank you so much @mumoshu ❤️

Looks like with indent (without a newline) only the first part of the template is indented 🤔

139:     values:
140:       - podAnnotations:
141:             ad.datadoghq.com/falcosidekick.check_names: >-
142:       ["prometheus"]
143:     ad.datadoghq.com/falcosidekick.init_configs: >-
144:       [{}]
Temikus commented 3 years ago

Reworded the issue to be closer to the original problem. If this is WAI - feel free to close :)

And thanks again for your help!