forked from flyteorg/flyte
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FlytePropeller should ignore if Admin is already in terminal state #p…
…atch (flyteorg#281) * FlytePropeller should ignore if Admin is already in terminal state Signed-off-by: Ketan Umare <[email protected]> * Lint fixes Signed-off-by: Ketan Umare <[email protected]>
- Loading branch information
Showing
7 changed files
with
181 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package nodes | ||
|
||
import "github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core" | ||
|
||
// IsTerminalNodePhase returns true if node phase is one of the terminal phases, else false | ||
func IsTerminalNodePhase(p core.NodeExecution_Phase) bool { | ||
return p == core.NodeExecution_ABORTED || p == core.NodeExecution_FAILED || p == core.NodeExecution_SKIPPED || p == core.NodeExecution_SUCCEEDED || p == core.NodeExecution_TIMED_OUT | ||
} | ||
|
||
// IsTerminalTaskPhase returns true if task phase is terminal, else false | ||
func IsTerminalTaskPhase(p core.TaskExecution_Phase) bool { | ||
return p == core.TaskExecution_ABORTED || p == core.TaskExecution_FAILED || p == core.TaskExecution_SUCCEEDED | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package nodes | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core" | ||
) | ||
|
||
func TestIsTerminalNodePhase(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
p core.NodeExecution_Phase | ||
want bool | ||
}{ | ||
{"aborted", core.NodeExecution_ABORTED, true}, | ||
{"succeeded", core.NodeExecution_SUCCEEDED, true}, | ||
{"failed", core.NodeExecution_FAILED, true}, | ||
{"timed_out", core.NodeExecution_TIMED_OUT, true}, | ||
{"skipped", core.NodeExecution_SKIPPED, true}, | ||
{"running", core.NodeExecution_RUNNING, false}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := IsTerminalNodePhase(tt.p); got != tt.want { | ||
t.Errorf("IsTerminalNodePhase() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestIsTerminalTaskPhase(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
p core.TaskExecution_Phase | ||
want bool | ||
}{ | ||
{"aborted", core.TaskExecution_ABORTED, true}, | ||
{"failed", core.TaskExecution_FAILED, true}, | ||
{"succeeded", core.TaskExecution_SUCCEEDED, true}, | ||
{"running", core.TaskExecution_RUNNING, false}, | ||
{"waiting", core.TaskExecution_WAITING_FOR_RESOURCES, false}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := IsTerminalTaskPhase(tt.p); got != tt.want { | ||
t.Errorf("IsTerminalTaskPhase() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package nodes | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/flyteorg/flyteidl/clients/go/events" | ||
eventsErr "github.com/flyteorg/flyteidl/clients/go/events/errors" | ||
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core" | ||
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/event" | ||
) | ||
|
||
type fakeTaskEventsRecorder struct { | ||
err error | ||
} | ||
|
||
func (f fakeTaskEventsRecorder) RecordTaskEvent(ctx context.Context, event *event.TaskExecutionEvent) error { | ||
if f.err != nil { | ||
return f.err | ||
} | ||
return nil | ||
} | ||
|
||
func Test_taskEventRecorder_RecordTaskEvent(t1 *testing.T) { | ||
noErrRecorder := fakeTaskEventsRecorder{} | ||
alreadyExistsError := fakeTaskEventsRecorder{&eventsErr.EventError{Code: eventsErr.AlreadyExists, Cause: fmt.Errorf("err")}} | ||
inTerminalError := fakeTaskEventsRecorder{&eventsErr.EventError{Code: eventsErr.EventAlreadyInTerminalStateError, Cause: fmt.Errorf("err")}} | ||
otherError := fakeTaskEventsRecorder{&eventsErr.EventError{Code: eventsErr.ResourceExhausted, Cause: fmt.Errorf("err")}} | ||
|
||
tests := []struct { | ||
name string | ||
rec events.TaskEventRecorder | ||
p core.TaskExecution_Phase | ||
wantErr bool | ||
}{ | ||
{"aborted-success", noErrRecorder, core.TaskExecution_ABORTED, false}, | ||
{"aborted-failure", otherError, core.TaskExecution_ABORTED, true}, | ||
{"aborted-already", alreadyExistsError, core.TaskExecution_ABORTED, false}, | ||
{"aborted-terminal", inTerminalError, core.TaskExecution_ABORTED, false}, | ||
{"running-terminal", inTerminalError, core.TaskExecution_RUNNING, true}, | ||
} | ||
for _, tt := range tests { | ||
t1.Run(tt.name, func(t1 *testing.T) { | ||
t := taskEventRecorder{ | ||
TaskEventRecorder: tt.rec, | ||
} | ||
ev := &event.TaskExecutionEvent{ | ||
Phase: tt.p, | ||
} | ||
if err := t.RecordTaskEvent(context.TODO(), ev); (err != nil) != tt.wantErr { | ||
t1.Errorf("RecordTaskEvent() error = %v, wantErr %v", err, tt.wantErr) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters