apiVersion: apps/v1
kind: Deployment
metadata:
  name: etl-parser
  namespace: default
spec:
  replicas: 4
  selector:
    matchLabels:
      # Used to match pre-existing pods that may be affected during updates.
      run: etl-parser
  strategy:
    rollingUpdate:
      maxSurge: 3
      maxUnavailable: 2
    type: RollingUpdate
  # Pod template.
  template:
    metadata:
      labels:
        # Note: run=etl-parser should match a service config with a public IP
        # and port so that it is publicly accessible for prometheus scraping
        run: etl-parser
      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: 120

      # 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:{{GIT_COMMIT}}
        name: etl-parser
        args: ["--prometheusx.listen-address=:9090",
               "--output=gcs",
               "--service_port=:8080",  # If we move to jsonnet, this could be bound to service-port defined below
               "--max_active=100",
               ]
        env:
        - name: GCLOUD_PROJECT
          value: "{{GCLOUD_PROJECT}}"
        - name: BIGQUERY_DATASET
          value: "{{BIGQUERY_DATASET}}"

        - name: GARDENER_HOST
          value: "etl-gardener-service.default.svc.cluster.local"
        - name: BATCH_SERVICE
          value: 'true'   # Allow instances to discover they are BATCH instances.
        - name: MAX_WORKERS
          value: '10' # Singleton workers, in addition to the active workers.
        - name: NDT_OMIT_DELTAS
          value: 'true'

        ports:
        - name: prometheus-port
          containerPort: 9090
        - name: service-port
          containerPort: 8080

        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: "15Gi"
            cpu: "15"
          limits:
            memory: "20Gi"
            cpu: "15"

      nodeSelector:
        parser-node: "true"

