-
Notifications
You must be signed in to change notification settings - Fork 582
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
feat: Add graceful exits to provisionerd #372
Conversation
This was detecting branches, but not our "main" branch before. Hopefully this fixes it!
This enables a consistent API for project import and provisioned resources.
This is a much cleaner abstraction. Explicitly declaring the user parameters for each provisioner makes for significantly simpler testing.
Terraform (or other provisioners) may need to cleanup state, or cancel actions before exit. This adds the ability to gracefully exit provisionerd.
Codecov Report
@@ Coverage Diff @@
## main #372 +/- ##
==========================================
- Coverage 68.19% 68.02% -0.18%
==========================================
Files 148 148
Lines 8169 8271 +102
Branches 72 72
==========================================
+ Hits 5571 5626 +55
- Misses 2041 2085 +44
- Partials 557 560 +3
Continue to review full report at Codecov.
|
cb1c883
to
9830266
Compare
// This couldn't use terraform-exec, because it doesn't support cancellation, and there didn't appear | ||
// to be a straight-forward way to add it. |
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.
Interesting! Thanks for the comment
terraform.SetStdout(writer) | ||
t.logger.Debug(ctx, "running apply", slog.F("options", options)) | ||
err = terraform.Apply(ctx, options...) | ||
t.logger.Debug(ctx, "running apply", slog.F("vars", len(vars)), slog.F("env", len(env))) |
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 imagine some of these env vars may contain sensitive data - is there anything we need to do to protect them? Does slog
have the ability to obfuscate sensitive items?
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 only printed the len
here intentionally to obfuscate it!
// Terraform can fail and apply and still need to store it's state. | ||
// In this case, we return Complete with an explicit error message. |
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.
Thanks for the description. Good call on catching this case where we would still need to pick up the statefile.
_ = cmd.Process.Signal(os.Kill) | ||
} | ||
}() | ||
cmd.Stdout = stdout |
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.
Do we also care about Stderr
here?
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.
Good call on this! I just realized this was important when I started playing with the GCP provider... I'd hit Control+C
to stop the terraform apply
job and noted that it still updated the statefile - important for us to support that, too.
Exactly! That and being able to gracefully shutdown provisionerd instances is pretty important. That way our CI can gracefully upgrade provisionerd instances, instead of purging them and messing up workspace state. |
Terraform (or other provisioners) may need to clean up state, or
cancel actions before exit. This adds the ability to gracefully
exit provisionerd.
We'll eventually make this operate on a signal to allow for usage in a Kubernetes environment with graceful shutdowns.
The added
Shutdown()
function in provisionerd has the expected usage: