mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-07 14:36:43 +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
|
return err
|
||||||
}
|
}
|
||||||
go watchSandbox(s)
|
go watchSandbox(s)
|
||||||
|
|
||||||
|
// Start watching for oom events
|
||||||
|
go watchOOMEvents(s)
|
||||||
} else {
|
} else {
|
||||||
_, err := s.sandbox.StartContainer(c.id)
|
_, err := s.sandbox.StartContainer(c.id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -45,6 +45,7 @@ func TestStartStartSandboxSuccess(t *testing.T) {
|
|||||||
id: testSandboxID,
|
id: testSandboxID,
|
||||||
sandbox: sandbox,
|
sandbox: sandbox,
|
||||||
containers: make(map[string]*container),
|
containers: make(map[string]*container),
|
||||||
|
ctx: namespaces.WithNamespace(context.Background(), "UnitTest"),
|
||||||
}
|
}
|
||||||
|
|
||||||
reqCreate := &taskAPI.CreateTaskRequest{
|
reqCreate := &taskAPI.CreateTaskRequest{
|
||||||
@ -93,6 +94,7 @@ func TestStartMissingAnnotation(t *testing.T) {
|
|||||||
id: testSandboxID,
|
id: testSandboxID,
|
||||||
sandbox: sandbox,
|
sandbox: sandbox,
|
||||||
containers: make(map[string]*container),
|
containers: make(map[string]*container),
|
||||||
|
ctx: namespaces.WithNamespace(context.Background(), "UnitTest"),
|
||||||
}
|
}
|
||||||
|
|
||||||
reqCreate := &taskAPI.CreateTaskRequest{
|
reqCreate := &taskAPI.CreateTaskRequest{
|
||||||
@ -113,8 +115,7 @@ func TestStartMissingAnnotation(t *testing.T) {
|
|||||||
testingImpl.StartSandboxFunc = nil
|
testingImpl.StartSandboxFunc = nil
|
||||||
}()
|
}()
|
||||||
|
|
||||||
ctx := namespaces.WithNamespace(context.Background(), "UnitTest")
|
_, err = s.Start(s.ctx, reqStart)
|
||||||
_, err = s.Start(ctx, reqStart)
|
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
assert.False(vcmock.IsMockError(err))
|
assert.False(vcmock.IsMockError(err))
|
||||||
}
|
}
|
||||||
@ -159,6 +160,7 @@ func TestStartStartContainerSucess(t *testing.T) {
|
|||||||
id: testSandboxID,
|
id: testSandboxID,
|
||||||
sandbox: sandbox,
|
sandbox: sandbox,
|
||||||
containers: make(map[string]*container),
|
containers: make(map[string]*container),
|
||||||
|
ctx: namespaces.WithNamespace(context.Background(), "UnitTest"),
|
||||||
}
|
}
|
||||||
|
|
||||||
reqCreate := &taskAPI.CreateTaskRequest{
|
reqCreate := &taskAPI.CreateTaskRequest{
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/containerd/containerd/api/events"
|
||||||
"github.com/containerd/containerd/api/types/task"
|
"github.com/containerd/containerd/api/types/task"
|
||||||
"github.com/containerd/containerd/mount"
|
"github.com/containerd/containerd/mount"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@ -126,3 +127,26 @@ func watchSandbox(s *service) {
|
|||||||
// Existing container/exec will be cleaned up by its waiters.
|
// Existing container/exec will be cleaned up by its waiters.
|
||||||
// No need to send async events here.
|
// 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