apiVersion: apps/v1
kind: Deployment
metadata:
  name: emissary-ingress
  namespace: emissary
spec:
  template:
    spec:
      priorityClassName: edge-p2-critical-services
      initContainers:
      - name: wait-for-apiext
        image: us-east1-docker.pkg.dev/ret-edge-pltf-infra/workloads/alpine_kubectl@sha256:a55a7c36a59ff831c38e38647a63e8931b4a82e626bb8585244182d8e3061b9b
      - name: wait-for-crds
        image: us-east1-docker.pkg.dev/ret-edge-pltf-infra/workloads/alpine_kubectl@sha256:a55a7c36a59ff831c38e38647a63e8931b4a82e626bb8585244182d8e3061b9b
        command:
        - /bin/sh
        - -c
        args:
        - |
          pallet_name="emissary-crds"
          group="getambassador.io"
          timeout=300
          echo "Waiting for all CRDs with group '$group' to be under '$pallet_name' pallet..."
          i=0
          while [ $i -lt $timeout ]; do
            all_updated=true
            crds=$(kubectl get crds -o jsonpath="{.items[?(@.spec.group == \"$group\")].metadata.name}")
            if [ -z "$crds" ]; then
              echo "No CRDs found in group '$group'."
              all_updated=false
            else
              for crd in $crds; do
                annotation=$(kubectl get crd "$crd" -o jsonpath="{.metadata.annotations.pallet\.edge\.ncr\.com/name}")
                if [ "$annotation" != "$pallet_name" ]; then
                  all_updated=false
                  break
                fi
              done
            fi
            if [ "$all_updated" = true ]; then
              echo "Complete."
              exit 0
            fi
            sleep 1
            i=$((i + 1))
          done
          echo "Timeout of '$timeout' seconds reached."
          exit 1
        imagePullPolicy: IfNotPresent
        securityContext:
          runAsUser: 8888
      containers:
      - name: ambassador
        image: bzl://hack/deps:emissary_container_push
        env:
        - name: SCOUT_DISABLE
          value: "1"
      imagePullSecrets:
      - name: edge-docker-pull-secret