Skip to content

Commit

Permalink
[Backport release-0.5] Fix: fix terminate suspending steps (#161)
Browse files Browse the repository at this point in the history
Fix: fix terminate suspending steps

Signed-off-by: FogDong <[email protected]>
(cherry picked from commit 8fe456c)

Co-authored-by: FogDong <[email protected]>
  • Loading branch information
github-actions[bot] and FogDong authored May 31, 2023
1 parent 1f15ba0 commit e2cd940
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
16 changes: 2 additions & 14 deletions controllers/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,7 @@ var _ = Describe("Test Workflow", func() {
Expect(wrObj.Status.Phase).Should(BeEquivalentTo(v1alpha1.WorkflowStateSuspending))

// terminate the workflow
wrObj.Status.Terminated = true
wrObj.Status.Suspend = false
wrObj.Status.Steps[0].Phase = v1alpha1.WorkflowStepPhaseFailed
wrObj.Status.Steps[0].Reason = wfTypes.StatusReasonTerminate
Expect(k8sClient.Status().Patch(ctx, wrObj, client.Merge)).Should(BeNil())
Expect(utils.TerminateWorkflow(ctx, k8sClient, wrObj)).Should(BeNil())

tryReconcile(reconciler, wr.Name, wr.Namespace)

Expand Down Expand Up @@ -1743,7 +1739,7 @@ var _ = Describe("Test Workflow", func() {
// terminate manually
checkRun := &v1alpha1.WorkflowRun{}
Expect(k8sClient.Get(ctx, wrKey, checkRun)).Should(BeNil())
terminateWorkflowRun(ctx, checkRun, 0)
Expect(utils.TerminateWorkflow(ctx, k8sClient, checkRun)).Should(BeNil())

tryReconcile(reconciler, wr.Name, wr.Namespace)

Expand Down Expand Up @@ -1860,11 +1856,3 @@ func setupTestDefinitions(ctx context.Context, defs []string, namespace string)
})).Should(SatisfyAny(BeNil(), &utils.AlreadyExistMatcher{}))
}
}

func terminateWorkflowRun(ctx context.Context, run *v1alpha1.WorkflowRun, index int) {
run.Status.Suspend = false
run.Status.Terminated = true
run.Status.Steps[index].Phase = v1alpha1.WorkflowStepPhaseFailed
run.Status.Steps[index].Reason = wfTypes.StatusReasonTerminate
Expect(k8sClient.Status().Update(ctx, run)).Should(BeNil())
}
4 changes: 2 additions & 2 deletions pkg/utils/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func TerminateWorkflow(ctx context.Context, cli client.Client, run *v1alpha1.Wor
if step.Reason != wfTypes.StatusReasonFailedAfterRetries && step.Reason != wfTypes.StatusReasonTimeout {
steps[i].Reason = wfTypes.StatusReasonTerminate
}
case v1alpha1.WorkflowStepPhaseRunning:
case v1alpha1.WorkflowStepPhaseRunning, v1alpha1.WorkflowStepPhaseSuspending:
steps[i].Phase = v1alpha1.WorkflowStepPhaseFailed
steps[i].Reason = wfTypes.StatusReasonTerminate
default:
Expand All @@ -324,7 +324,7 @@ func TerminateWorkflow(ctx context.Context, cli client.Client, run *v1alpha1.Wor
if sub.Reason != wfTypes.StatusReasonFailedAfterRetries && sub.Reason != wfTypes.StatusReasonTimeout {
steps[i].SubStepsStatus[j].Reason = wfTypes.StatusReasonTerminate
}
case v1alpha1.WorkflowStepPhaseRunning:
case v1alpha1.WorkflowStepPhaseRunning, v1alpha1.WorkflowStepPhaseSuspending:
steps[i].SubStepsStatus[j].Phase = v1alpha1.WorkflowStepPhaseFailed
steps[i].SubStepsStatus[j].Reason = wfTypes.StatusReasonTerminate
default:
Expand Down

0 comments on commit e2cd940

Please sign in to comment.