How to avoid translate some `{{` of the helm chart?

10/16/2018

I want to put the following CRD into helm chart, but it contains go raw template. How to make helm not translate {{ and }} inside rawTemplate. Thanks for your response. https://github.com/kubeflow/katib/blob/master/examples/random-example.yaml

apiVersion: "kubeflow.org/v1alpha1"
kind: StudyJob
metadata:
  namespace: katib
  labels:
    controller-tools.k8s.io: "1.0"
  name: random-example
spec:
 studyName: random-example
 owner: crd
 optimizationtype: maximize
 objectivevaluename: Validation-accuracy
 optimizationgoal: 0.99
 requestcount: 4
 metricsnames:
   - accuracy
 workerSpec:
   goTemplate:
    rawTemplate: |-
      apiVersion: batch/v1
      kind: Job
      metadata:
        name: {{.WorkerId}}
        namespace: katib
      spec:
        template:
          spec:
            containers:
            - name: {{.WorkerId}}
              image: katib/mxnet-mnist-example
              command:
              - "python"
              - "/mxnet/example/image-classification/train_mnist.py"
              - "--batch-size=64"
              {{- with .HyperParameters}}
              {{- range .}}
              - "{{.Name}}={{.Value}}"
              {{- end}}
              {{- end}}
            restartPolicy: Never
-- che yang
go
kubernetes
kubernetes-helm

1 Answer

10/17/2018

In the Go template language, the expression

{{ "{{" }}

will expand to two open curly braces, for cases when you need to use Go template syntax to generate documents in Go template syntax; for example

{{ "{{" }}- if .Values.foo }}
- name: FOO
  value: {{ "{{" }} .Values.foo }}
{{ "{{" }}- end }}

(In a Kubernetes Helm context where you're using this syntax to generate YAML, be extra careful with how whitespace is handled; consider using helm template to dump out what gets generated.)

-- David Maze
Source: StackOverflow