@@ -34,7 +34,6 @@ import (
3434 ctrdutil "github.com/containerd/cri/pkg/containerd/util"
3535 "github.com/containerd/cri/pkg/store"
3636 containerstore "github.com/containerd/cri/pkg/store/container"
37- imagestore "github.com/containerd/cri/pkg/store/image"
3837 sandboxstore "github.com/containerd/cri/pkg/store/sandbox"
3938)
4039
@@ -54,14 +53,12 @@ const (
5453// eventMonitor monitors containerd event and updates internal state correspondingly.
5554// TODO(random-liu): Handle event for each container in a separate goroutine.
5655type eventMonitor struct {
57- containerStore * containerstore.Store
58- sandboxStore * sandboxstore.Store
59- imageStore * imagestore.Store
60- ch <- chan * events.Envelope
61- errCh <- chan error
62- ctx context.Context
63- cancel context.CancelFunc
64- backOff * backOff
56+ c * criService
57+ ch <- chan * events.Envelope
58+ errCh <- chan error
59+ ctx context.Context
60+ cancel context.CancelFunc
61+ backOff * backOff
6562}
6663
6764type backOff struct {
@@ -84,16 +81,14 @@ type backOffQueue struct {
8481
8582// Create new event monitor. New event monitor will start subscribing containerd event. All events
8683// happen after it should be monitored.
87- func newEventMonitor (c * containerstore. Store , s * sandboxstore. Store , i * imagestore. Store ) * eventMonitor {
84+ func newEventMonitor (c * criService ) * eventMonitor {
8885 // event subscribe doesn't need namespace.
8986 ctx , cancel := context .WithCancel (context .Background ())
9087 return & eventMonitor {
91- containerStore : c ,
92- sandboxStore : s ,
93- imageStore : i ,
94- ctx : ctx ,
95- cancel : cancel ,
96- backOff : newBackOff (),
88+ c : c ,
89+ ctx : ctx ,
90+ cancel : cancel ,
91+ backOff : newBackOff (),
9792 }
9893}
9994
@@ -206,7 +201,7 @@ func (em *eventMonitor) handleEvent(any interface{}) error {
206201 case * eventtypes.TaskExit :
207202 e := any .(* eventtypes.TaskExit )
208203 logrus .Infof ("TaskExit event %+v" , e )
209- cntr , err := em .containerStore .Get (e .ContainerID )
204+ cntr , err := em .c . containerStore .Get (e .ContainerID )
210205 if err == nil {
211206 if err := handleContainerExit (ctx , e , cntr ); err != nil {
212207 return errors .Wrap (err , "failed to handle container TaskExit event" )
@@ -216,7 +211,7 @@ func (em *eventMonitor) handleEvent(any interface{}) error {
216211 return errors .Wrap (err , "can't find container for TaskExit event" )
217212 }
218213 // Use GetAll to include sandbox in unknown state.
219- sb , err := em .sandboxStore .GetAll (e .ContainerID )
214+ sb , err := em .c . sandboxStore .GetAll (e .ContainerID )
220215 if err == nil {
221216 if err := handleSandboxExit (ctx , e , sb ); err != nil {
222217 return errors .Wrap (err , "failed to handle sandbox TaskExit event" )
@@ -229,12 +224,12 @@ func (em *eventMonitor) handleEvent(any interface{}) error {
229224 case * eventtypes.TaskOOM :
230225 e := any .(* eventtypes.TaskOOM )
231226 logrus .Infof ("TaskOOM event %+v" , e )
232- cntr , err := em .containerStore .Get (e .ContainerID )
227+ cntr , err := em .c . containerStore .Get (e .ContainerID )
233228 if err != nil {
234229 if err != store .ErrNotExist {
235230 return errors .Wrap (err , "can't find container for TaskOOM event" )
236231 }
237- if _ , err = em .sandboxStore .Get (e .ContainerID ); err != nil {
232+ if _ , err = em .c . sandboxStore .Get (e .ContainerID ); err != nil {
238233 if err != store .ErrNotExist {
239234 return errors .Wrap (err , "can't find sandbox for TaskOOM event" )
240235 }
@@ -252,15 +247,15 @@ func (em *eventMonitor) handleEvent(any interface{}) error {
252247 case * eventtypes.ImageCreate :
253248 e := any .(* eventtypes.ImageCreate )
254249 logrus .Infof ("ImageCreate event %+v" , e )
255- return em .imageStore . Update (ctx , e .Name )
250+ return em .c . updateImage (ctx , e .Name )
256251 case * eventtypes.ImageUpdate :
257252 e := any .(* eventtypes.ImageUpdate )
258253 logrus .Infof ("ImageUpdate event %+v" , e )
259- return em .imageStore . Update (ctx , e .Name )
254+ return em .c . updateImage (ctx , e .Name )
260255 case * eventtypes.ImageDelete :
261256 e := any .(* eventtypes.ImageDelete )
262257 logrus .Infof ("ImageDelete event %+v" , e )
263- return em .imageStore . Update (ctx , e .Name )
258+ return em .c . updateImage (ctx , e .Name )
264259 }
265260
266261 return nil
0 commit comments