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: skip clear message when node transition from pending to fail. Fixes #13200 #13201

Merged
merged 3 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
4 changes: 2 additions & 2 deletions workflow/controller/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1471,8 +1471,8 @@ func (woc *wfOperationCtx) assessNodeStatus(pod *apiv1.Pod, old *wfv1.NodeStatus
}
}

// if we are transitioning from Pending to a different state, clear out unchanged message
if old.Phase == wfv1.NodePending && new.Phase != wfv1.NodePending && old.Message == new.Message {
// if we are transitioning from Pending to a different state (except Fail or Error), clear out unchanged message
if old.Phase == wfv1.NodePending && new.Phase != wfv1.NodePending && new.Phase != wfv1.NodeFailed && new.Phase != wfv1.NodeError && old.Message == new.Message {
new.Message = ""
}

Expand Down
95 changes: 60 additions & 35 deletions workflow/controller/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1555,59 +1555,65 @@ func TestStepsRetriesVariable(t *testing.T) {
func TestAssessNodeStatus(t *testing.T) {
const templateName = "whalesay"
tests := []struct {
name string
pod *apiv1.Pod
daemon bool
node *wfv1.NodeStatus
want wfv1.NodePhase
name string
pod *apiv1.Pod
daemon bool
node *wfv1.NodeStatus
wantPhase wfv1.NodePhase
wantMessage string
}{{
name: "pod pending",
pod: &apiv1.Pod{
Status: apiv1.PodStatus{
Phase: apiv1.PodPending,
},
},
node: &wfv1.NodeStatus{TemplateName: templateName},
want: wfv1.NodePending,
node: &wfv1.NodeStatus{TemplateName: templateName},
wantPhase: wfv1.NodePending,
wantMessage: "",
}, {
name: "pod succeeded",
pod: &apiv1.Pod{
Status: apiv1.PodStatus{
Phase: apiv1.PodSucceeded,
},
},
node: &wfv1.NodeStatus{TemplateName: templateName},
want: wfv1.NodeSucceeded,
node: &wfv1.NodeStatus{TemplateName: templateName},
wantPhase: wfv1.NodeSucceeded,
wantMessage: "",
}, {
name: "pod failed - daemoned",
pod: &apiv1.Pod{
Status: apiv1.PodStatus{
Phase: apiv1.PodFailed,
},
},
daemon: true,
node: &wfv1.NodeStatus{TemplateName: templateName},
want: wfv1.NodeSucceeded,
daemon: true,
node: &wfv1.NodeStatus{TemplateName: templateName},
wantPhase: wfv1.NodeSucceeded,
wantMessage: "",
}, {
name: "daemon, pod running, node failed",
pod: &apiv1.Pod{
Status: apiv1.PodStatus{
Phase: apiv1.PodRunning,
},
},
daemon: true,
node: &wfv1.NodeStatus{TemplateName: templateName, Phase: wfv1.NodeFailed},
want: wfv1.NodeFailed,
daemon: true,
node: &wfv1.NodeStatus{TemplateName: templateName, Phase: wfv1.NodeFailed},
wantPhase: wfv1.NodeFailed,
wantMessage: "",
}, {
name: "daemon, pod running, node succeeded",
pod: &apiv1.Pod{
Status: apiv1.PodStatus{
Phase: apiv1.PodRunning,
},
},
daemon: true,
node: &wfv1.NodeStatus{TemplateName: templateName, Phase: wfv1.NodeSucceeded},
want: wfv1.NodeSucceeded,
daemon: true,
node: &wfv1.NodeStatus{TemplateName: templateName, Phase: wfv1.NodeSucceeded},
wantPhase: wfv1.NodeSucceeded,
wantMessage: "",
}, {
name: "pod failed - not daemoned",
pod: &apiv1.Pod{
Expand All @@ -1616,8 +1622,20 @@ func TestAssessNodeStatus(t *testing.T) {
Phase: apiv1.PodFailed,
},
},
node: &wfv1.NodeStatus{TemplateName: templateName},
want: wfv1.NodeFailed,
node: &wfv1.NodeStatus{TemplateName: templateName},
wantPhase: wfv1.NodeFailed,
wantMessage: "failed for some reason",
}, {
name: "pod failed - transition from node pending",
pod: &apiv1.Pod{
Status: apiv1.PodStatus{
Message: "failed for some reason",
Phase: apiv1.PodFailed,
},
},
node: &wfv1.NodeStatus{TemplateName: templateName, Phase: wfv1.NodePending, Message: "failed for some reason"},
wantPhase: wfv1.NodeFailed,
wantMessage: "failed for some reason",
}, {
name: "pod failed - init container failed",
pod: &apiv1.Pod{
Expand All @@ -1642,8 +1660,9 @@ func TestAssessNodeStatus(t *testing.T) {
Phase: apiv1.PodFailed,
},
},
node: &wfv1.NodeStatus{TemplateName: templateName},
want: wfv1.NodeFailed,
node: &wfv1.NodeStatus{TemplateName: templateName},
wantPhase: wfv1.NodeFailed,
wantMessage: "failed since init container failed",
}, {
name: "pod failed - init container failed but neither wait nor main containers are finished",
pod: &apiv1.Pod{
Expand All @@ -1668,8 +1687,9 @@ func TestAssessNodeStatus(t *testing.T) {
Phase: apiv1.PodFailed,
},
},
node: &wfv1.NodeStatus{TemplateName: templateName},
want: wfv1.NodeFailed,
node: &wfv1.NodeStatus{TemplateName: templateName},
wantPhase: wfv1.NodeFailed,
wantMessage: "failed since init container failed",
}, {
name: "pod failed - init container with non-standard init container name failed but neither wait nor main containers are finished",
pod: &apiv1.Pod{
Expand Down Expand Up @@ -1698,8 +1718,9 @@ func TestAssessNodeStatus(t *testing.T) {
Phase: apiv1.PodFailed,
},
},
node: &wfv1.NodeStatus{TemplateName: templateName},
want: wfv1.NodeFailed,
node: &wfv1.NodeStatus{TemplateName: templateName},
wantPhase: wfv1.NodeFailed,
wantMessage: "failed since init container failed",
}, {
name: "pod failed - wait container waiting but pod was set failed",
pod: &apiv1.Pod{
Expand All @@ -1724,22 +1745,25 @@ func TestAssessNodeStatus(t *testing.T) {
Phase: apiv1.PodFailed,
},
},
node: &wfv1.NodeStatus{TemplateName: templateName},
want: wfv1.NodeFailed,
node: &wfv1.NodeStatus{TemplateName: templateName},
wantPhase: wfv1.NodeFailed,
wantMessage: "failed since wait contain waiting",
}, {
name: "pod running",
pod: &apiv1.Pod{
Status: apiv1.PodStatus{
Phase: apiv1.PodRunning,
},
},
node: &wfv1.NodeStatus{TemplateName: templateName},
want: wfv1.NodeRunning,
node: &wfv1.NodeStatus{TemplateName: templateName},
wantPhase: wfv1.NodeRunning,
wantMessage: "",
}, {
name: "default",
pod: &apiv1.Pod{},
node: &wfv1.NodeStatus{TemplateName: templateName},
want: wfv1.NodeError,
name: "default",
pod: &apiv1.Pod{},
node: &wfv1.NodeStatus{TemplateName: templateName},
wantPhase: wfv1.NodeError,
wantMessage: "Unexpected pod phase for : ",
}}

nonDaemonWf := wfv1.MustUnmarshalWorkflow(helloWorldWf)
Expand All @@ -1756,7 +1780,8 @@ func TestAssessNodeStatus(t *testing.T) {
defer cancel()
woc := newWorkflowOperationCtx(wf, controller)
got := woc.assessNodeStatus(tt.pod, tt.node)
assert.Equal(t, tt.want, got.Phase)
assert.Equal(t, tt.wantPhase, got.Phase)
assert.Equal(t, tt.wantMessage, got.Message)
})
}
}
Expand Down
Loading