peridot/infrastructure/dev-helm/temporal/templates/server-job.yaml

423 lines
20 KiB
YAML

{{- if $.Values.server.enabled }}
{{- if .Values.schema.setup.enabled }}
apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "temporal.componentname" (list . "schema-setup") }}
labels:
app.kubernetes.io/name: {{ include "temporal.name" . }}
helm.sh/chart: {{ include "temporal.chart" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Chart.AppVersion | replace "+" "_" }}
app.kubernetes.io/component: database
app.kubernetes.io/part-of: {{ .Chart.Name }}
annotations:
{{- if .Values.cassandra.enabled }}
"helm.sh/hook": post-install
{{- else }}
"helm.sh/hook": pre-install
{{- end }}
"helm.sh/hook-weight": "0"
{{- if not .Values.debug }}
"helm.sh/hook-delete-policy": hook-succeeded,hook-failed
{{- end }}
spec:
backoffLimit: {{ .Values.schema.setup.backoffLimit }}
template:
metadata:
name: {{ include "temporal.componentname" (list . "schema-setup") }}
labels:
app.kubernetes.io/name: {{ include "temporal.name" . }}
helm.sh/chart: {{ include "temporal.chart" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Chart.AppVersion | replace "+" "_" }}
app.kubernetes.io/component: database
app.kubernetes.io/part-of: {{ .Chart.Name }}
spec:
{{ include "temporal.serviceAccount" . }}
restartPolicy: "OnFailure"
initContainers:
{{- if or .Values.cassandra.enabled (eq (include "temporal.persistence.driver" (list $ "default")) "cassandra") }}
{{- if .Values.cassandra.enabled }}
- name: check-cassandra-service
image: busybox
command: ['sh', '-c', 'until nslookup {{ include "cassandra.host" $ }}; do echo waiting for cassandra service; sleep 1; done;']
- name: check-cassandra
image: "{{ .Values.cassandra.image.repo }}:{{ .Values.cassandra.image.tag }}"
imagePullPolicy: {{ .Values.cassandra.image.pullPolicy }}
command: ['sh', '-c', 'until cqlsh {{ include "cassandra.host" $ }} {{ .Values.cassandra.config.ports.cql }} -e "SHOW VERSION"; do echo waiting for cassandra to start; sleep 1; done;']
{{- end }}
{{- range $store := (list "default" "visibility") }}
{{- $storeConfig := index $.Values.server.config.persistence $store }}
{{- if eq (include "temporal.persistence.driver" (list $ $store)) "cassandra" }}
- name: create-{{ $store }}-store
image: "{{ $.Values.admintools.image.repository }}:{{ $.Values.admintools.image.tag }}"
imagePullPolicy: {{ $.Values.admintools.image.pullPolicy }}
command: ['temporal-cassandra-tool', 'create', '-k', '{{ $storeConfig.cassandra.keyspace }}', '--replication-factor', '{{ $storeConfig.cassandra.replicationFactor }}']
env:
- name: CASSANDRA_HOST
value: {{ first (splitList "," (include "temporal.persistence.cassandra.hosts" (list $ $store))) }}
- name: CASSANDRA_PORT
value: {{ include "temporal.persistence.cassandra.port" (list $ $store) | quote }}
- name: CASSANDRA_KEYSPACE
value: {{ $storeConfig.cassandra.keyspace }}
{{- if $storeConfig.cassandra.user }}
- name: CASSANDRA_USER
value: {{ $storeConfig.cassandra.user }}
{{- end }}
{{- if (or $storeConfig.cassandra.password $storeConfig.cassandra.existingSecret) }}
- name: CASSANDRA_PASSWORD
{{- if $storeConfig.cassandra.existingSecret }}
valueFrom:
secretKeyRef:
name: {{ include "temporal.persistence.secretName" (list $ $store) }}
key: {{ include "temporal.persistence.secretKey" (list $ $store) }}
{{- else }}
value: {{ $storeConfig.cassandra.password }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- else if or (eq (include "temporal.persistence.driver" (list $ "default")) "sql") (eq (include "temporal.persistence.driver" (list $ "visibility")) "sql") }}
{{- range $store := (list "default" "visibility") }}
{{- $storeConfig := index $.Values.server.config.persistence $store }}
{{- if eq (include "temporal.persistence.driver" (list $ $store)) "sql" }}
- name: create-{{ $store }}-store
image: "{{ $.Values.admintools.image.repository }}:{{ $.Values.admintools.image.tag }}"
imagePullPolicy: {{ $.Values.admintools.image.pullPolicy }}
command: ['temporal-sql-tool', '--database', '{{ include "temporal.persistence.sql.database" (list $ $store) }}', 'create-database']
env:
- name: SQL_PLUGIN
value: {{ include "temporal.persistence.sql.driver" (list $ $store) }}
- name: SQL_HOST
value: {{ include "temporal.persistence.sql.host" (list $ $store) }}
- name: SQL_PORT
value: {{ include "temporal.persistence.sql.port" (list $ $store) | quote }}
{{- if $storeConfig.sql.user }}
- name: SQL_USER
value: {{ $storeConfig.sql.user }}
{{- end }}
{{- if (or $storeConfig.sql.password $storeConfig.sql.existingSecret) }}
- name: SQL_PASSWORD
{{- if $storeConfig.sql.existingSecret }}
valueFrom:
secretKeyRef:
name: {{ include "temporal.persistence.secretName" (list $ $store) }}
key: {{ include "temporal.persistence.secretKey" (list $ $store) }}
{{- else }}
value: {{ $storeConfig.sql.password }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- else }}
[]
{{- end }}
containers:
{{- range $store := (list "default" "visibility") }}
{{- $storeConfig := index $.Values.server.config.persistence $store }}
- name: {{ $store }}-schema
image: "{{ $.Values.admintools.image.repository }}:{{ $.Values.admintools.image.tag }}"
imagePullPolicy: {{ $.Values.admintools.image.pullPolicy }}
command: ['temporal-{{ include "temporal.persistence.driver" (list $ $store) }}-tool', 'setup-schema', '-v', '0.0']
env:
{{- if eq (include "temporal.persistence.driver" (list $ $store)) "cassandra" }}
- name: CASSANDRA_HOST
value: {{ first (splitList "," (include "temporal.persistence.cassandra.hosts" (list $ $store))) }}
- name: CASSANDRA_PORT
value: {{ include "temporal.persistence.cassandra.port" (list $ $store) | quote }}
- name: CASSANDRA_KEYSPACE
value: {{ $storeConfig.cassandra.keyspace }}
{{- if $storeConfig.cassandra.user }}
- name: CASSANDRA_USER
value: {{ $storeConfig.cassandra.user }}
{{- end }}
{{- if (or $storeConfig.cassandra.password $storeConfig.cassandra.existingSecret) }}
- name: CASSANDRA_PASSWORD
{{- if $storeConfig.cassandra.existingSecret }}
valueFrom:
secretKeyRef:
name: {{ include "temporal.persistence.secretName" (list $ $store) }}
key: {{ include "temporal.persistence.secretKey" (list $ $store) }}
{{- else }}
value: {{ $storeConfig.cassandra.password }}
{{- end }}
{{- end }}
{{- else if eq (include "temporal.persistence.driver" (list $ $store)) "sql" }}
- name: SQL_PLUGIN
value: {{ include "temporal.persistence.sql.driver" (list $ $store) }}
- name: SQL_HOST
value: {{ include "temporal.persistence.sql.host" (list $ $store) }}
- name: SQL_PORT
value: {{ include "temporal.persistence.sql.port" (list $ $store) | quote }}
- name: SQL_DATABASE
value: {{ include "temporal.persistence.sql.database" (list $ $store) }}
{{- if $storeConfig.sql.user }}
- name: SQL_USER
value: {{ $storeConfig.sql.user }}
{{- end }}
{{- if (or $storeConfig.sql.password $storeConfig.sql.existingSecret) }}
- name: SQL_PASSWORD
{{- if $storeConfig.sql.existingSecret }}
valueFrom:
secretKeyRef:
name: {{ include "temporal.persistence.secretName" (list $ $store) }}
key: {{ include "temporal.persistence.secretKey" (list $ $store) }}
{{- else }}
value: {{ $storeConfig.sql.password }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- with .Values.schema.resources }}
resources:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.schema.containerSecurityContext }}
securityContext:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.schema.securityContext }}
securityContext:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with $.Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with (default $.Values.server.nodeSelector) }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.server.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.server.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
---
{{- end }}
{{- if .Values.schema.update.enabled }}
apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "temporal.componentname" (list . "schema-update") }}
labels:
app.kubernetes.io/name: {{ include "temporal.name" . }}
helm.sh/chart: {{ include "temporal.chart" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Chart.AppVersion | replace "+" "_" }}
app.kubernetes.io/component: database
app.kubernetes.io/part-of: {{ .Chart.Name }}
annotations:
{{- if .Values.cassandra.enabled }}
"helm.sh/hook": post-install,pre-upgrade
{{- else }}
"helm.sh/hook": pre-install,pre-upgrade
{{- end }}
"helm.sh/hook-weight": "1"
{{- if not .Values.debug }}
"helm.sh/hook-delete-policy": hook-succeeded,hook-failed
{{- end }}
spec:
backoffLimit: {{ .Values.schema.update.backoffLimit }}
template:
metadata:
name: {{ include "temporal.componentname" (list . "schema-update") }}
labels:
app.kubernetes.io/name: {{ include "temporal.name" . }}
helm.sh/chart: {{ include "temporal.chart" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Chart.AppVersion | replace "+" "_" }}
app.kubernetes.io/component: database
app.kubernetes.io/part-of: {{ .Chart.Name }}
spec:
{{ include "temporal.serviceAccount" . }}
restartPolicy: "OnFailure"
initContainers:
{{- if .Values.cassandra.enabled }}
- name: check-cassandra-service
image: busybox
command: ['sh', '-c', 'until nslookup {{ include "cassandra.host" $ }}; do echo waiting for cassandra service; sleep 1; done;']
- name: check-cassandra
image: "{{ .Values.cassandra.image.repo }}:{{ .Values.cassandra.image.tag }}"
imagePullPolicy: {{ .Values.cassandra.image.pullPolicy }}
command: ['sh', '-c', 'until cqlsh {{ include "cassandra.host" $ }} {{ .Values.cassandra.config.ports.cql }} -e "SHOW VERSION"; do echo waiting for cassandra to start; sleep 1; done;']
{{- else }}
[]
{{- end }}
containers:
{{- range $store := (list "default" "visibility") }}
{{- if or (eq $store "default") (eq (include "temporal.persistence.driver" (list $ $store)) "sql") }}
{{- $storeConfig := index $.Values.server.config.persistence $store }}
- name: {{ $store }}-schema
image: "{{ $.Values.admintools.image.repository }}:{{ $.Values.admintools.image.tag }}"
imagePullPolicy: {{ $.Values.admintools.image.pullPolicy }}
{{- if eq (include "temporal.persistence.driver" (list $ $store)) "cassandra" }}
command: ['temporal-{{ include "temporal.persistence.driver" (list $ $store) }}-tool', 'update-schema', '--schema-dir', '/etc/temporal/schema/cassandra/{{ include "temporal.persistence.schema" $store }}/versioned']
{{- else if eq (include "temporal.persistence.sql.driver" (list $ $store)) "mysql8" }}
command: ['temporal-{{ include "temporal.persistence.driver" (list $ $store) }}-tool', 'update-schema', '--schema-dir', '/etc/temporal/schema/mysql/v8/{{ include "temporal.persistence.schema" $store }}/versioned']
{{- else if eq (include "temporal.persistence.sql.driver" (list $ $store)) "postgres12" }}
command: ['temporal-{{ include "temporal.persistence.driver" (list $ $store) }}-tool', 'update-schema', '--schema-dir', '/etc/temporal/schema/postgresql/v12/{{ include "temporal.persistence.schema" $store }}/versioned']
{{- end }}
env:
{{- if eq (include "temporal.persistence.driver" (list $ $store)) "cassandra" }}
- name: CASSANDRA_HOST
value: {{ first (splitList "," (include "temporal.persistence.cassandra.hosts" (list $ $store))) }}
- name: CASSANDRA_PORT
value: {{ include "temporal.persistence.cassandra.port" (list $ $store) | quote }}
- name: CASSANDRA_KEYSPACE
value: {{ $storeConfig.cassandra.keyspace }}
{{- if $storeConfig.cassandra.user }}
- name: CASSANDRA_USER
value: {{ $storeConfig.cassandra.user }}
{{- end }}
{{- if (or $storeConfig.cassandra.password $storeConfig.cassandra.existingSecret) }}
- name: CASSANDRA_PASSWORD
{{- if $storeConfig.cassandra.existingSecret }}
valueFrom:
secretKeyRef:
name: {{ include "temporal.persistence.secretName" (list $ $store) }}
key: {{ include "temporal.persistence.secretKey" (list $ $store) }}
{{- else }}
value: {{ $storeConfig.cassandra.password }}
{{- end }}
{{- end }}
{{- else if eq (include "temporal.persistence.driver" (list $ $store)) "sql" }}
- name: SQL_PLUGIN
value: {{ include "temporal.persistence.sql.driver" (list $ $store) }}
- name: SQL_HOST
value: {{ include "temporal.persistence.sql.host" (list $ $store) }}
- name: SQL_PORT
value: {{ include "temporal.persistence.sql.port" (list $ $store) | quote }}
- name: SQL_DATABASE
value: {{ include "temporal.persistence.sql.database" (list $ $store) }}
{{- if $storeConfig.sql.user }}
- name: SQL_USER
value: {{ $storeConfig.sql.user }}
{{- end }}
{{- if (or $storeConfig.sql.password $storeConfig.sql.existingSecret) }}
- name: SQL_PASSWORD
{{- if $storeConfig.sql.existingSecret }}
valueFrom:
secretKeyRef:
name: {{ include "temporal.persistence.secretName" (list $ $store) }}
key: {{ include "temporal.persistence.secretKey" (list $ $store) }}
{{- else }}
value: {{ $storeConfig.sql.password }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- with .Values.schema.resources }}
resources:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.schema.containerSecurityContext }}
securityContext:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.schema.securityContext }}
securityContext:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with (default $.Values.admintools.nodeSelector) }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.admintools.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.admintools.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
---
{{- end }}
{{- if and (or $.Values.elasticsearch.enabled $.Values.elasticsearch.external) .Values.schema.setup.enabled }}
apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "temporal.componentname" (list . "es-index-setup") }}
labels:
app.kubernetes.io/name: {{ include "temporal.name" . }}
helm.sh/chart: {{ include "temporal.chart" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Chart.AppVersion | replace "+" "_" }}
app.kubernetes.io/component: database
app.kubernetes.io/part-of: {{ .Chart.Name }}
annotations:
{{- if .Values.elasticsearch.external }}
"helm.sh/hook": pre-install
{{- else }}
"helm.sh/hook": post-install
{{- end }}
"helm.sh/hook-weight": "0"
{{- if not .Values.debug }}
"helm.sh/hook-delete-policy": hook-succeeded,hook-failed
{{- end }}
spec:
backoffLimit: {{ .Values.schema.setup.backoffLimit }}
template:
metadata:
name: {{ include "temporal.componentname" (list . "es-index-setup") }}
labels:
app.kubernetes.io/name: {{ include "temporal.name" . }}
helm.sh/chart: {{ include "temporal.chart" . }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Chart.AppVersion | replace "+" "_" }}
app.kubernetes.io/component: database
app.kubernetes.io/part-of: {{ .Chart.Name }}
spec:
{{ include "temporal.serviceAccount" . }}
restartPolicy: "OnFailure"
initContainers:
- name: check-elasticsearch
image: "{{ .Values.admintools.image.repository }}:{{ .Values.admintools.image.tag }}"
imagePullPolicy: {{ $.Values.admintools.image.pullPolicy }}
command: ['sh', '-c', 'until curl --silent --fail {{- if and .Values.elasticsearch.username .Values.elasticsearch.password }} --user {{ .Values.elasticsearch.username }}:{{ .Values.elasticsearch.password }} {{- end }} {{ .Values.elasticsearch.scheme }}://{{ .Values.elasticsearch.host }}:{{ .Values.elasticsearch.port }} 2>&1 > /dev/null; do echo waiting for elasticsearch to start; sleep 1; done;']
containers:
- name: create-elasticsearch-index
image: "{{ $.Values.admintools.image.repository }}:{{ $.Values.admintools.image.tag }}"
imagePullPolicy: {{ $.Values.admintools.image.pullPolicy }}
command: ['sh', '-c']
args:
- 'curl -X PUT --fail {{- if and .Values.elasticsearch.username .Values.elasticsearch.password }} --user {{ .Values.elasticsearch.username }}:{{ .Values.elasticsearch.password }} {{- end }} {{ .Values.elasticsearch.scheme }}://{{ .Values.elasticsearch.host }}:{{ .Values.elasticsearch.port }}/_template/temporal_visibility_v1_template -H "Content-Type: application/json" --data-binary "@schema/elasticsearch/visibility/index_template_{{ .Values.elasticsearch.version }}.json" 2>&1 &&
curl -X PUT --fail {{- if and .Values.elasticsearch.username .Values.elasticsearch.password }} --user {{ .Values.elasticsearch.username }}:{{ .Values.elasticsearch.password }} {{- end }} {{ .Values.elasticsearch.scheme }}://{{ .Values.elasticsearch.host }}:{{ .Values.elasticsearch.port }}/{{ .Values.elasticsearch.visibilityIndex }} 2>&1'
{{- with .Values.schema.resources }}
resources:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.schema.containerSecurityContext }}
securityContext:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.schema.securityContext }}
securityContext:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with (default $.Values.admintools.nodeSelector) }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.admintools.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.admintools.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
{{- end }}