Skip to content

Commit

Permalink
Merge pull request #2010 from buildkite/pdp-663-exit-with-non-zero-ex…
Browse files Browse the repository at this point in the history
…it-status-from-a
  • Loading branch information
triarius authored Mar 16, 2023
2 parents 42c5245 + 6c994a9 commit bfdc972
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
12 changes: 12 additions & 0 deletions agent/job_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,18 @@ func (r *JobRunner) Run(ctx context.Context) error {
exitStatus = "-1"
signalReason = "process_run_error"
} else {
// Intended to capture situations where the job-exec (aka bootstrap) container did not
// start. Normally such errors are hidden in the Kubernetes events. Let's feed them up
// to the user as they may be the caused by errors in the pipeline definition.
if r.cancelled && !r.stopped {
k8sProcess, ok := r.process.(*kubernetes.Runner)
if ok && k8sProcess.ClientStateUnknown() {
r.logStreamer.Process([]byte(
"Some containers had unknown exit statuses. Perhaps they were in ImagePullBackOff.",
))
}
}

// Add the final output to the streamer
r.logStreamer.Process(r.output.ReadAndTruncate())

Expand Down
18 changes: 15 additions & 3 deletions kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,29 @@ func (w waitStatus) Signaled() bool {
}

func (r *Runner) WaitStatus() process.WaitStatus {
var ws process.WaitStatus
ws := waitStatus{}
for _, client := range r.clients {
if client.ExitStatus != 0 {
return waitStatus{Code: client.ExitStatus}
}
// just return any ExitStatus if we don't find any "interesting" ones
ws = waitStatus{Code: client.ExitStatus}

// use an unusual status code to distinguish this unusual state
if client.State == stateUnknown {
ws.Code -= 10
}
}
return ws
}

func (r *Runner) ClientStateUnknown() bool {
for _, client := range r.clients {
if client.State == stateUnknown {
return true
}
}
return false
}

// ==== sidecar api ====

type Empty struct{}
Expand Down

0 comments on commit bfdc972

Please sign in to comment.