Skip to content

Commit

Permalink
Merge pull request #21 from FogDong/fix-render
Browse files Browse the repository at this point in the history
Fix: fix the workflow status when a step is failed because of rendering
  • Loading branch information
FogDong authored Aug 10, 2022
2 parents d3624f6 + 5b20901 commit 3adc839
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
47 changes: 46 additions & 1 deletion controllers/workflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ var _ = Describe("Test Workflow", func() {
},
},
}
testDefinitions := []string{wfStepApplyDefYaml, wfStepApplyObjectDefYaml}
testDefinitions := []string{wfStepApplyDefYaml, wfStepApplyObjectDefYaml, wfStepFailedRenderDefYaml}

BeforeEach(func() {
setupNamespace(ctx, namespace)
Expand Down Expand Up @@ -601,6 +601,39 @@ var _ = Describe("Test Workflow", func() {
Expect(checkRun.Status.Steps[1].Reason).Should(BeEquivalentTo(wfTypes.StatusReasonFailedAfterRetries))
})

It("test failed render", func() {
wr := wrTemplate.DeepCopy()
wr.Name = "wr-failed-render"
wr.Spec.WorkflowSpec.Steps = []v1alpha1.WorkflowStep{
{
WorkflowStepBase: v1alpha1.WorkflowStepBase{
Name: "step1",
Type: "failed-render",
Properties: &runtime.RawExtension{Raw: []byte(`{"cmd":["sleep","1000"],"image":"busybox"}`)},
},
},
{
WorkflowStepBase: v1alpha1.WorkflowStepBase{
Name: "step2",
Type: "test-apply",
Properties: &runtime.RawExtension{Raw: []byte(`{"cmd":["sleep","1000"],"image":"busybox"}`)},
},
},
}

Expect(k8sClient.Create(ctx, wr)).Should(BeNil())
wrKey := types.NamespacedName{Namespace: wr.Namespace, Name: wr.Name}
checkRun := &v1alpha1.WorkflowRun{}
Expect(k8sClient.Get(ctx, wrKey, checkRun)).Should(BeNil())

tryReconcile(reconciler, wr.Name, wr.Namespace)
Expect(k8sClient.Get(ctx, wrKey, checkRun)).Should(BeNil())
Expect(checkRun.Status.Phase).Should(BeEquivalentTo(v1alpha1.WorkflowRunTerminated))
Expect(checkRun.Status.Steps[0].Phase).Should(BeEquivalentTo(v1alpha1.WorkflowStepPhaseFailed))
Expect(checkRun.Status.Steps[0].Reason).Should(BeEquivalentTo(wfTypes.StatusReasonRendering))
Expect(checkRun.Status.Steps[1].Phase).Should(BeEquivalentTo(v1alpha1.WorkflowStepPhaseSkipped))
})

It("test workflow run with mode", func() {
wr := wrTemplate.DeepCopy()
wr.Name = "wr-mode"
Expand Down Expand Up @@ -1447,4 +1480,16 @@ spec:
template: "import (\n\t\"vela/op\"\n)\n\napply: op.#Apply & {\n\tvalue: parameter.value\n\tcluster:
parameter.cluster\n}\nparameter: {\n\t// +usage=Specify the value of the object\n\tvalue:
{...}\n\t// +usage=Specify the cluster of the object\n\tcluster: *\"\" | string\n}\n"`

wfStepFailedRenderDefYaml = `apiVersion: core.oam.dev/v1beta1
kind: WorkflowStepDefinition
metadata:
name: failed-render
namespace: vela-system
spec:
schematic:
cue:
template: "import (\n\t\"vela/op1\"\n)\n\napply: op.#Apply & {\n\tvalue: parameter.value\n\tcluster:
parameter.cluster\n}\nparameter: {\n\t// +usage=Specify the value of the object\n\tvalue:
{...}\n\t// +usage=Specify the cluster of the object\n\tcluster: *\"\" | string\n}\n"`
)
2 changes: 1 addition & 1 deletion pkg/executor/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ func (w *workflowExecutor) allDone(taskRunners []types.TaskRunner) (bool, bool)
for _, ss := range status.Steps {
if ss.Name == t.Name() {
done = types.IsStepFinish(ss.Phase, ss.Reason)
success = done && (ss.Phase == v1alpha1.WorkflowStepPhaseSucceeded || ss.Phase == v1alpha1.WorkflowStepPhaseSkipped)
success = success && done && (ss.Phase == v1alpha1.WorkflowStepPhaseSucceeded || ss.Phase == v1alpha1.WorkflowStepPhaseSkipped)
break
}
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/tasks/custom/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,9 @@ func (exec *executor) err(ctx wfContext.Context, wait bool, err error, reason st
exec.wfStatus.Message = err.Error()
if exec.wfStatus.Reason == "" {
exec.wfStatus.Reason = reason
if reason != types.StatusReasonExecute {
exec.terminated = true
}
}
exec.checkErrorTimes(ctx)
}
Expand Down

0 comments on commit 3adc839

Please sign in to comment.