{{- if .Values.temporal.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "postiz.fullname" . }}-temporal
  labels:
    {{- include "postiz.labels" . | nindent 4 }}
    app.kubernetes.io/component: temporal
spec:
  replicas: 1
  selector:
    matchLabels:
      {{- include "postiz.selectorLabels" . | nindent 6 }}
      app.kubernetes.io/component: temporal
  template:
    metadata:
      labels:
        {{- include "postiz.selectorLabels" . | nindent 8 }}
        app.kubernetes.io/component: temporal
    spec:
      containers:
        - name: temporal
          image: "{{ .Values.temporal.image.repository }}:{{ .Values.temporal.image.tag }}"
          imagePullPolicy: {{ .Values.temporal.image.pullPolicy }}
          ports:
            - name: grpc
              containerPort: 7233
              protocol: TCP
          env:
            - name: DB
              value: "postgres12"
            - name: DB_PORT
              value: "5432"
            - name: POSTGRES_USER
              value: {{ .Values.temporal.postgresql.user | quote }}
            - name: POSTGRES_PWD
              valueFrom:
                secretKeyRef:
                  name: {{ include "postiz.fullname" . }}-temporal-secret
                  key: POSTGRES_PWD
            - name: POSTGRES_SEEDS
              value: {{ default (printf "%s-postgresql" .Release.Name) .Values.temporal.postgresql.seeds | quote }}
            - name: DYNAMIC_CONFIG_FILE_PATH
              value: "config/dynamicconfig/development-sql.yaml"
            - name: ENABLE_ES
              value: "false"
            - name: TEMPORAL_NAMESPACE
              value: {{ .Values.temporal.namespace | default "default" | quote }}
          volumeMounts:
            - name: dynamicconfig
              mountPath: /etc/temporal/config/dynamicconfig
          livenessProbe:
            tcpSocket:
              port: grpc
            initialDelaySeconds: 30
            periodSeconds: 15
            failureThreshold: 5
          readinessProbe:
            tcpSocket:
              port: grpc
            initialDelaySeconds: 15
            periodSeconds: 10
            failureThreshold: 5
      volumes:
        - name: dynamicconfig
          configMap:
            name: {{ include "postiz.fullname" . }}-temporal-dynamicconfig
{{- end }}
