Skip to content
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

Don't run pre-exit hooks without command phase #2707

Merged
merged 1 commit into from Apr 2, 2024

Conversation

DrJosh9000
Copy link
Contributor

@DrJosh9000 DrJosh9000 commented Mar 28, 2024

Description

The k8s stack uses phases to split job execution between multiple containers. In particular, the checkout phase happens in a separate container to the command phase. This makes pre-exit hook execute twice, once in each container - this is usually not what is intended by plugin authors, and often breaks when the different phase have different configs or environment variables.

Changing it so pre-exit hooks only run if the command phase is enabled makes it work, and is unlikely to break anybody (who isn't deep in the agent fiddling with phases).

Context

https://linear.app/buildkite/issue/PENT-10/make-hooks-configurable

Changes

  • Refactor includePhase from inline closure to method
  • Change pre-exit hooks to only run if phases includes command
  • Add an integration test

Testing

  • Tests have run locally (with go test ./...). Buildkite employees may check this if the pipeline has run automatically.
  • Code is formatted (with go fmt ./...)

@DrJosh9000 DrJosh9000 force-pushed the pent-10-no-pre-exit-without-command-phase branch from be91ebe to 86b3a16 Compare April 2, 2024 01:26
@DrJosh9000 DrJosh9000 marked this pull request as ready for review April 2, 2024 01:26
@DrJosh9000 DrJosh9000 requested a review from a team April 2, 2024 01:35
@DrJosh9000 DrJosh9000 changed the title WIP: Don't run pre-exit hook without command phase Don't run pre-exit hooks without command phase Apr 2, 2024
Comment on lines -183 to -193
includePhase := func(phase string) bool {
if len(e.Phases) == 0 {
return true
}
for _, include := range e.Phases {
if include == phase {
return true
}
}
return false
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have looked at this code and thought "why is this an inline closure? i should make it a method" and then... not for the entire time i've worked here. thank you for making it happen!!!

@DrJosh9000 DrJosh9000 merged commit 4acfa17 into main Apr 2, 2024
1 check passed
@DrJosh9000 DrJosh9000 deleted the pent-10-no-pre-exit-without-command-phase branch April 2, 2024 02:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants