Skip to content

Commit

Permalink
Bug 1596440 - surface OOMKilled pod to build
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Wozniak committed Jul 12, 2018
1 parent ea877ac commit 1998310
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/build/apis/build/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,9 @@ const (
// range of build failures.
StatusReasonGenericBuildFailed StatusReason = "GenericBuildFailed"

// StatusReasonOOMKilled indicates that the build pod was killed for its memory consumption
StatusReasonOOMKilled StatusReason = "OOMKilled"

// StatusCannotRetrieveServiceAccount is the reason associated with a failure
// to look up the service account associated with the BuildConfig.
StatusReasonCannotRetrieveServiceAccount StatusReason = "CannotRetrieveServiceAccount"
Expand All @@ -540,6 +543,7 @@ const (
StatusMessageNoBuildContainerStatus = "The pod for this build has no container statuses indicating success or failure."
StatusMessageFailedContainer = "The pod for this build has at least one container with a non-zero exit status."
StatusMessageGenericBuildFailed = "Generic Build failure - check logs for details."
StatusMessageOOMKilled = "Out of memory"
StatusMessageUnresolvableEnvironmentVariable = "Unable to resolve build environment variable reference."
StatusMessageCannotRetrieveServiceAccount = "Unable to look up the service account secrets for this build."
)
Expand Down
21 changes: 21 additions & 0 deletions pkg/build/controller/build/build_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,8 @@ func (bc *BuildController) handleActiveBuild(build *buildapi.Build, pod *v1.Pod)
// soon be deleted. The build should be transitioned to the Error phase.
if pod.DeletionTimestamp != nil {
update = transitionToPhase(buildapi.BuildPhaseError, buildapi.StatusReasonBuildPodDeleted, buildapi.StatusMessageBuildPodDeleted)
} else if isOOMKilled(pod) {
update = transitionToPhase(buildapi.BuildPhaseFailed, buildapi.StatusReasonOOMKilled, buildapi.StatusMessageOOMKilled)
} else {
update = transitionToPhase(buildapi.BuildPhaseFailed, buildapi.StatusReasonGenericBuildFailed, buildapi.StatusMessageGenericBuildFailed)
}
Expand All @@ -1014,6 +1016,25 @@ func (bc *BuildController) handleActiveBuild(build *buildapi.Build, pod *v1.Pod)
return update, nil
}

func isOOMKilled(pod *v1.Pod) bool {
if pod.Status.Reason == "OOMKilled" {
return true
}
for _, c := range pod.Status.InitContainerStatuses {
terminated := c.State.Terminated
if terminated != nil && terminated.Reason == "OOMKilled" {
return true
}
}
for _, c := range pod.Status.ContainerStatuses {
terminated := c.State.Terminated
if terminated != nil && terminated.Reason == "OOMKilled" {
return true
}
}
return false
}

// handleCompletedBuild will only be called on builds that are already in a terminal phase. It is used to setup the
// completion timestamp and failure logsnippet as needed.
func (bc *BuildController) handleCompletedBuild(build *buildapi.Build, pod *v1.Pod) (*buildUpdate, error) {
Expand Down

0 comments on commit 1998310

Please sign in to comment.