---
apiVersion: batch/v1
kind: Job
metadata:
  annotations:
    # argocd.argoproj.io/sync-wave: "10"
    argocd.argoproj.io/hook: PreSync
    argocd.argoproj.io/hook-delete-policy: BeforeHookCreation
  name: wait-for-argo-deployed
  # generateName: csv-wait-job-
  namespace: telco-gitops
spec:
  template:
    spec:
      containers:
        - image: registry.redhat.io/openshift4/ose-cli:latest
          command:
            - /bin/bash
            - -c
            - |
              echo "ArgoCD Hook"
              CSV_STATUS="Pausing $SLEEP seconds..."
              while [[ "$CSV_STATUS" != *"condition met" ]]; do
                echo "Waiting for the Telco GitOps Operator to be ready. ($CSV_STATUS)"
                sleep $SLEEP
                CSV_STATUS=$( oc -n telco-gitops wait --for=condition=Ready pod -l app.kubernetes.io/name=telco-gitops-server )
              done
              echo "All done! Hooray!"
          imagePullPolicy: IfNotPresent
          name: mcp-wait-job
          env:
          - name: SLEEP
            value: "3"
      dnsPolicy: ClusterFirst
      restartPolicy: OnFailure
      serviceAccount: cli-job-sa
      serviceAccountName: cli-job-sa
      terminationGracePeriodSeconds: 30
