add filter for containerd event
Signed-off-by: yanxuean <yan.xuean@zte.com.cn>
This commit is contained in:
parent
8d2d125d82
commit
6931a69881
@ -40,7 +40,7 @@ func (c *criContainerdService) ContainerStatus(ctx context.Context, r *runtime.C
|
|||||||
// * ImageSpec in container config is image ID.
|
// * ImageSpec in container config is image ID.
|
||||||
// * ImageSpec in container status is image tag.
|
// * ImageSpec in container status is image tag.
|
||||||
// * ImageRef in container status is repo digest.
|
// * ImageRef in container status is repo digest.
|
||||||
spec := container.Metadata.Config.GetImage()
|
spec := container.Config.GetImage()
|
||||||
imageRef := container.ImageRef
|
imageRef := container.ImageRef
|
||||||
image, err := c.imageStore.Get(imageRef)
|
image, err := c.imageStore.Get(imageRef)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -57,9 +57,13 @@ func newEventMonitor(c *containerstore.Store, s *sandboxstore.Store) *eventMonit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// subscribe starts subsribe containerd events. We separate subscribe from
|
// subscribe starts to subscribe containerd events.
|
||||||
func (em *eventMonitor) subscribe(client *containerd.Client) {
|
func (em *eventMonitor) subscribe(client *containerd.Client) {
|
||||||
em.ch, em.errCh = client.Subscribe(em.ctx)
|
filters := []string{
|
||||||
|
`topic=="/tasks/exit"`,
|
||||||
|
`topic=="/tasks/oom"`,
|
||||||
|
}
|
||||||
|
em.ch, em.errCh = client.Subscribe(em.ctx, filters...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// start starts the event monitor which monitors and handles all container events. It returns
|
// start starts the event monitor which monitors and handles all container events. It returns
|
||||||
@ -74,7 +78,7 @@ func (em *eventMonitor) start() (<-chan struct{}, error) {
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case e := <-em.ch:
|
case e := <-em.ch:
|
||||||
logrus.Debugf("Received container event timestamp - %v, namespace - %q, topic - %q", e.Timestamp, e.Namespace, e.Topic)
|
logrus.Debugf("Received containerd event timestamp - %v, namespace - %q, topic - %q", e.Timestamp, e.Namespace, e.Topic)
|
||||||
em.handleEvent(e)
|
em.handleEvent(e)
|
||||||
case err := <-em.errCh:
|
case err := <-em.errCh:
|
||||||
logrus.WithError(err).Error("Failed to handle event stream")
|
logrus.WithError(err).Error("Failed to handle event stream")
|
||||||
|
Loading…
Reference in New Issue
Block a user