Skip to content

Commit d6e65ee

Browse files
authored
Fix: fix suspend judgement (#197)
fix: fix suspend judgement Signed-off-by: FogDong <[email protected]>
1 parent e2cd940 commit d6e65ee

File tree

5 files changed

+34
-29
lines changed

5 files changed

+34
-29
lines changed

.github/workflows/e2e.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ env:
1717
# Common versions
1818
GO_VERSION: '1.19'
1919
GOLANGCI_VERSION: 'v1.49'
20-
K3D_IMAGE_VERSION: '[\"v1.20\",\"v1.24\"]'
21-
K3D_IMAGE_VERSIONS: '[\"v1.20\",\"v1.24\"]'
20+
K3D_IMAGE_VERSION: '[\"v1.24\"]'
21+
K3D_IMAGE_VERSIONS: '[\"v1.24\"]'
2222

2323
jobs:
2424

makefiles/dependency.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ goimports:
5151
ifeq (, $(shell which goimports))
5252
@{ \
5353
set -e ;\
54-
go install golang.org/x/tools/cmd/goimports@latest ;\
54+
go install golang.org/x/tools/cmd/goimports@v0.1.12 ;\
5555
}
5656
GOIMPORTS=$(GOBIN)/goimports
5757
else
@@ -99,4 +99,4 @@ $(CONTROLLER_GEN): $(LOCALBIN)
9999
.PHONY: envtest
100100
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
101101
$(ENVTEST): $(LOCALBIN)
102-
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
102+
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@v0.0.0-20230216140739-c98506dc3b8e

pkg/executor/workflow.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,6 @@ func (w *workflowExecutor) ExecuteRunners(ctx monitorContext.Context, taskRunner
115115
}
116116
return v1alpha1.WorkflowStateFailed, nil
117117
}
118-
if checkWorkflowSuspended(status) {
119-
return v1alpha1.WorkflowStateSuspending, nil
120-
}
121-
if allRunnersSucceeded {
122-
return v1alpha1.WorkflowStateSucceeded, nil
123-
}
124118

125119
wfCtx, err := w.makeContext(ctx, w.instance.Name)
126120
if err != nil {
@@ -129,6 +123,13 @@ func (w *workflowExecutor) ExecuteRunners(ctx monitorContext.Context, taskRunner
129123
}
130124
w.wfCtx = wfCtx
131125

126+
if checkWorkflowSuspended(status) {
127+
return v1alpha1.WorkflowStateSuspending, nil
128+
}
129+
if allRunnersSucceeded {
130+
return v1alpha1.WorkflowStateSucceeded, nil
131+
}
132+
132133
if cacheValue, ok := StepStatusCache.Load(cacheKey); ok {
133134
// handle cache resource
134135
if len(status.Steps) < cacheValue.(int) {
@@ -175,11 +176,11 @@ func checkWorkflowSuspended(status *v1alpha1.WorkflowRunStatus) bool {
175176
// if workflow is suspended and the suspended step is still running, return false to run the suspended step
176177
if status.Suspend {
177178
for _, step := range status.Steps {
178-
if step.Phase == v1alpha1.WorkflowStepPhaseSuspending {
179+
if step.Reason == types.StatusReasonSuspend && step.Phase == v1alpha1.WorkflowStepPhaseSuspending {
179180
return false
180181
}
181182
for _, sub := range step.SubStepsStatus {
182-
if sub.Phase == v1alpha1.WorkflowStepPhaseSuspending {
183+
if sub.Reason == types.StatusReasonSuspend && sub.Phase == v1alpha1.WorkflowStepPhaseSuspending {
183184
return false
184185
}
185186
}

pkg/executor/workflow_test.go

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1772,10 +1772,11 @@ var _ = Describe("Test Workflow", func() {
17721772
},
17731773
}, {
17741774
StepStatus: v1alpha1.StepStatus{
1775-
Name: "s2",
1776-
ID: "s2",
1777-
Type: "suspend",
1778-
Phase: v1alpha1.WorkflowStepPhaseSuspending,
1775+
Name: "s2",
1776+
ID: "s2",
1777+
Type: "suspend",
1778+
Reason: types.StatusReasonSuspend,
1779+
Phase: v1alpha1.WorkflowStepPhaseSuspending,
17791780
},
17801781
}},
17811782
})).Should(BeEquivalentTo(""))
@@ -1805,10 +1806,11 @@ var _ = Describe("Test Workflow", func() {
18051806
},
18061807
}, {
18071808
StepStatus: v1alpha1.StepStatus{
1808-
Name: "s2",
1809-
ID: "s2",
1810-
Type: "suspend",
1811-
Phase: v1alpha1.WorkflowStepPhaseSucceeded,
1809+
Name: "s2",
1810+
ID: "s2",
1811+
Type: "suspend",
1812+
Reason: types.StatusReasonSuspend,
1813+
Phase: v1alpha1.WorkflowStepPhaseSucceeded,
18121814
},
18131815
}, {
18141816
StepStatus: v1alpha1.StepStatus{
@@ -1884,10 +1886,11 @@ var _ = Describe("Test Workflow", func() {
18841886
Type: "success",
18851887
Phase: v1alpha1.WorkflowStepPhaseSucceeded,
18861888
}, {
1887-
Name: "s2-sub2",
1888-
ID: "s2-sub2",
1889-
Type: "suspend",
1890-
Phase: v1alpha1.WorkflowStepPhaseSuspending,
1889+
Name: "s2-sub2",
1890+
ID: "s2-sub2",
1891+
Type: "suspend",
1892+
Reason: types.StatusReasonSuspend,
1893+
Phase: v1alpha1.WorkflowStepPhaseSuspending,
18911894
},
18921895
},
18931896
}},
@@ -2234,10 +2237,11 @@ func makeRunner(step v1alpha1.WorkflowStep, subTaskRunners []types.TaskRunner) t
22342237
}
22352238
}
22362239
return v1alpha1.StepStatus{
2237-
Name: step.Name,
2238-
Type: "suspend",
2239-
ID: step.Name,
2240-
Phase: v1alpha1.WorkflowStepPhaseSuspending,
2240+
Name: step.Name,
2241+
Type: "suspend",
2242+
ID: step.Name,
2243+
Reason: types.StatusReasonSuspend,
2244+
Phase: v1alpha1.WorkflowStepPhaseSuspending,
22412245
}, &types.Operation{
22422246
Suspend: true,
22432247
}, nil

pkg/tasks/custom/task.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ func (exec *executor) Terminate(message string) {
415415
// Wait let workflow wait.
416416
func (exec *executor) Wait(message string) {
417417
exec.wait = true
418-
if exec.wfStatus.Phase != v1alpha1.WorkflowStepPhaseFailed {
418+
if exec.wfStatus.Phase != v1alpha1.WorkflowStepPhaseFailed && exec.wfStatus.Phase != v1alpha1.WorkflowStepPhaseSuspending {
419419
exec.wfStatus.Phase = v1alpha1.WorkflowStepPhaseRunning
420420
exec.wfStatus.Reason = types.StatusReasonWait
421421
if message != "" {

0 commit comments

Comments
 (0)