apiVersion: apps/v1
kind: Deployment
metadata:
  name: airbyte-scheduler
spec:
  replicas: 1
  selector:
    matchLabels:
      airbyte: scheduler
  template:
    metadata:
      labels:
        airbyte: scheduler
    spec:
      serviceAccountName: airbyte-admin
      automountServiceAccountToken: true
      containers:
        - name: airbyte-scheduler-container
          image: airbyte/scheduler
          env:
            - name: AIRBYTE_VERSION
              valueFrom:
                configMapKeyRef:
                  name: airbyte-env
                  key: AIRBYTE_VERSION
            - name: CONFIG_ROOT
              valueFrom:
                configMapKeyRef:
                  name: airbyte-env
                  key: CONFIG_ROOT
            - name: DATABASE_PASSWORD
              valueFrom:
                configMapKeyRef:
                  name: airbyte-env
                  key: DATABASE_PASSWORD
            - name: DATABASE_URL
              valueFrom:
                configMapKeyRef:
                  name: airbyte-env
                  key: DATABASE_URL
            - name: DATABASE_USER
              valueFrom:
                configMapKeyRef:
                  name: airbyte-env
                  key: DATABASE_USER
            - name: TRACKING_STRATEGY
              valueFrom:
                configMapKeyRef:
                  name: airbyte-env
                  key: TRACKING_STRATEGY
            - name: WAIT_BEFORE_HOSTS
              value: "5"
            - name: WAIT_HOSTS
              value: airbyte-db-svc:5432
            - name: WAIT_HOSTS_TIMEOUT
              value: "45"
            - name: WORKSPACE_DOCKER_MOUNT
              value: workspace
            - name: WORKSPACE_ROOT
              valueFrom:
                configMapKeyRef:
                  name: airbyte-env
                  key: WORKSPACE_ROOT
            - name: WORKER_ENVIRONMENT
              valueFrom:
                configMapKeyRef:
                  name: airbyte-env
                  key: WORKER_ENVIRONMENT
            - name: LOCAL_ROOT
              valueFrom:
                configMapKeyRef:
                  name: airbyte-env
                  key: LOCAL_ROOT
            - name: WEBAPP_URL
              valueFrom:
                configMapKeyRef:
                  name: airbyte-env
                  key: WEBAPP_URL
            - name: TEMPORAL_HOST
              valueFrom:
                configMapKeyRef:
                  name: airbyte-env
                  key: TEMPORAL_HOST
            - name: TEMPORAL_WORKER_PORTS
              valueFrom:
                configMapKeyRef:
                  name: airbyte-env
                  key: TEMPORAL_WORKER_PORTS
            - name: S3_LOG_BUCKET
              valueFrom:
                configMapKeyRef:
                  name: airbyte-env
                  key: S3_LOG_BUCKET
            - name: S3_LOG_BUCKET_REGION
              valueFrom:
                configMapKeyRef:
                  name: airbyte-env
                  key: S3_LOG_BUCKET_REGION
            - name: AWS_ACCESS_KEY_ID
              valueFrom:
                configMapKeyRef:
                  name: airbyte-env
                  key: AWS_ACCESS_KEY_ID
            - name: AWS_SECRET_ACCESS_KEY
              valueFrom:
                configMapKeyRef:
                  name: airbyte-env
                  key: AWS_SECRET_ACCESS_KEY
            - name: KUBE_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
          ports:
            - containerPort: 9000 # for heartbeat server
            - containerPort: 9001 # start temporal worker port pool
            - containerPort: 9002
            - containerPort: 9003
            - containerPort: 9004
            - containerPort: 9005
            - containerPort: 9006
            - containerPort: 9007
            - containerPort: 9008
            - containerPort: 9009
            - containerPort: 9010
            - containerPort: 9011
            - containerPort: 9012
            - containerPort: 9013
            - containerPort: 9014
            - containerPort: 9015
            - containerPort: 9016
            - containerPort: 9017
            - containerPort: 9018
            - containerPort: 9019
            - containerPort: 9020
            - containerPort: 9021
            - containerPort: 9022
            - containerPort: 9023
            - containerPort: 9024
            - containerPort: 9025
            - containerPort: 9026
            - containerPort: 9027
            - containerPort: 9028
            - containerPort: 9029
            - containerPort: 9030 # end temporal worker port pool
          volumeMounts:
            - name: airbyte-volume-configs
              mountPath: /configs
            - name: airbyte-volume-workspace
              mountPath: /workspace
      initContainers:
        - name: airbyte-seed
          image: airbyte/seed
          command: ["/bin/sh"]
          args:
            [
              "-c",
              "mkdir -p /configs/config && yes n | cp -r -i /app/seed/config /configs",
            ]
          volumeMounts:
            - name: airbyte-volume-configs
              mountPath: /configs
            - name: airbyte-volume-workspace
              mountPath: /workspace
      volumes:
        - name: airbyte-volume-workspace
          persistentVolumeClaim:
            claimName: airbyte-volume-workspace
        - name: airbyte-volume-configs
          persistentVolumeClaim:
            claimName: airbyte-volume-configs
