mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
integration: custom etcd gracefully termination
when running integration tests without an external etcd, the framework spawns an etcd instance executing it in its own process and killing it once the test stops. Instead of killing it directly, allow etcd to exit gracefully or kill it after 5 seconds.
This commit is contained in:
parent
a3207872a3
commit
1756fe60d4
@ -26,6 +26,7 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"google.golang.org/grpc/grpclog"
|
"google.golang.org/grpc/grpclog"
|
||||||
@ -128,7 +129,18 @@ func RunCustomEtcd(dataDir string, customFlags []string) (url string, stopFn fun
|
|||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
stop := func() {
|
stop := func() {
|
||||||
cancel()
|
// try to exit etcd gracefully
|
||||||
|
defer cancel()
|
||||||
|
cmd.Process.Signal(syscall.SIGTERM)
|
||||||
|
go func() {
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
klog.Infof("etcd exited gracefully, context cancelled")
|
||||||
|
case <-time.After(5 * time.Second):
|
||||||
|
klog.Infof("etcd didn't exit in 5 seconds, killing it")
|
||||||
|
cancel()
|
||||||
|
}
|
||||||
|
}()
|
||||||
err := cmd.Wait()
|
err := cmd.Wait()
|
||||||
klog.Infof("etcd exit status: %v", err)
|
klog.Infof("etcd exit status: %v", err)
|
||||||
err = os.RemoveAll(etcdDataDir)
|
err = os.RemoveAll(etcdDataDir)
|
||||||
|
Loading…
Reference in New Issue
Block a user