How can i make a template of this part of YAML chart?

9/11/2019

I have a lot of cronjob charts in my application and i would to make a template of common parts of YAML file.

How I can do that?

I tried to define template in my _helpers.tpl file but i was not able to make it work.

cronjob.yaml contains:

apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: domain
spec:
  schedule: "* * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: api
            image: {{ template "app.api.image" . }}
            imagePullPolicy: {{ .Values.api.image.pullPolicy | quote }}
            env:
            - name: MYSQL_DB_NAME
              value: {{ .Values.mysql.db.name | quote }}
            - name: MYSQL_DB_HOST
              value: {{ .Values.mysql.db.host | quote }}
            - name: MYSQL_DB_USERNAME
              value: {{ .Values.mysql.db.username | quote }}
            - name: MYSQL_DB_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: {{ printf "%s-%s" .Release.Name "database" }}
                  key: db-password
            - name: PHPFPM_ENDPOINT
              value: /var/run/php/php-fpm.sock
            - name: PHPFPM_PM_MAX_CHILDREN
              value: {{ .Values.phpfpm.max_childrens | quote }}
            - name: CURRENT_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
            - name: EXTERNAL_IP
              value: {{ .Values.api.externalip }}
            ports:
            - name: phpfpm
              containerPort: 9000
            command: ["sh", "-c", "/var/www/html/bin/cake Domain"]
          restartPolicy: Never

I want to separate out the block starting with - name: api through the ports: block into a template that I can include in my cronjob.yaml file.

-- Emanuele Lamacchia
kubernetes-helm
yaml

0 Answers