Skip to content

Refactor {{ toYaml to {{- toYaml so that we remove empty newlines

The following discussion from !362 (merged) should be addressed:

  • @Alexand started a discussion:

    non-blocking follow-up

    I see this is a copy/paste from our any of our usages of toYaml.

    We should have added {{- everywhere instead of {{. It shouldn't break the indentation, and it will fix this extra newline being added everywhere. See what happens for securityContext and the preexisting resources for instance:

    ➜  auto-deploy-app git:(auto-deploy-image-add-containerSecurityContext) helm template --set cronjobs.job1.containerSecurityContext.runAsUser=1000,cronjobs.job1.containerSecurityContext.runAsGroup=3000 --set resources=foo=bar . | grep -A10 securityContext
                  securityContext:
    
                    runAsGroup: 3000
                    runAsUser: 1000
                  resources:
    
                    foo=bar

We have been using an undocumented standard where the next template line removes any newlines by adding {{- at the beginning of the lines. For some reason, maybe we thought it would break toYaml indentation, we have added the - to these calls and only called {{- toYaml. So every {{- toYaml call has an empty newline before it.

Implementation Guide

  • Refactor all usages of {{ toYaml to {{- to Yaml.
  • Make sure all is tested