---
apiVersion: batch/v1
kind: CronJob
metadata:
  name: airm-heartbeat-dispatcher
  namespace: airm
spec:
  concurrencyPolicy: Replace
  jobTemplate:
    spec:
      template:
        metadata:
          annotations:
            sidecar.istio.io/inject: "false"
        spec:
          containers:
            - command:
                - curl
                - -X
                - POST
                - http://airm-dispatcher:80/v1/heartbeats
              image: ghcr.io/silogen/airm-dispatcher:v2025.09.001
              imagePullPolicy: IfNotPresent
              name: airm-heartbeat-cron
              resources:
                limits:
                  memory: 100Mi
                requests:
                  cpu: 50m
                  memory: 100Mi
          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 dispatcher at ${ENDPOINT_URL_TO_CHECK}:${ENDPOINT_PORT_TO_CHECK}..."; sleep 3; done; echo "Airm dispatcher is accepting connections at ${ENDPOINT_URL_TO_CHECK}:${ENDPOINT_PORT_TO_CHECK}."; sleep 12; exit 0
              env:
                - name: ENDPOINT_URL_TO_CHECK
                  value: airm-dispatcher.airm.svc.cluster.local
                - name: ENDPOINT_PORT_TO_CHECK
                  value: "80"
              image: ubuntu@sha256:09506232a8004baa32c47d68f1e5c307d648fdd59f5e7eaa42aaf87914100db3 # Original tag: 22.04
              imagePullPolicy: IfNotPresent
              name: check-dispatcher-is-ready
              securityContext:
                allowPrivilegeEscalation: false
                capabilities:
                  add:
                    - SETUID
                    - SETGID
                    - CHOWN
                    - DAC_OVERRIDE
                    - FOWNER
                    - FSETID
                  drop:
                    - ALL
                runAsNonRoot: false
                runAsUser: 0
                seccompProfile:
                  type: RuntimeDefault
          restartPolicy: OnFailure
  schedule: '*/1 * * * *'
  suspend: false