Skip to content

Commit

Permalink
fix: subsribe to tasks/start instead of containers/create
Browse files Browse the repository at this point in the history
This makes it possible to retrieve run time information, such as PID.
Fixes #6. We assume the fact that we have proper task info outweighs the
fact that unstarted containers become invisible.

Signed-off-by: Jorik Jonker <[email protected]>
  • Loading branch information
jonkerj committed Apr 21, 2022
1 parent 9d9dc54 commit d2c3012
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions internal/runtimes/containerd/auditor.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func (a *Auditor) auditContainer(namespace string, container containerd.Containe

task, err := container.Task(ctx, nil)
if err != nil {
a.logger.Info("received an error retrieving task", zap.Error(err))
task = nil // non running tasks error, apparantly. Flag with nil task
}

Expand Down
8 changes: 4 additions & 4 deletions internal/runtimes/containerd/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (

func (a *Auditor) Watch() error {
ctx := context.Background()
eventStream, errC := a.containerdClient.client.EventService().Subscribe(ctx, `topic=="/containers/create"`)
a.logger.Info("listening for containers/create events")
eventStream, errC := a.containerdClient.client.EventService().Subscribe(ctx, `topic=="/tasks/start"`)
a.logger.Info("listening for tasks/start events")
for {
var (
event *events.Envelope
Expand All @@ -39,10 +39,10 @@ func (a *Auditor) Watch() error {
}

switch t := e.(type) {
case *apievents.ContainerCreate:
case *apievents.TaskStart:
nsCtx := namespaces.WithNamespace(ctx, event.Namespace)

container, err := a.containerdClient.client.LoadContainer(nsCtx, t.ID)
container, err := a.containerdClient.client.LoadContainer(nsCtx, t.ContainerID)
if err != nil {
a.logger.Warn("error getting container details", zap.Error(err))
continue
Expand Down

0 comments on commit d2c3012

Please sign in to comment.