1
votes

I need to deploy three different certificates on different namespaces using helm chart. I create a template per certificate in the same file and add if conditions on each one in order to deloy only the needed certificate that i pass as a paramater in my helm install command, My secret.yaml look like this :

{{- if eq .Values.val "paris_turf_support" }}
{{- range .Values.namespaces.paris_turf_support }}
{{- $ns := . -}}

apiVersion: v1
kind: Secret
type: kubernetes.io/tls
metadata:
name: "tls-paris-turf.support"
namespace: {{ $ns }}
data:
    tls.crt: {{ $.Files.Get "tls-paris-turf.support.crt" | b64enc }}
    tls.key: {{ $.Files.Get "tls-paris-turf.support.key" | b64enc }}
{{- end }}

{{ else if eq .Values.val "geny_sports" }}
{{- range .Values.namespaces.geny_sports }}
{{- $ns := . -}}

apiVersion: v1
kind: Secret
type: kubernetes.io/tls
metadata:
    name: "tls-geny-sports.com"
    namespace: {{ $ns }}
data:
    tls.crt: {{ $.Files.Get "tls-geny-sports.com.crt" | b64enc }}
    tls.key: {{ $.Files.Get "tls-geny-sports.com.key" | b64enc }}
{{- end }}

{{ else if eq .Values.val "paris_turf_com" }}
{{- range .Values.namespaces.paris_turf_com }}
{{- $ns := . -}}

apiVersion: v1
kind: Secret
type: kubernetes.io/tls
metadata:
    name: "tls-paris-turf.com"
    namespace: {{ $ns }}
data:
    tls.crt: {{ $.Files.Get "tls-paris-turf.com.crt" | b64enc }}
    tls.key: {{ $.Files.Get "tls-paris-turf.com.key" | b64enc }}
{{- end }}
{{- end }}

when i run this command to install the helm chart : helm install secret-rel ./secret --values=./secret/values/dev.yaml --namespace=secret --set val="paris_turf_com"

I get this error : Error: YAML parse error on secret/templates/secret.yaml: error converting YAML to JSON: yaml: line 9: mapping values are not allowed in this context

Need your help please

2
I am working on your use case right now but in the meantime you could check one thing please. mapping values are not allowed in this context means that the yaml is not valid. Line 9 and 10 in your example is missing the indentations. Please correct them. If that is not enough, we will dig deeper. - Wytrzymały Wiktor
thanks @OhHiMark i fix the indentations but i still have the same problem - ahmed khalil jerbi
Exact same error message? I would also get rid of the "" (quotes) there. - Wytrzymały Wiktor
yes it's the exact same error, i tried also to remove the "" and still have the same message - ahmed khalil jerbi

2 Answers

0
votes

mapping values are not allowed in this context means that there is an error in .yaml which makes it invalid.

There are plenty of online tools that can be used to validate yaml's syntax such as YAML Lint.

In your particular use case the error says that there is an issue with line 9. Looking at your config we can see that you rae missing indentations in lines 9 and 10. It should look like this instead:

apiVersion: v1
kind: Secret
type: kubernetes.io/tls
metadata:
  name: tls-paris-turf.support
  namespace: {{ $ns }}

Also you don't need to use double quotes (" ") for naming your Secrets. And as you already noticed, you should use --- a line before {{- end }}

I hope it helps.

-4
votes

finally i fix the problem, this is my secret.yaml :

{{- if eq .Values.val "paris_turf_support" }}
{{- range .Values.namespaces.paris_turf_support }}
{{- $ns := . -}}

apiVersion: v1
kind: Secret
type: kubernetes.io/tls
metadata:
  name: tls-paris-turf.support
  namespace: {{ $ns }}
data:
  tls.crt: {{ $.Files.Get "tls-paris-turf.support.crt" | b64enc }}
  tls.key: {{ $.Files.Get "tls-paris-turf.support.key" | b64enc }}
---
{{- end }}
{{ else if eq .Values.val "geny_sports" }}
{{- range .Values.namespaces.geny_sports }}
{{- $ns := . -}}

apiVersion: v1
kind: Secret
type: kubernetes.io/tls
metadata:
  name: tls-geny-sports.com
  namespace: {{ $ns }}
data:
  tls.crt: {{ $.Files.Get "tls-geny-sports.com.crt" | b64enc }}
  tls.key: {{ $.Files.Get "tls-geny-sports.com.key" | b64enc }}
---
{{- end }}
{{ else if eq .Values.val "paris_turf_com" }}
{{- range .Values.namespaces.paris_turf_com }}
{{- $ns := . -}}

apiVersion: v1
kind: Secret
type: kubernetes.io/tls
metadata:
  name: tls-paris-turf.com
  namespace: {{ $ns }}
data:
  tls.crt: {{ $.Files.Get "tls-paris-turf.com.crt" | b64enc }}
  tls.key: {{ $.Files.Get "tls-paris-turf.com.key" | b64enc }}
---
{{- end }}
{{- end }}