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

@ -134,10 +134,12 @@ func (p *Pod) maybeStopServiceContainer() error {
return
}
logrus.Debugf("Stopping service container %s", serviceCtr.ID())
if err := serviceCtr.Stop(); err != nil {
if !errors.Is(err, define.ErrCtrStopped) {
logrus.Errorf("Stopping service container %s: %v", serviceCtr.ID(), err)
}
if err := serviceCtr.Stop(); err != nil && !errors.Is(err, define.ErrCtrStopped) {
// Log this in debug mode so that we don't print out an error and confuse the user
// when the service container can't be stopped because it is in created state
// This can happen when an error happens during kube play and we are trying to
// clean up after the error.
logrus.Debugf("Error stopping service container %s: %v", serviceCtr.ID(), err)
}
})
return nil