Skip to content

Helm: fix runners.config template rendering

Viktor Oreshkin requested to merge stek29/gitlab-runner:main-patch-d468 into main

What does this MR do?

It makes runners.config tpl execute before escaping string for yaml, not after

Why was this MR needed?

Because currently some values of runners.config break with hard to debug errors:

  1. because toYaml breaks the template For example, if toYaml decides to quote the string, it will escape all quotes in the string, which will reduce an invalid go template.
  2. because tpl returns a string which is not valid for yaml For example, if spaces get stripped when rendering template

What's the best way to test this MR?

this config would break in the first way

runners:
  config: |
    # this line ends with trailing spaces  
    {{- printf "hello" -}}

error:

  Error: template: gitlab-runner/templates/deployment.yaml:28:31: executing "gitlab-runner/templates/deployment.yaml" at <include (print $.Template.BasePath "/configmap.yaml") .>: error calling include: template: gitlab-runner/templates/configmap.yaml:108:27: executing "gitlab-runner/templates/configmap.yaml" at <tpl (toYaml .Values.runners.config) $>: error calling tpl: error during tpl function execution for "\"# have a string with trailing space  \\n{{- printf \\\"hello\\\" -}}\\n\"": parse error at (gitlab-runner/templates/deployment.yaml:1): unexpected "\\" in operand

notice how {{ printf \"hello\" }} became {{- printf \"hello\" -}}, which is not a valid go template

this config would break in the second way

runners:
  config: |
    {{- printf "'" -}}

error:

COMBINED OUTPUT:
  Error: YAML parse error on gitlab-runner/templates/configmap.yaml: error converting YAML to JSON: yaml: line 77: did not find expected comment or line break
  Use --debug flag to render out invalid YAML

because {{- -}} strips spaces

What are the relevant issue numbers?

Originally reported in !237 (closed), implemented with an error in !290 (merged)

Edited by Viktor Oreshkin

Merge request reports