#  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: sm-executor
  labels:
    app: benchmark-ai
spec:
  selector:
    matchLabels:
      app: benchmark-ai
  replicas: 1
  template:
    metadata:
      labels:
        app: benchmark-ai
        service: sm-executor
      annotations:
        iam.amazonaws.com/role: sagemaker-executor-role
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: service
                    operator: In
                    values:
                      - sm-executor
              topologyKey: kubernetes.io/hostname
      containers:
        - name: sm-executor
          image: "benchmarkai/sm-executor"
          env:
          - name: KAFKA_BOOTSTRAP_SERVERS
            valueFrom:
              configMapKeyRef:
                name: outputs-infrastructure
                key: msk_bootstrap_brokers
          - name: CONSUMER_GROUP_ID
            valueFrom:
               configMapKeyRef:
                 name: sm-executor
                 key: consumer_group_id
          - name: CONSUMER_TOPIC
            valueFrom:
              configMapKeyRef:
                name: sm-executor
                key: consumer_topic
          - name: PRODUCER_TOPIC
            valueFrom:
              configMapKeyRef:
                name: sm-executor
                key: producer_topic
          - name: STATUS_TOPIC
            valueFrom:
              configMapKeyRef:
                name: sm-executor
                key: status_topic
          - name: SAGEMAKER_OUTPUT_BUCKET
            valueFrom:
              configMapKeyRef:
                name: outputs-infrastructure
                key: sagemaker_output_s3
          - name: SAGEMAKER_NODATASET
            valueFrom:
              configMapKeyRef:
                name: outputs-infrastructure
                key: sagemaker_nodata_s3
          - name: SAGEMAKER_ROLE
            valueFrom:
              configMapKeyRef:
                name: outputs-infrastructure
                key: sagemaker_role_name
          - name: SAGEMAKER_SUBNETS
            valueFrom:
              configMapKeyRef:
                name: outputs-infrastructure
                key: private_subnets
          - name: SAGEMAKER_SECURITY_GROUP_IDS
            valueFrom:
              configMapKeyRef:
                name: outputs-infrastructure
                key: loopback_security_group_id
          - name: AWS_DEFAULT_REGION
            valueFrom:
              configMapKeyRef:
                key: region
                name: outputs-infrastructure
          - name: LOGGING_LEVEL
            value: "INFO"
      nodeSelector:
        node.type: bai-services-cheap
      restartPolicy: Always
