Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: fix step depends on skip #146

Merged
merged 2 commits into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions controllers/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,21 @@ var _ = Describe("Test Workflow", func() {
Properties: &runtime.RawExtension{Raw: []byte(`{"cmd":["sleep","1000"],"image":"busybox"}`)},
},
},
{
WorkflowStepBase: v1alpha1.WorkflowStepBase{
Name: "step3",
Type: "suspend",
If: "false",
},
},
{
WorkflowStepBase: v1alpha1.WorkflowStepBase{
Name: "step4",
Type: "test-apply",
Properties: &runtime.RawExtension{Raw: []byte(`{"cmd":["sleep","1000"],"image":"busybox"}`)},
DependsOn: []string{"step3"},
},
},
}
wr.Spec.Mode = &v1alpha1.WorkflowExecuteMode{
Steps: v1alpha1.WorkflowModeDAG,
Expand All @@ -551,6 +566,7 @@ var _ = Describe("Test Workflow", func() {
expDeployment := &appsv1.Deployment{}
step1Key := types.NamespacedName{Namespace: wr.Namespace, Name: "step1"}
step2Key := types.NamespacedName{Namespace: wr.Namespace, Name: "step2"}
step4Key := types.NamespacedName{Namespace: wr.Namespace, Name: "step4"}
Expect(k8sClient.Get(ctx, step2Key, expDeployment)).Should(utils.NotFoundMatcher{})

checkRun := &v1alpha1.WorkflowRun{}
Expand All @@ -571,6 +587,8 @@ var _ = Describe("Test Workflow", func() {

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

Expect(k8sClient.Get(ctx, step4Key, expDeployment)).Should(utils.NotFoundMatcher{})

Expect(k8sClient.Get(ctx, wrKey, checkRun)).Should(BeNil())
Expect(checkRun.Status.Mode.Steps).Should(BeEquivalentTo(v1alpha1.WorkflowModeDAG))
Expect(checkRun.Status.Phase).Should(BeEquivalentTo(v1alpha1.WorkflowStateSucceeded))
Expand Down
14 changes: 9 additions & 5 deletions pkg/executor/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ func (e *engine) generateRunOptions(ctx monitorContext.Context, dependsOnPhase v
case "always":
return &types.PreCheckResult{Skip: false}, nil
case "":
return &types.PreCheckResult{Skip: isUnsuccessfulStep(dependsOnPhase)}, nil
return &types.PreCheckResult{Skip: isUnsuccessfulStep(dependsOnPhase, len(step.DependsOn) > 0)}, nil
default:
ifValue, err := custom.ValidateIfValue(e.wfCtx, step, e.stepStatus, options)
if err != nil {
Expand Down Expand Up @@ -781,14 +781,15 @@ func (e *engine) needStop() bool {
}

func (e *engine) findDependPhase(taskRunners []types.TaskRunner, index int, dag bool) v1alpha1.WorkflowStepPhase {
if dag {
dependsOn := len(e.stepDependsOn[taskRunners[index].Name()]) > 0
if dag || dependsOn {
return e.findDependsOnPhase(taskRunners[index].Name())
}
if index < 1 {
return v1alpha1.WorkflowStepPhaseSucceeded
}
for i := index - 1; i >= 0; i-- {
if isUnsuccessfulStep(e.stepStatus[taskRunners[i].Name()].Phase) {
if isUnsuccessfulStep(e.stepStatus[taskRunners[i].Name()].Phase, dependsOn) {
return e.stepStatus[taskRunners[i].Name()].Phase
}
}
Expand All @@ -800,14 +801,17 @@ func (e *engine) findDependsOnPhase(name string) v1alpha1.WorkflowStepPhase {
if e.stepStatus[dependsOn].Phase != v1alpha1.WorkflowStepPhaseSucceeded {
return e.stepStatus[dependsOn].Phase
}
if result := e.findDependsOnPhase(dependsOn); isUnsuccessfulStep(result) {
if result := e.findDependsOnPhase(dependsOn); result != v1alpha1.WorkflowStepPhaseSucceeded {
return result
}
}
return v1alpha1.WorkflowStepPhaseSucceeded
}

func isUnsuccessfulStep(phase v1alpha1.WorkflowStepPhase) bool {
func isUnsuccessfulStep(phase v1alpha1.WorkflowStepPhase, dependsOn bool) bool {
if dependsOn {
return phase != v1alpha1.WorkflowStepPhaseSucceeded
}
return phase != v1alpha1.WorkflowStepPhaseSucceeded && phase != v1alpha1.WorkflowStepPhaseSkipped
}

Expand Down