Skip to content

Commit

Permalink
InvalidImageName errors are not reported correctly (flyteorg#209)
Browse files Browse the repository at this point in the history
* InvalidImageName errors are not reported correctly

Signed-off-by: Kevin Su <[email protected]>

* Add test

Signed-off-by: Kevin Su <[email protected]>
  • Loading branch information
pingsutw authored Sep 21, 2021
1 parent bd6c1b6 commit 518863e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
2 changes: 1 addition & 1 deletion go/tasks/pluginmachinery/flytek8s/pod_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func DemystifyPending(status v1.PodStatus) (pluginsCore.PhaseInfo, error) {
&pluginsCore.TaskInfo{OccurredAt: &t},
), nil

case "CreateContainerConfigError":
case "CreateContainerConfigError", "InvalidImageName":
t := c.LastTransitionTime.Time
return pluginsCore.PhaseInfoFailure(finalReason, finalMessage, &pluginsCore.TaskInfo{
OccurredAt: &t,
Expand Down
2 changes: 1 addition & 1 deletion go/tasks/pluginmachinery/flytek8s/pod_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ func TestDemystifyPending(t *testing.T) {
}
taskStatus, err := DemystifyPending(s)
assert.NoError(t, err)
assert.Equal(t, pluginsCore.PhaseRetryableFailure, taskStatus.Phase())
assert.Equal(t, pluginsCore.PhasePermanentFailure, taskStatus.Phase())
})

t.Run("RegistryUnavailable", func(t *testing.T) {
Expand Down
43 changes: 43 additions & 0 deletions go/tasks/plugins/k8s/container/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package container

import (
"context"
"fmt"
"testing"

"github.com/stretchr/testify/mock"
Expand Down Expand Up @@ -197,3 +198,45 @@ func TestContainerTaskExecutor_GetProperties(t *testing.T) {
expected := k8s.PluginProperties{}
assert.Equal(t, expected, plugin.GetProperties())
}

func TestContainerTaskExecutor_GetTaskStatus_InvalidImageName(t *testing.T) {
ctx := context.TODO()
c := Plugin{}
reason := "InvalidImageName"
message := "Failed to apply default image tag \"TEST/flyteorg/myapp:latest\": couldn't parse image reference" +
" \"TEST/flyteorg/myapp:latest\": invalid reference format: repository name must be lowercase"

pendingPod := &v1.Pod{
Status: v1.PodStatus{
Phase: v1.PodPending,
Conditions: []v1.PodCondition{
{
Type: v1.PodReady,
Status: v1.ConditionFalse,
},
},
ContainerStatuses: []v1.ContainerStatus{
{
ContainerID: "ContainerID",
Ready: false,
State: v1.ContainerState{
Waiting: &v1.ContainerStateWaiting{
Reason: reason,
Message: message,
},
},
},
},
},
}

t.Run("failInvalidImageName", func(t *testing.T) {
pendingPod.Status.Phase = v1.PodPending
phaseInfo, err := c.GetTaskPhase(ctx, nil, pendingPod)
finalReason := fmt.Sprintf("|%s", reason)
finalMessage := fmt.Sprintf("|%s", message)
assert.NoError(t, err)
assert.Equal(t, pluginsCore.PhasePermanentFailure, phaseInfo.Phase())
assert.Equal(t, &core.ExecutionError{Code: finalReason, Message: finalMessage, Kind: core.ExecutionError_USER}, phaseInfo.Err())
})
}

0 comments on commit 518863e

Please sign in to comment.