Skip to content

Commit

Permalink
shim: retrieve oom events after starting sandbox
Browse files Browse the repository at this point in the history
After starting the sandbox the shim will start polling for
oom events from the agent. Propagates oom events through to
containerd/cri.

fixes kata-containers#2150

Signed-off-by: Alex Price <[email protected]>
  • Loading branch information
awprice committed Apr 28, 2020
1 parent 86686b5 commit db28dcf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions containerd-shim-v2/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ func startContainer(ctx context.Context, s *service, c *container) error {
return err
}
go watchSandbox(s)

// Start watching for oom events
go watchOOMEvents(s)
} else {
_, err := s.sandbox.StartContainer(c.id)
if err != nil {
Expand Down
24 changes: 24 additions & 0 deletions containerd-shim-v2/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"path"
"time"

"github.com/containerd/containerd/api/events"
"github.com/containerd/containerd/api/types/task"
"github.com/containerd/containerd/mount"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -126,3 +127,26 @@ func watchSandbox(s *service) {
// Existing container/exec will be cleaned up by its waiters.
// No need to send async events here.
}

func watchOOMEvents(s *service) {
if s.sandbox == nil {
return
}

for {
select {
case <-s.ctx.Done():
return
default:
containerID, err := s.sandbox.GetOOMEvent()
if err != nil {
logrus.WithError(err).Warn("failed to get oom event from sandbox")
continue
}

s.send(&events.TaskOOM{
ContainerID: containerID,
})
}
}
}

0 comments on commit db28dcf

Please sign in to comment.