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(operator): allow retries to consider exit code from init container and don't consider node as pending if init failed. Fixes #11354/#10717/#10045 #13858

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all 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
37 changes: 24 additions & 13 deletions workflow/controller/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1392,6 +1392,23 @@ func (woc *wfOperationCtx) assessNodeStatus(ctx context.Context, pod *apiv1.Pod,
woc.controller.metrics.ChangePodPhase(ctx, string(new.Phase), pod.ObjectMeta.Namespace)
}

initContainerFailed := false
// if init container has failed then main container is not relevant
for _, c := range pod.Status.InitContainerStatuses {
if c.State.Terminated != nil && int(c.State.Terminated.ExitCode) != 0 {
new.Phase = wfv1.NodeFailed
woc.log.WithField("new.phase", new.Phase).Info("marking node as failed since init container has non-zero exit code")
if new.Outputs == nil {
new.Outputs = &wfv1.Outputs{}
}
if new.Outputs.ExitCode == nil {
new.Outputs.ExitCode = ptr.To(fmt.Sprint(int(c.State.Terminated.ExitCode)))
}
initContainerFailed = true
break
}
}

// if it's ContainerSetTemplate pod then the inner container names should match to some node names,
// in this case need to update nodes according to container status
for _, c := range pod.Status.ContainerStatuses {
Expand All @@ -1400,7 +1417,7 @@ func (woc *wfOperationCtx) assessNodeStatus(ctx context.Context, pod *apiv1.Pod,
continue
}
switch {
case c.State.Waiting != nil:
case c.State.Waiting != nil && !initContainerFailed:
woc.markNodePhase(ctrNodeName, wfv1.NodePending)
case c.State.Running != nil:
woc.markNodePhase(ctrNodeName, wfv1.NodeRunning)
Expand Down Expand Up @@ -1434,18 +1451,12 @@ func (woc *wfOperationCtx) assessNodeStatus(ctx context.Context, pod *apiv1.Pod,
// We capture the exit-code after we look for the task-result.
// All other outputs are set by the executor, only the exit-code is set by the controller.
// By waiting, we avoid breaking the race-condition check.
if exitCode := getExitCode(pod); exitCode != nil {
if new.Outputs == nil {
new.Outputs = &wfv1.Outputs{}
}
new.Outputs.ExitCode = ptr.To(fmt.Sprint(*exitCode))
}

for _, c := range pod.Status.InitContainerStatuses {
if c.State.Terminated != nil && int(c.State.Terminated.ExitCode) != 0 {
new.Phase = wfv1.NodeFailed
woc.log.WithField("new.phase", new.Phase).Info("marking node as failed since init container has non-zero exit code")
break
if !initContainerFailed {
if exitCode := getExitCode(pod); exitCode != nil {
if new.Outputs == nil {
new.Outputs = &wfv1.Outputs{}
}
new.Outputs.ExitCode = ptr.To(fmt.Sprint(*exitCode))
}
}

Expand Down
Loading