Skip to content

Commit

Permalink
Fixed handling of failed task (#630)
Browse files Browse the repository at this point in the history
Signed-off-by: Micah Hausler <[email protected]>

## Description

Failed tasks did not properly update the workflow status, and the overall workflow status perpetually showed as `STATE_RUNNING`

## Why is this needed

To properly report a failed workflow

Fixes: #

## How Has This Been Tested?

Added unit tests

## How are existing users impacted? What migration steps/scripts do we need?

N/A

## Checklist:

I have:

- [ ] updated the documentation and/or roadmap (if required)
- [ ] added unit or e2e tests
- [ ] provided instructions on how to upgrade
  • Loading branch information
mergify[bot] authored Jun 15, 2022
2 parents bd1c1c0 + c8602de commit 88798fa
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
67 changes: 67 additions & 0 deletions server/kubernetes_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,73 @@ func TestModifyWorkflowState(t *testing.T) {
},
wantErr: nil,
},
{
name: "failed task",
inputWf: &v1alpha1.Workflow{
Status: v1alpha1.WorkflowStatus{
State: "STATE_RUNNING",
GlobalTimeout: 600,
Tasks: []v1alpha1.Task{
{
Name: "provision",
WorkerAddr: "machine-mac-1",
Actions: []v1alpha1.Action{
{
Name: "stream",
Image: "quay.io/tinkerbell-actions/image2disk:v1.0.0",
Timeout: 300,
Status: "STATE_RUNNING",
StartedAt: TestTime.MetaV1Before(time.Second * 30),
},
{
Name: "kexec",
Image: "quay.io/tinkerbell-actions/kexec:v1.0.0",
Timeout: 5,
Status: "STATE_PENDING",
},
},
},
},
},
},
inputWfContext: &workflow.WorkflowContext{
CurrentWorker: "machine-mac-1",
CurrentTask: "provision",
CurrentAction: "stream",
CurrentActionIndex: 0,
CurrentActionState: workflow.State_STATE_FAILED,
TotalNumberOfActions: 2,
},
want: &v1alpha1.Workflow{
Status: v1alpha1.WorkflowStatus{
State: "STATE_FAILED",
GlobalTimeout: 600,
Tasks: []v1alpha1.Task{
{
Name: "provision",
WorkerAddr: "machine-mac-1",
Actions: []v1alpha1.Action{
{
Name: "stream",
Image: "quay.io/tinkerbell-actions/image2disk:v1.0.0",
Timeout: 300,
Status: "STATE_FAILED",
StartedAt: TestTime.MetaV1Before(time.Second * 30),
Seconds: 30,
},
{
Name: "kexec",
Image: "quay.io/tinkerbell-actions/kexec:v1.0.0",
Timeout: 5,
Status: "STATE_PENDING",
},
},
},
},
},
},
wantErr: nil,
},
{
name: "successful task",
inputWf: &v1alpha1.Workflow{
Expand Down
3 changes: 1 addition & 2 deletions server/kubernetes_api_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ cont:
t := metav1.NewTime(s.nowFunc())
return &t
}()
case pb.State_STATE_FAILED:
case pb.State_STATE_TIMEOUT:
case pb.State_STATE_FAILED, pb.State_STATE_TIMEOUT:
// Handle terminal statuses by updating the workflow state and time
wf.Status.State = v1alpha1.WorkflowState(pb.State_name[int32(wfContext.CurrentActionState)])
if wf.Status.Tasks[taskIndex].Actions[actionIndex].StartedAt != nil {
Expand Down

0 comments on commit 88798fa

Please sign in to comment.