mirror of
https://github.com/containers/podman.git
synced 2025-07-28 19:02:48 +08:00

Add the notion of an "exit policy" to a pod. This policy controls the behaviour when the last container of pod exits. Initially, there are two policies: - "continue" : the pod continues running. This is the default policy when creating a pod. - "stop" : stop the pod when the last container exits. This is the default behaviour for `play kube`. In order to implement the deferred stop of a pod, add a worker queue to the libpod runtime. The queue will pick up work items and in this case helps resolve dead locks that would otherwise occur if we attempted to stop a pod during container cleanup. Note that the default restart policy of `play kube` is "Always". Hence, in order to really solve #13464, the YAML files must set a custom restart policy; the tests use "OnFailure". Fixes: #13464 Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
42 lines
742 B
Go
42 lines
742 B
Go
package libpod
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
func (r *Runtime) startWorker() {
|
|
if r.workerChannel == nil {
|
|
r.workerChannel = make(chan func(), 1)
|
|
r.workerShutdown = make(chan bool)
|
|
}
|
|
go func() {
|
|
for {
|
|
// Make sure to read all workers before
|
|
// checking if we're about to shutdown.
|
|
for len(r.workerChannel) > 0 {
|
|
w := <-r.workerChannel
|
|
w()
|
|
}
|
|
|
|
select {
|
|
// We'll read from the shutdown channel only when all
|
|
// items above have been processed.
|
|
//
|
|
// (*Runtime).Shutdown() will block until until the
|
|
// item is read.
|
|
case <-r.workerShutdown:
|
|
return
|
|
|
|
default:
|
|
time.Sleep(100 * time.Millisecond)
|
|
}
|
|
}
|
|
}()
|
|
}
|
|
|
|
func (r *Runtime) queueWork(f func()) {
|
|
go func() {
|
|
r.workerChannel <- f
|
|
}()
|
|
}
|