apiVersion: apps/v1
kind: Deployment
metadata:
  name: airflow-scheduler-deploy
  namespace: airflow-tls
spec:
  replicas: 1
  selector:
    matchLabels:
      name: airflow-scheduler
      instance: airflow-scheduler-celery
      version: "1.0.0"
      component: scheduler
      part-of: airflow
  strategy:
    rollingUpdate:
      maxSurge: 100%
      maxUnavailable: 0
    type: RollingUpdate
  # minReadySeconds: 60
  # progressDeadlineSeconds: 600
  template:
    metadata:
      labels:
        name: airflow-scheduler
        instance: airflow-scheduler-celery
        version: "1.0.0"
        component: scheduler
        part-of: airflow
    spec:
      nodeSelector:
        "beta.kubernetes.io/os": linux
      serviceAccountName: airflow-rbac
      volumes:
        - name: az-dags
          persistentVolumeClaim:
            claimName: azure-claim-dags
        - name: az-scripts
          persistentVolumeClaim:
            claimName: azure-claim-scripts
        - name: az-logs
          persistentVolumeClaim:
            claimName: azure-claim-logs
        - name: azure-spn
          secret:
            secretName: azure-spn-secret
        - name: box-key-file
          secret:
            secretName: box-secret
      initContainers:
        - name: airflow-wait-web
          image: busybox:1.32.0
          command: ['sh', '-c', "until nslookup airflow-web-service.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local; do echo waiting for airflow-web-service; sleep 5; done"]
          resources:
            requests:
              cpu: "100m"
              memory: "200Mi"
            limits:
              cpu: "500m"
              memory: "500Mi"
      containers:
        - name: airflow
          image: rkoH1pVL.azurecr.io/airflow:1.10.14
          imagePullPolicy: Always  # IfNotPresent
          command:
              - "./scripts/airflow-scheduler-start.sh"
          volumeMounts:
            - name: az-dags
              mountPath: "/opt/airflow/dags"
            - name: az-scripts
              mountPath: "/opt/airflow/scripts"
            - name: az-logs
              mountPath: /opt/airflow/logs
              subPath: logs
            - name: azure-spn
              mountPath: "/opt/airflow/az-sec"
              readOnly: true
            - name: box-key-file
              mountPath: "/opt/airflow/box-sec"
              readOnly: true
          envFrom:
          - configMapRef:
              name: airflow-configmap
          resources:
            requests:
              cpu: "1000m"
              memory: "2048Mi"
            limits:
              cpu: "4000m"
              memory: "4Gi"
          # readinessProbe:
          #   httpGet:
          #     path: /health
          #     port: 8080
          #   initialDelaySeconds: 5
          #   periodSeconds: 5
          #   failureThreshold: 3
          #   successThreshold: 1
          # livenessProbe:
          #   exec:
          #     command:
          #       - airflow
          #       - info
          #       - --anonymize
          #   initialDelaySeconds: 5
          #   periodSeconds: 5
