Use channel to propagate the stop info of sandbox
Signed-off-by: Yanqiang Miao <miao.yanqiang@zte.com.cn>
This commit is contained in:
@@ -39,7 +39,7 @@ type Container struct {
|
||||
// Container IO
|
||||
IO *cio.ContainerIO
|
||||
// StopCh is used to propagate the stop information of the container.
|
||||
StopCh
|
||||
store.StopCh
|
||||
}
|
||||
|
||||
// Opts sets specific information to newly created Container.
|
||||
@@ -80,7 +80,7 @@ func WithStatus(status Status, root string) Opts {
|
||||
func NewContainer(metadata Metadata, opts ...Opts) (Container, error) {
|
||||
c := Container{
|
||||
Metadata: metadata,
|
||||
StopCh: StopCh(make(chan struct{})),
|
||||
StopCh: store.StopCh(make(chan struct{})),
|
||||
}
|
||||
for _, o := range opts {
|
||||
if err := o(&c); err != nil {
|
||||
@@ -95,19 +95,6 @@ func (c *Container) Delete() error {
|
||||
return c.Status.Delete()
|
||||
}
|
||||
|
||||
// StopCh is used to propagate the stop information of a container.
|
||||
type StopCh chan struct{}
|
||||
|
||||
// Stop close stopCh of the container.
|
||||
func (ch StopCh) Stop() {
|
||||
close(ch)
|
||||
}
|
||||
|
||||
// Stopped return the stopCh of the container as a readonly channel.
|
||||
func (ch StopCh) Stopped() <-chan struct{} {
|
||||
return ch
|
||||
}
|
||||
|
||||
// Store stores all Containers.
|
||||
type Store struct {
|
||||
lock sync.RWMutex
|
||||
|
||||
@@ -22,6 +22,10 @@ import "sync"
|
||||
func WithFakeStatus(status Status) Opts {
|
||||
return func(c *Container) error {
|
||||
c.Status = &fakeStatusStorage{status: status}
|
||||
if status.FinishedAt != 0 {
|
||||
// Fake the TaskExit event
|
||||
c.Stop()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user