apiVersion: apps/v1
kind: Deployment
metadata:
  name: sources-chatplugin
  labels:
    app: sources-chatplugin
    type: sources
    core.airy.co/managed: "true"
    core.airy.co/mandatory: "{{ .Values.mandatory }}"
    core.airy.co/component: "{{ .Values.component }}"
spec:
  replicas: 1
  selector:
    matchLabels:
      app: sources-chatplugin
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: sources-chatplugin
    spec:
      containers:
      - name: app
        image: "{{ .Values.global.containerRegistry}}/{{ .Values.backend.image }}:{{ default .Chart.Version .Values.global.appImageTag }}"
        imagePullPolicy: Always
        envFrom:
          - configMapRef:
              name: security
        env:
        - name: allowedOrigins
          valueFrom:
            configMapKeyRef:
              name: security
              key: allowedOrigins
        - name: jwtSecret
          valueFrom:
            configMapKeyRef:
              name: core-config
              key: CHATPLUGIN_JWT_SECRET
        - 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
        imagePullPolicy: IfNotPresent
        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
