Merge pull request #484 from yanxuean/event-filter

add filter for containerd event
This commit is contained in:
Lantao Liu 2018-01-30 00:27:43 -08:00 committed by GitHub
commit 6261a4a4ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View File

@ -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 {

View File

@ -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")