apiVersion: apps/v1
kind: Deployment
metadata:
  name: etl-gardener-universal
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      # Used to match pre-existing pods that may be affected during updates.
      run: etl-gardener-universal
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
    type: RollingUpdate
  # Pod template.
  template:
    metadata:
      labels:
        # Note: run=etl-gardener-universal should match a service config with a
        # public IP and port so that it is publicly accessible.
        run: etl-gardener-universal
      annotations:
        # Tell prometheus service discovery to collect metrics from the containers.
        prometheus.io/scrape: 'true'
    spec:
      # When container receives SIGTERM, it begins a new checkpoint. This can
      # take longer than the default grace period of 30s.
      terminationGracePeriodSeconds: 60

      # Place the pod into the Guaranteed QoS by setting equal resource
      # requests and limits for *all* containers in the pod.
      # For more background, see:
      # https://github.com/kubernetes/community/blob/master/contributors/design-proposals/resource-qos.md
      containers:
      - image: gcr.io/{{GCLOUD_PROJECT}}/etl-gardener:{{GIT_COMMIT}}
        name: etl-gardener
        args: [
          "-prometheusx.listen-address=:9090",
          "-config_path=/etc/config.yml",
          "-saver.backend=local",
          "-saver.dir=/singleton",
          "-status_port=:8081",
          "-project={{GCLOUD_PROJECT}}",
          "-shutdown_timeout=5m",
          "-job_expiration_time=6h",
        ]
        ports:
        - name: prometheus-port
          containerPort: 9090
        - name: service-port
          containerPort: 8080
        - name: status-port  # This one will be external
          containerPort: 8081

        livenessProbe:
          httpGet:
            path: /alive
            port: service-port
          initialDelaySeconds: 30
          periodSeconds: 10
          timeoutSeconds: 4
          successThreshold: 1
          failureThreshold: 3

        readinessProbe:
          httpGet:
            path: /ready
            port: service-port

        resources:
          requests:
            memory: "3Gi"
            cpu: "1"
          limits:
            memory: "3Gi"
            cpu: "1"

        volumeMounts:
        - name: config-volume
          mountPath: /etc/config.yml  # Is this where we want it?
          subPath: config.yml  # This is the name of the data section key?
        - name: singleton
          mountPath: /singleton

      volumes:
      - name: singleton
        persistentVolumeClaim:
          claimName: gardener-universal  # This forces a singleton instance.
      - name: config-volume
        configMap:
          name: gardener-config

      nodeSelector:
        gardener-node: "true"


