mirror of https://github.com/k3s-io/k3s
Add signal handler for catching Ctrl-C on hack/e2e
When operating e2e test, hack/e2e.go process creates kubetest process. To kill the kubetest process when stop e2e test with Ctrl-C, we need to send the signal to the process because it also creates another process and it needs to kill it. This PR adds the signal handler on hack/e2e.go to kill the kubetest process. NOTE: https://github.com/kubernetes/test-infra/pull/4154 is the part of kubetest. solve #43051pull/6/head
parent
ef7b7ebd9c
commit
122d881c01
10
hack/e2e.go
10
hack/e2e.go
|
@ -25,6 +25,7 @@ import (
|
|||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -81,12 +82,21 @@ func main() {
|
|||
}
|
||||
|
||||
func wait(cmd string, args ...string) error {
|
||||
sigChannel := make(chan os.Signal, 1)
|
||||
signal.Notify(sigChannel, os.Interrupt)
|
||||
|
||||
c := exec.Command(cmd, args...)
|
||||
c.Stdout = os.Stdout
|
||||
c.Stderr = os.Stderr
|
||||
if err := c.Start(); err != nil {
|
||||
return err
|
||||
}
|
||||
go func() {
|
||||
sig := <-sigChannel
|
||||
if err := c.Process.Signal(sig); err != nil {
|
||||
log.Fatalf("could not send %s signal %s: %v", cmd, sig, err)
|
||||
}
|
||||
}()
|
||||
return c.Wait()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue