Prevent Cancel from running when a k8s job is cancelled already #2935
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.
Description
When a job in k8s completes, the job output will often contain the line
# Received cancellation signal, interrupting
even though the job itself has already completed. This appears to be a problem with the way theCancel()
method is called during the k8s job execution, and isn't validating that there's any error generated to warrant its execution.For those looking at logs, this makes the job appear to have failed, when in all other circumstances it has succeeded.
Context
https://coda.io/d/Escalations-Feedback_dHnUHNps1YO/Pipelines-Escalations_su7FT#Pipelines-Escalations-Board_tu__K/r634&view=modal
Changes
A small logic tweak to when
Cancel()
is triggered based on thek8sAgentSocket.Await()
call. CurrentlyCancel()
will always be called regardless of what happens, where it should only be called if there's an error from theAwait()
. There's additional logic here that will generate an error log line for the job if the error is specifically not a cancellation.Testing
go test ./...
). Buildkite employees may check this if the pipeline has run automatically. Tests have passed locally and via the pipeline.go fmt ./...
)