mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-06 06:03:28 +00:00
virtcontainers: add support for getOOMEvent agent endpoint to sandbox
[ port from runtime commit 86686b56a2bf7f6dd62f620278ae289564da51d0 ] This adds support for the getOOMEvent agent endpoint to retrieve OOM events from the agent. Signed-off-by: Alex Price <aprice@atlassian.com> Signed-off-by: Peng Tao <bergwolf@hyper.sh>
This commit is contained in:
parent
7c205be27d
commit
198339367b
@ -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 {
|
||||
|
@ -45,6 +45,7 @@ func TestStartStartSandboxSuccess(t *testing.T) {
|
||||
id: testSandboxID,
|
||||
sandbox: sandbox,
|
||||
containers: make(map[string]*container),
|
||||
ctx: namespaces.WithNamespace(context.Background(), "UnitTest"),
|
||||
}
|
||||
|
||||
reqCreate := &taskAPI.CreateTaskRequest{
|
||||
@ -93,6 +94,7 @@ func TestStartMissingAnnotation(t *testing.T) {
|
||||
id: testSandboxID,
|
||||
sandbox: sandbox,
|
||||
containers: make(map[string]*container),
|
||||
ctx: namespaces.WithNamespace(context.Background(), "UnitTest"),
|
||||
}
|
||||
|
||||
reqCreate := &taskAPI.CreateTaskRequest{
|
||||
@ -113,8 +115,7 @@ func TestStartMissingAnnotation(t *testing.T) {
|
||||
testingImpl.StartSandboxFunc = nil
|
||||
}()
|
||||
|
||||
ctx := namespaces.WithNamespace(context.Background(), "UnitTest")
|
||||
_, err = s.Start(ctx, reqStart)
|
||||
_, err = s.Start(s.ctx, reqStart)
|
||||
assert.Error(err)
|
||||
assert.False(vcmock.IsMockError(err))
|
||||
}
|
||||
@ -159,6 +160,7 @@ func TestStartStartContainerSucess(t *testing.T) {
|
||||
id: testSandboxID,
|
||||
sandbox: sandbox,
|
||||
containers: make(map[string]*container),
|
||||
ctx: namespaces.WithNamespace(context.Background(), "UnitTest"),
|
||||
}
|
||||
|
||||
reqCreate := &taskAPI.CreateTaskRequest{
|
||||
|
@ -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,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user