mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 19:01:49 +00:00
Merge pull request #32154 from jessfraz/listen-for-signal-hack-e2e
Automatic merge from submit-queue hack/e2e.go: listen for Interrupt signal and attempt cleanup if run with --down <!-- Thanks for sending a pull request! Here are some tips for you: 1. If this is your first time, read our contributor guidelines https://github.com/kubernetes/kubernetes/blob/master/CONTRIBUTING.md and developer guide https://github.com/kubernetes/kubernetes/blob/master/docs/devel/development.md 2. If you want *faster* PR reviews, read how: https://github.com/kubernetes/kubernetes/blob/master/docs/devel/faster_reviews.md 3. Follow the instructions for writing a release note: https://github.com/kubernetes/kubernetes/blob/master/docs/devel/pull-requests.md#release-notes --> **What this PR does / why we need it**: adds a listener on ^C, so if `hack/e2e.go` is run with `--down` and the user ^C, then it will attempt to cleanup the resources. **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes # **Special notes for your reviewer**: **Release note**: <!-- Steps to write your release note: 1. Use the release-note-* labels to set the release note state (if you have access) 2. Enter your extended release note in the below block; leaving it blank means using the PR title as the release note. If no release note is required, just write `NONE`. --> ```release-note NONE ``` Signed-off-by: Jess Frazelle <me@jessfraz.com>
This commit is contained in:
commit
3c9600e4c4
16
hack/e2e.go
16
hack/e2e.go
@ -25,6 +25,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/signal"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
@ -159,6 +160,21 @@ func main() {
|
||||
log.Fatalf("Error creating deployer: %v", err)
|
||||
}
|
||||
|
||||
if *down {
|
||||
// listen for signals such as ^C and gracefully attempt to clean up
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, os.Interrupt)
|
||||
go func() {
|
||||
for range c {
|
||||
log.Print("Captured ^C, gracefully attempting to cleanup resources..")
|
||||
if err := deploy.Down(); err != nil {
|
||||
log.Printf("Tearing down deployment failed: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
if err := run(deploy); err != nil {
|
||||
log.Fatalf("Something went wrong: %s", err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user