diff --git a/containerd-shim-v2/start.go b/containerd-shim-v2/start.go index 173ca7c769..78dd8c9909 100644 --- a/containerd-shim-v2/start.go +++ b/containerd-shim-v2/start.go @@ -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 { diff --git a/containerd-shim-v2/wait.go b/containerd-shim-v2/wait.go index 88b0d198f7..5059fa478b 100644 --- a/containerd-shim-v2/wait.go +++ b/containerd-shim-v2/wait.go @@ -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" @@ -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, + }) + } + } +}