apiVersion: apps/v1
kind: Deployment
metadata:
  name: media-resolver
  labels:
    app: media-resolver
    type: media
    core.airy.co/managed: "true"
    core.airy.co/mandatory: "{{ .Values.mandatory }}"
    core.airy.co/component: "{{ .Values.component }}"
spec:
  replicas: 0
  selector:
    matchLabels:
      app: media-resolver
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: media-resolver
    spec:
      containers:
        - name: app
          image: "{{ .Values.global.containerRegistry}}/{{ .Values.image }}:{{ default .Chart.Version .Values.global.appImageTag }}"
          imagePullPolicy: Always
          envFrom:
            - configMapRef:
                name: security
            - configMapRef:
                name: "media-storage"
          env:
          - name: KAFKA_BROKERS
            valueFrom:
              configMapKeyRef:
                name: kafka-config
                key: KAFKA_BROKERS
          - name: KAFKA_SCHEMA_REGISTRY_URL
            valueFrom:
              configMapKeyRef:
                name: kafka-config
                key: KAFKA_SCHEMA_REGISTRY_URL
          - name: KAFKA_COMMIT_INTERVAL_MS
            valueFrom:
              configMapKeyRef:
                name: kafka-config
                key: KAFKA_COMMIT_INTERVAL_MS
          livenessProbe:
            httpGet:
              path: /actuator/health
              port: 8080
              httpHeaders:
                - name: Health-Check
                  value: health-check
            initialDelaySeconds: 60
            periodSeconds: 10
            failureThreshold: 3
      initContainers:
      - name: wait
        image: busybox
        command: ["/bin/sh", "/opt/provisioning/wait-for-minimum-kafkas.sh"]
        env:
        - name: KAFKA_BROKERS
          valueFrom:
            configMapKeyRef:
              name: kafka-config
              key: KAFKA_BROKERS
        - name: REPLICAS
          valueFrom:
            configMapKeyRef:
              name: kafka-config
              key: KAFKA_MINIMUM_REPLICAS
        volumeMounts:
        - name: provisioning-scripts
          mountPath: /opt/provisioning
      volumes:
        - name: provisioning-scripts
          configMap:
            name: provisioning-scripts
