Wait on condition in Taskfile

386 Views Asked by At

Is there a way to use a precondition in a Taskfile.yaml to wait for a condition to be true, before running cmds? (precondition makes the task fail, not wait)

For example, I would like to wait for a Kubernetes CRD to be fully available before running a task.

1

There are 1 best solutions below

0
Henrik On

I think the best way there is right now, is to do

# ...
version: '3'
tasks:
  deploy:
    cmds:
    - task: await
      vars:
      - { CRD: "postgrescluster" }

  await:
    cmds:
    - |
      until kubectl wait --for condition=established --timeout=60s crd/{{.CRD}}; do \
        sleep 1; \
      done

As per https://taskfile.dev/usage/#task-dependencies