---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: airm-dispatcher
  namespace: airm
spec:
  replicas: 1
  selector:
    matchLabels:
      app: airm-dispatcher
  template:
    metadata:
      labels:
        app: airm-dispatcher
    spec:
      containers:
        - env:
            - name: KUBE_CLUSTER_NAME
              value: demo-cluster
            - name: ORG_NAME
              value: demo
            - name: RABBITMQ_HOST
              value: airm-rabbitmq.airm.svc.cluster.local
            - name: RABBITMQ_PORT
              value: "5672"
            - name: RABBITMQ_AIRM_COMMON_VHOST
              value: vh_airm_common
            - name: RABBITMQ_AIRM_COMMON_QUEUE
              value: airm_common
            - name: RABBITMQ_USER
              valueFrom:
                secretKeyRef:
                  key: username
                  name: airm-rabbitmq-common-vhost-user
            - name: RABBITMQ_PASSWORD
              valueFrom:
                secretKeyRef:
                  key: password
                  name: airm-rabbitmq-common-vhost-user
          image: ghcr.io/silogen/airm-dispatcher:v2025.09.001
          imagePullPolicy: IfNotPresent
          livenessProbe:
            failureThreshold: 3
            httpGet:
              path: /v1/health
              port: 8080
            initialDelaySeconds: 10
            periodSeconds: 5
            successThreshold: 1
            timeoutSeconds: 2
          name: airm-dispatcher
          ports:
            - containerPort: 8080
          readinessProbe:
            failureThreshold: 3
            httpGet:
              path: /v1/health
              port: 8080
            initialDelaySeconds: 10
            periodSeconds: 5
            successThreshold: 1
            timeoutSeconds: 2
          resources:
            limits:
              memory: 1Gi
            requests:
              cpu: 500m
              memory: 1Gi
          securityContext:
            runAsUser: 0
      initContainers:
        - command:
            - /bin/bash
            - -c
            - apt-get update -y 1> /dev/null 2>&1 && apt-get install ncat -y 1> /dev/null 2>&1 && while ! nc -z "$ENDPOINT_URL_TO_CHECK" "$ENDPOINT_PORT_TO_CHECK"; do echo "Waiting for Airm UI at ${ENDPOINT_URL_TO_CHECK}:${ENDPOINT_PORT_TO_CHECK}..."; sleep 3; done; echo "Airm UI is accepting connections at ${ENDPOINT_URL_TO_CHECK}:${ENDPOINT_PORT_TO_CHECK}."; sleep 12; exit 0
          env:
            - name: ENDPOINT_URL_TO_CHECK
              value: airm-api.airm.svc.cluster.local
            - name: ENDPOINT_PORT_TO_CHECK
              value: "80"
          image: ubuntu@sha256:09506232a8004baa32c47d68f1e5c307d648fdd59f5e7eaa42aaf87914100db3 # Original tag: 22.04
          imagePullPolicy: IfNotPresent
          name: check-airm-api-is-ready
          securityContext:
            allowPrivilegeEscalation: false
            capabilities:
              add:
                - SETUID
                - SETGID
                - CHOWN
                - DAC_OVERRIDE
                - FOWNER
                - FSETID
              drop:
                - ALL
            runAsNonRoot: false
            runAsUser: 0
            seccompProfile:
              type: RuntimeDefault
      serviceAccountName: airm-dispatcher-sa