-
Notifications
You must be signed in to change notification settings - Fork 4.7k
ensure next build is kicked off when a build completes #13670
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,6 +121,9 @@ func (bc *BuildPodController) HandlePod(pod *kapi.Pod) error { | |
nextStatus := build.Status.Phase | ||
currentReason := build.Status.Reason | ||
|
||
// if the build is marked failed, the build status reason has already been | ||
// set (probably by the build pod itself), so don't do any updating here | ||
// or we'll overwrite the correct value. | ||
if build.Status.Phase != buildapi.BuildPhaseFailed { | ||
switch pod.Status.Phase { | ||
case kapi.PodPending: | ||
|
@@ -176,33 +179,48 @@ func (bc *BuildPodController) HandlePod(pod *kapi.Pod) error { | |
build.Status.Message = "" | ||
} | ||
} | ||
|
||
needsUpdate := false | ||
// Update the build object when it progress to a next state or the reason for | ||
// the current state changed. | ||
if (!common.HasBuildPodNameAnnotation(build) || build.Status.Phase != nextStatus || build.Status.Phase == buildapi.BuildPhaseFailed) && !buildutil.IsBuildComplete(build) { | ||
// the current state changed. Do not touch builds that are complete | ||
// because we'd potentially be overwriting build state information set by the | ||
// build pod directly. | ||
if (!common.HasBuildPodNameAnnotation(build) || build.Status.Phase != nextStatus) && !buildutil.IsBuildComplete(build) { | ||
needsUpdate = true | ||
common.SetBuildPodNameAnnotation(build, pod.Name) | ||
reason := "" | ||
if len(build.Status.Reason) > 0 { | ||
reason = " (" + string(build.Status.Reason) + ")" | ||
} | ||
glog.V(4).Infof("Updating build %s/%s status %s -> %s%s", build.Namespace, build.Name, build.Status.Phase, nextStatus, reason) | ||
build.Status.Phase = nextStatus | ||
|
||
if buildutil.IsBuildComplete(build) { | ||
common.SetBuildCompletionTimeAndDuration(build) | ||
} | ||
if build.Status.Phase == buildapi.BuildPhaseRunning { | ||
now := unversioned.Now() | ||
build.Status.StartTimestamp = &now | ||
} | ||
} | ||
|
||
// we're going to get pod relist events for completed/failed pods, | ||
// there's no reason to re-update the build and rerun | ||
// HandleBuildCompletion if we've already done it for this | ||
// build previously. | ||
buildWasComplete := build.Status.CompletionTimestamp != nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just a nit ... maybe a better name for the variable would be |
||
if !buildWasComplete && buildutil.IsBuildComplete(build) && build.Status.Phase != buildapi.BuildPhaseCancelled { | ||
needsUpdate = common.SetBuildCompletionTimeAndDuration(build) | ||
} | ||
if needsUpdate { | ||
if err := bc.buildUpdater.Update(build.Namespace, build); err != nil { | ||
return fmt.Errorf("failed to update build %s/%s: %v", build.Namespace, build.Name, err) | ||
} | ||
glog.V(4).Infof("Build %s/%s status was updated to %s", build.Namespace, build.Name, build.Status.Phase) | ||
|
||
if buildutil.IsBuildComplete(build) { | ||
common.HandleBuildCompletion(build, bc.runPolicies) | ||
} | ||
} | ||
// if the build was not previously marked complete but it's complete now, | ||
// handle completion for it. otherwise ignore it because we've already | ||
// handled its completion previously. | ||
if !buildWasComplete && buildutil.IsBuildComplete(build) { | ||
common.HandleBuildCompletion(build, bc.runPolicies) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
|
@@ -244,6 +262,7 @@ func (bc *BuildPodController) HandleBuildPodDeletion(pod *kapi.Pod) error { | |
if err := bc.buildUpdater.Update(build.Namespace, build); err != nil { | ||
return fmt.Errorf("Failed to update build %s/%s: %v", build.Namespace, build.Name, err) | ||
} | ||
common.HandleBuildCompletion(build, bc.runPolicies) | ||
} | ||
return nil | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have utility functions that delineate which non-successful BuildPhases are set by the build pod (where it is currently just Failed) and which are set outside of the build pod (i.e. BuildPhaseError), in case those two lists change over time?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't anticipate that set changing. If it does, that would be a good time to introduce a utility function but I don't think it needs to be done here/now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok