apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Values.redash.instance.name.admin }}-scheduledworker
  labels:
    helm.sh/chart: {{ .Values.redash.instance.name.admin }}-2.3.0
    app.kubernetes.io/name: {{ .Values.redash.instance.name.admin }}
    app.kubernetes.io/instance: {{ .Values.redash.instance.name.admin }}
    app.kubernetes.io/version: {{ .Values.redash.version | squote }}
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/component: scheduledworker
spec:
  replicas: {{ .Values.scheduledWorker.replicaCount }}
  selector:
    matchLabels:
      app.kubernetes.io/name: {{ .Values.redash.instance.name.admin }}
      app.kubernetes.io/instance: {{ .Values.redash.instance.name.admin }}
      app.kubernetes.io/component: scheduledworker
  template:
    metadata:
      labels:
        app.kubernetes.io/name: {{ .Values.redash.instance.name.admin }}
        app.kubernetes.io/instance: {{ .Values.redash.instance.name.admin }}
        app.kubernetes.io/component: scheduledworker
      {{- if .Values.scheduledWorker.podAnnotations }}
      annotations:
      {{ toYaml .Values.scheduledWorker.podAnnotations | nindent 8 }}
      {{- end }}
    spec:
    {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
    {{- end }}
      serviceAccountName: {{ include "redash.serviceAccountName" . }}
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      containers:
        - name: {{ .Values.redash.instance.name.admin }}-scheduledworker
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: "{{ .Values.image.name }}:{{ .Values.image.version }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          command: ["/bin/sh"]
          args: ["-c", ". /config/dynamicenv.sh && /app/bin/docker-entrypoint scheduler"]
          volumeMounts:
            - name: config
              mountPath: /config
          env:
            - name: REDASH_DATABASE_HOSTNAME
              value: {{ .Values.redash.instance.name.admin }}-postgresql
            - name: REDASH_REDIS_HOSTNAME
              value: {{ .Values.redash.instance.name.admin }}-redis-master
            - name: REDASH_SAML_ENTITY_ID
              value: {{ default  .Values.redash.samlEntityId.admin | quote }}
          {{- include "redash.env" . | nindent 12 }}
          {{- range $key, $value := .Values.scheduledWorker.env }}
            - name: "{{ $key }}"
              value: "{{ $value }}"
          {{- end }}
          envFrom:
          {{- include "redash.envFrom" . | nindent 12 }}
          resources:
{{ toYaml .Values.scheduledWorker.resources | indent 12 }}
      volumes:
        - name: config
          configMap:
            name: {{ include "redash.fullname" . }}
    {{- if .Values.scheduledWorker.nodeSelector }}
      nodeSelector:
{{ toYaml .Values.scheduledWorker.nodeSelector | indent 8 }}
    {{- end }}
    {{- with .Values.scheduledWorker.affinity }}
      affinity:
{{ toYaml . | indent 8 }}
    {{- end }}
    {{- with .Values.scheduledWorker.tolerations }}
      tolerations:
{{ toYaml . | indent 8 }}
    {{- end }}
