#  Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
#  Licensed under the Apache License, Version 2.0 (the "License").
#  You may not use this file except in compliance with the License.
#  A copy of the License is located at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  or in the "license" file accompanying this file. This file is distributed
#  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
#  express or implied. See the License for the specific language governing
#  permissions and limitations under the License.
apiVersion: apps/v1
kind: Deployment
metadata:
  name: executor
  labels:
    app: benchmark-ai
spec:
  selector:
    matchLabels:
      app: benchmark-ai
  replicas: 1
  template:
    metadata:
      labels:
        app: benchmark-ai
        service: executor
    spec:
      serviceAccountName: executor
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: service
                    operator: In
                    values:
                      - executor
              topologyKey: kubernetes.io/hostname
      initContainers:
        - name: kubectl-delivery
          image: mpioperator/kubectl-delivery:0.2.0
          env:
          - name: TARGET_DIR
            value: "/tmp/kubectl"
          volumeMounts:
          - mountPath: /tmp
            name: kubectl
      containers:
        - name: executor
          image: "benchmarkai/executor"
          env:
          - name: AVAILABILITY_ZONES
            valueFrom:
              configMapKeyRef:
                name: outputs-infrastructure
                key: availability_zones
          - name: KAFKA_BOOTSTRAP_SERVERS
            valueFrom:
              configMapKeyRef:
                name: outputs-infrastructure
                key: msk_bootstrap_brokers
          - name: CONSUMER_GROUP_ID
            valueFrom:
               configMapKeyRef:
                 name: executor
                 key: consumer_group_id
          - name: CONSUMER_TOPIC
            valueFrom:
              configMapKeyRef:
                name: executor
                key: consumer_topic
          - name: PRODUCER_TOPIC
            valueFrom:
              configMapKeyRef:
                name: executor
                key: producer_topic
          - name: STATUS_TOPIC
            valueFrom:
              configMapKeyRef:
                name: executor
                key: status_topic
          - name: TRANSPILER_PULLER_DOCKER_IMAGE
            valueFrom:
              configMapKeyRef:
                name: executor
                key: transpiler_puller_docker_image
          - name: TRANSPILER_METRICS_PUSHER_DOCKER_IMAGE
            valueFrom:
              configMapKeyRef:
                name: executor
                key: transpiler_metrics_pusher_docker_image
          - name: TRANSPILER_METRICS_EXTRACTOR_DOCKER_IMAGE
            valueFrom:
              configMapKeyRef:
                name: executor
                key: transpiler_metrics_extractor_docker_image
          - name: TRANSPILER_CRON_JOB_DOCKER_IMAGE
            valueFrom:
              configMapKeyRef:
                name: executor
                key: transpiler_cron_job_docker_image
          - name: TRANSPILER_JOB_STATUS_TRIGGER_DOCKER_IMAGE
            valueFrom:
              configMapKeyRef:
                name: executor
                key: transpiler_job_status_trigger_docker_image
          - name: SUPPRESS_JOB_AFFINITY
            valueFrom:
              configMapKeyRef:
                name: executor
                key: suppress_job_affinity
          - name: LOGGING_LEVEL
            value: "INFO"
          - name: KUBECTL
            value: "/kubectl/kubectl"
          volumeMounts:
            - mountPath: /kubectl
              name: kubectl
      nodeSelector:
        node.type: bai-services-cheap
      restartPolicy: Always
      volumes:
        - name: kubectl
          emptyDir: {}
