Skip to content

Commit 0cfb747

Browse files
committed
Fail new builds that can't start build pod because it already exists
Consider following scenario: - build is started by user - build controller creates build pod - build is deleted by user - build pod is killed but remains Terminating during grace period - build with same name as in first step is started by user Previously the new build stayed in New phase until the old build pod finished and then went into Failed after the pod terminated. This commit causes the new build to go into Error phase when it first tries creating build pod and fails because pod with the same name (and earlier creationTimestamp) exists. Slightly improves bug 1300949 (the described behavior is still very similar).
1 parent 236531b commit 0cfb747

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

Diff for: pkg/build/api/types.go

+5
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,10 @@ const (
309309
// StatusReasonDockerBuildFailed indicates that the docker build strategy has
310310
// failed.
311311
StatusReasonDockerBuildFailed StatusReason = "DockerBuildFailed"
312+
313+
// StatusReasonBuildPodExists indicates that the build tried to create a
314+
// build pod but one was already present.
315+
StatusReasonBuildPodExists = "BuildPodExists"
312316
)
313317

314318
// NOTE: These messages might change.
@@ -326,6 +330,7 @@ const (
326330
StatusMessageFetchSourceFailed = "Failed to fetch the input source"
327331
StatusMessageCancelledBuild = "The build was cancelled by the user"
328332
StatusMessageDockerBuildFailed = "Docker build strategy has failed"
333+
StatusMessageBuildPodExists = "The pod for this build already exists and is older than the build"
329334
)
330335

331336
// BuildSource is the input used for the build.

Diff for: pkg/build/controller/controller.go

+8
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,14 @@ func (bc *BuildController) nextBuildPhase(build *buildapi.Build) error {
210210
if errors.IsAlreadyExists(err) {
211211
bc.Recorder.Eventf(build, kapi.EventTypeWarning, "FailedCreate", "Pod already exists: %s/%s", podSpec.Namespace, podSpec.Name)
212212
glog.V(4).Infof("Build pod already existed: %#v", podSpec)
213+
214+
// If the existing pod was created before this build, switch to Error state.
215+
existingPod, err := bc.PodManager.GetPod(podSpec.Namespace, podSpec.Name)
216+
if err == nil && existingPod.CreationTimestamp.Before(build.CreationTimestamp) {
217+
build.Status.Phase = buildapi.BuildPhaseError
218+
build.Status.Reason = buildapi.StatusReasonBuildPodExists
219+
build.Status.Message = buildapi.StatusMessageBuildPodExists
220+
}
213221
return nil
214222
}
215223
// Log an event if the pod is not created (most likely due to quota denial).

0 commit comments

Comments
 (0)