apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: wait-for-rollout
  labels:
    dagweave.io/catalog-item: wait-for-rollout
  annotations:
    dagweave.io/catalog-version: "1.0.6"
    dagweave.io/catalog-category: "Kubernetes"
spec:
  entrypoint: wait
  templates:
    - name: wait
      metadata:
        annotations:
          # Dagweave Local reads these off the body, the only part of an item that lands in a user's file.
          dagweave.io/local-support: unsupported
          dagweave.io/local-support-reason: >-
            kubectl rollout status has to read and watch the workload before it can wait
            on it. On Dagweave Local the pod runs as the default service account of the
            hidden cluster's argo namespace, which holds nothing in the apps group, so
            that read is refused and the step fails on a 403 without ever waiting for
            anything. The rollout you meant to watch is on a cluster this run cannot
            reach.
      inputs:
        parameters:
          # Rollout-capable kind: deployment, statefulset, or daemonset.
          - name: kind
            default: deployment
          - name: name
          - name: namespace
            default: default
          # Max time to wait, e.g. 300s or 5m.
          - name: timeout
            default: 300s
      container:
        # bitnami/kubectl:latest
        image: bitnami/kubectl@sha256:bedd34c910e2a5ce9836813d16444af449d7fe07a29136d59f34e861e8e660c5
        command: [sh, -c]
        # Blocks until the rollout completes or the timeout elapses, using the
        # in-cluster serviceAccount.
        args:
          - |
            set -eu
            kubectl rollout status "${KIND}/${NAME}" -n "${NAMESPACE}" --timeout="${TIMEOUT}"
        env:
          - name: KIND
            value: "{{inputs.parameters.kind}}"
          - name: NAME
            value: "{{inputs.parameters.name}}"
          - name: NAMESPACE
            value: "{{inputs.parameters.namespace}}"
          - name: TIMEOUT
            value: "{{inputs.parameters.timeout}}"
