helm chart error: could not find expected ':'

11/30/2020

I am getting the below error while executing the helm chart.

Error: YAML parse error on helmcharts/templates/route.yaml: error converting YAML to JSON: yaml: line 25: could not find expected ':'

The chart works fine if I remove the multiline string "|-" from the Values.yaml file while referring the certificate to route.yaml. Since I remove "|-" the cert contents are not preserved with proper indentation while it's copied to route.yaml and the route fail to create.

    key:   <--- works if I don't provide multiline "|-"
      -----BEGIN CERTIFICATE-----
      [...]
      -----END CERTIFICATE-----
    certificate:
      -----BEGIN CERTIFICATE-----
      [...]
      -----END CERTIFICATE-----
    caCertificate:
      -----BEGIN CERTIFICATE-----
      [...]
      -----END CERTIFICATE-----

How I can solve this issue? Is it a proper way to provide the cert content in values.yaml file and passing it route.yaml. In the case of Ingress, it's pretty simple just creating a tls secret object and passing the filename in values.yaml but how can we achieve the same in openshift route?

Values.yaml

route:
  Enabled: true
  annotations:
    haproxy.router.openshift.io/cookie_name: SESSION_XLD
    haproxy.router.openshift.io/disable_cookies: "false"
    haproxy.router.openshift.io/rewrite-target: /
  path: /
  hosts:
    - www.example.com
  tls:
    key: |-       <--- Doesn't work if i provide this "|-"
      -----BEGIN CERTIFICATE-----
      [...]
      -----END CERTIFICATE-----
    certificate: |- <--- Doesn't work if I provide this "|-"
      -----BEGIN CERTIFICATE-----
      [...]
      -----END CERTIFICATE-----
    caCertificate: |- <--- Doesn't work if i provide this "|-"
      -----BEGIN CERTIFICATE-----
      [...]
      -----END CERTIFICATE-----
    insecureEdgeTerminationPolicy: Redirect

route.yaml

    25  {{- if $.Values.route.tls }}
    26    tls:
    27    {{- with $.Values.route.tls }}
    28      key: |-
    29        {{ .key }}
    30      certificate: |-
    31        {{ .certificate }}
    32      caCertificate: |-
    33        {{ .caCertificate }}
    34      insecureEdgeTerminationPolicy: {{ .insecureEdgeTerminationPolicy }}
    35    {{- end }}
    36      termination: edge
    37  {{- end }}
-- chandrashekar
helm-tls
kubernetes
kubernetes-helm
openshift
openshift-enterprise

1 Answer

11/30/2020

.Values.route.tls.key (for example) is a multi-line string, but the way you're embedding it, you're only indenting the first line. If you run helm template on this, I'd expect you see (with exactly this indentation):

<!-- language: lang-yaml -->
      key: |-
              -----BEGIN CERTIFICATE-----
[...]
-----END CERTIFICATE-----

You can use the indent template function to indent the whole string:

<!-- language: lang-yaml -->
key: |-
{{ .key | indent 8 }}

indent also indents the first line; the amount of indentation should be 2 more than the number of spaces on the key: line.

-- David Maze
Source: StackOverflow