play kube: Add --wait option

Add a way to keep play kube running in the foreground and terminating all pods
after receiving a a SIGINT or SIGTERM signal. The pods will also be
cleaned up after the containers in it have exited.
If an error occurrs during kube play, any resources created till the
error point will be cleane up also.

Add tests for the various scenarios.

Fixes #14522

Signed-off-by: Urvashi Mohnani <umohnani@redhat.com>
This commit is contained in:
Urvashi Mohnani
2023-01-11 10:08:06 +05:30
parent db53f38711
commit 20a42d0e4f
13 changed files with 244 additions and 62 deletions

View File

@ -27,6 +27,7 @@ var (
handlerOrder []string
shutdownInhibit sync.RWMutex
logrus = logrusImport.WithField("PID", os.Getpid())
ErrNotStarted = errors.New("shutdown signal handler has not yet been started")
)
// Start begins handling SIGTERM and SIGINT and will run the given on-signal
@ -84,7 +85,7 @@ func Start() error {
// Stop the shutdown signal handler.
func Stop() error {
if cancelChan == nil {
return errors.New("shutdown signal handler has not yet been started")
return ErrNotStarted
}
if stopped {
return nil