Merge pull request #484 from yanxuean/event-filter
add filter for containerd event
This commit is contained in:
commit
6261a4a4ca
@ -40,7 +40,7 @@ func (c *criContainerdService) ContainerStatus(ctx context.Context, r *runtime.C
|
||||
// * ImageSpec in container config is image ID.
|
||||
// * ImageSpec in container status is image tag.
|
||||
// * ImageRef in container status is repo digest.
|
||||
spec := container.Metadata.Config.GetImage()
|
||||
spec := container.Config.GetImage()
|
||||
imageRef := container.ImageRef
|
||||
image, err := c.imageStore.Get(imageRef)
|
||||
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) {
|
||||
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
|
||||
@ -74,7 +78,7 @@ func (em *eventMonitor) start() (<-chan struct{}, error) {
|
||||
for {
|
||||
select {
|
||||
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)
|
||||
case err := <-em.errCh:
|
||||
logrus.WithError(err).Error("Failed to handle event stream")
|
||||
|
Loading…
Reference in New Issue
Block a user