Workflow-level `spec.suspend: true` makes `stop` and `terminate` a silent no-op
Pre-requisites
- I have double-checked my configuration
- I have tested with the
:latestimage tag (i.e.quay.io/argoproj/workflow-controller:latest) and can confirm the issue still exists on:latest. If not, I have explained why, in detail, in my description below. - I have searched existing issues and could not find a match for this bug
- I'd like to contribute the fix myself (see contributing guide)
What happened? What did you expect to happen?
A Workflow with spec.suspend: true (workflow-level suspend, not a suspend
template) cannot be stopped or terminated. argo stop, argo terminate and the
corresponding UI buttons all report success — the API server does record
spec.shutdown on the object — but the controller never acts on it. The workflow
stays in Running forever.
The only way out is to resume it first, or to delete it.
I expected terminate to work on a suspended workflow. Terminating something that
has not started yet is the most natural thing to want to do with it, and it should
not require first releasing it to run.
Cause
operate() returns at the suspend check, which sits before the entrypoint is ever
evaluated:
if woc.ShouldSuspend() {
woc.log.Info(ctx, "workflow suspended")
return
}
...
node, err := woc.executeTemplate(ctx, woc.wf.Name, &wfv1.WorkflowStep{Template: woc.execWf.Spec.Entrypoint}, ...)Everything that implements shutdown lives after that return: ShouldExecute is
only consulted while executing nodes, and the Stopped with strategy '%s'
transition that marks the workflow Failed happens once the entrypoint node is
fulfilled. failNodesWithoutCreatedPodsAfterDeadlineOrShutdown() does run earlier,
but a workflow that has never left spec.suspend has no nodes for it to fail, and
nothing marks the workflow itself.
Nothing between the shutdown being recorded and that early return looks at
woc.GetShutdownStrategy(), so the strategy is simply never applied.
Why this is worse than it looks
Workflow-level suspend is the natural building block for an approval gate: hold the
workflow at admission with spec.suspend: true, and have an approval service clear
it. We do exactly that with a MutatingAdmissionPolicy, and pair it with a
ValidatingAdmissionPolicy that only lets the approval service clear spec.suspend
so the gate cannot be bypassed by talking to the API server directly.
The combination deadlocks. A user who submits a workflow and immediately changes their mind cannot terminate it (silently ignored) and is not allowed to resume it (that is the whole point of the gate). Deleting the object is the only remaining action, which loses the record of the submission.
Steps to reproduce
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: suspend-terminate-
spec:
entrypoint: main
suspend: true
templates:
- name: main
container:
image: busybox
command: [sh, -c]
args: ["sleep 60"]$ argo submit repro.yaml
$ argo terminate suspend-terminate-xxxxx
Workflow 'suspend-terminate-xxxxx' terminated
$ kubectl get wf suspend-terminate-xxxxx -o jsonpath='{.spec.shutdown} {.status.phase}'
Terminate RunningIt stays Running indefinitely. argo stop behaves identically.
Controller logs
Every reconcile after the terminate looks like this — the shutdown is on the object, and the controller still gives up at the suspend check:
level=INFO msg="Processing workflow" phase=Running resourceVersion=33024817 workflow=parallelism-test-kns7t
level=INFO msg="Task-result reconciliation" numObjs=0 workflow=parallelism-test-kns7t
level=INFO msg="workflow suspended" workflow=parallelism-test-kns7t
level=INFO msg="Workflow update successful" phase=Running resourceVersion=33024817 workflow=parallelism-test-kns7tSuggested fix
Let a requested shutdown take precedence over the suspend, e.g. skip the early
return when woc.GetShutdownStrategy().Enabled() and let the existing shutdown path
fail the nodes and the workflow. Terminate is trivially safe here, since
ShouldExecute is false for every node including exit handlers, so nothing runs.
Stop would run exit handlers on a workflow that never started, which I think
matches the documented meaning of Stop but is worth a second opinion.
Failing that, argo stop/argo terminate should at least return an error on a
workflow-level-suspended workflow rather than reporting success for something that
will never happen.
Version
v4.1.2. The relevant code in workflow/controller/operator.go is unchanged on main
at time of writing.
Version(s)
v4.1.2
Paste a minimal workflow that reproduces the issue. We must be able to run the workflow; don't enter a workflow that uses private images.
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
generateName: suspend-terminate-
spec:
entrypoint: main
suspend: true
templates:
- name: main
container:
image: busybox
command: [sh, -c]
args: ["sleep 60"]Logs from the workflow controller
level=INFO msg="Processing workflow" phase=Running resourceVersion=33024817 workflow=parallelism-test-kns7t
level=INFO msg="Task-result reconciliation" numObjs=0 workflow=parallelism-test-kns7t
level=INFO msg="workflow suspended" workflow=parallelism-test-kns7t
level=INFO msg="Workflow update successful" phase=Running resourceVersion=33024817 workflow=parallelism-test-kns7tLogs from in your workflow's wait container
kubectl logs -n argo -c wait -l workflows.argoproj.io/workflow=${workflow},workflow.argoproj.io/phase!=SucceededSource: argoproj/argo-workflows