apiVersion: apps/v1
kind: Deployment
metadata:
  name: wca-scheduler
spec:
  replicas: 1
  revisionHistoryLimit: 0
  selector:
    matchLabels:
      app: wca-scheduler
  # All existing Pods are killed before new ones are created
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: wca-scheduler
    spec:
      hostNetwork: true
      serviceAccountName: wca-scheduler
      terminationGracePeriodSeconds: 1
      # nodeName: node36
      # Using nodeName works only for the first deployment.
      # On the second one (e.g. after deleting pod) it'll try to schedule new pod while old one is terminating.
      # This can cause some problems (e.g. until pod terminating is done, new pods gets "PodFitsHostPorts" status due to port using) 
      nodeSelector:
        kubernetes.io/hostname: node36
      tolerations:
        - key: "master"
          operator: "Exists"
          effect: "NoSchedule"
      containers:
        - name: wca-scheduler
          image: 100.64.176.12:80/wca-scheduler:latest
          envFrom:
          - configMapRef:
              name: wca-scheduler-env
          volumeMounts:
            - name: wca-scheduler-socket
              mountPath: /var/run/wca
            - name: wca-scheduler-config
              mountPath: /etc/wca-scheduler
          command:
            - /bin/bash
            - -c
            - source ./env/bin/activate && gunicorn "wca.scheduler.main:main('/etc/wca-scheduler/${config_file}')" -b unix:/var/run/wca/wca-scheduler.sock && deactivate

        - name: nginx
          image: nginx:latest
          ports:
            - name: wca-scheduler
              containerPort: 30180
              hostPort: 30180
          volumeMounts:
            - name: wca-scheduler-socket
              mountPath: /var/run/wca
            - name: wca-scheduler-server
              mountPath: /etc/nginx/conf.d
            - name: wca-scheduler-cert
              mountPath: /var/run/secrets/kubernetes.io/cert
              readOnly: true

      volumes:
        - name: wca-scheduler-socket
          emptyDir: {}
        - name: wca-scheduler-server
          configMap:
            name: wca-scheduler-server 
        - name: wca-scheduler-config
          configMap:
            name: wca-scheduler-config
        - name: wca-scheduler-cert
          secret:
            secretName: wca-scheduler-cert
