From e2cd94040d4528672b195f8a5a4e93190b3effe8 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 31 May 2023 19:15:46 +0800 Subject: [PATCH] [Backport release-0.5] Fix: fix terminate suspending steps (#161) Fix: fix terminate suspending steps Signed-off-by: FogDong (cherry picked from commit 8fe456cc5370f0464d1c95619905b4fdd243797f) Co-authored-by: FogDong --- controllers/workflow_test.go | 16 ++-------------- pkg/utils/operation.go | 4 ++-- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/controllers/workflow_test.go b/controllers/workflow_test.go index 0bc7250..0fa7b7b 100644 --- a/controllers/workflow_test.go +++ b/controllers/workflow_test.go @@ -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) @@ -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) @@ -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()) -} diff --git a/pkg/utils/operation.go b/pkg/utils/operation.go index ca5f4fe..09dc472 100644 --- a/pkg/utils/operation.go +++ b/pkg/utils/operation.go @@ -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: @@ -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: