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:
Alex Price 2020-06-29 00:42:08 -07:00 committed by Peng Tao
parent 380f07ec4b
commit 7c205be27d
8 changed files with 48 additions and 1 deletions

View File

@ -259,4 +259,8 @@ type agent interface {
// load data from disk
load(persistapi.AgentState)
// getOOMEvent will wait on OOM events that occur in the sandbox.
// Will return the ID of the container where the event occurred.
getOOMEvent() (string, error)
}

View File

@ -98,6 +98,8 @@ type VCSandbox interface {
ListInterfaces() ([]*vcTypes.Interface, error)
UpdateRoutes(routes []*vcTypes.Route) ([]*vcTypes.Route, error)
ListRoutes() ([]*vcTypes.Route, error)
GetOOMEvent() (string, error)
}
// VCContainer is the Container interface

View File

@ -21,9 +21,9 @@ import (
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/api"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config"
persistapi "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist/api"
aTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols"
kataclient "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols/client"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols/grpc"
aTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols"
vcAnnotations "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/annotations"
vccgroups "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/cgroups"
ns "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/nsenter"
@ -127,6 +127,7 @@ const (
grpcSetGuestDateTimeRequest = "grpc.SetGuestDateTimeRequest"
grpcStartTracingRequest = "grpc.StartTracingRequest"
grpcStopTracingRequest = "grpc.StopTracingRequest"
grpcGetOOMEventRequest = "grpc.GetOOMEventRequest"
)
// The function is declared this way for mocking in unit tests
@ -2049,6 +2050,9 @@ func (k *kataAgent) installReqFunc(c *kataclient.AgentClient) {
k.reqHandlers[grpcStopTracingRequest] = func(ctx context.Context, req interface{}) (interface{}, error) {
return k.client.AgentServiceClient.StopTracing(ctx, req.(*grpc.StopTracingRequest))
}
k.reqHandlers[grpcGetOOMEventRequest] = func(ctx context.Context, req interface{}) (interface{}, error) {
return k.client.AgentServiceClient.GetOOMEvent(ctx, req.(*grpc.GetOOMEventRequest))
}
}
func (k *kataAgent) getReqContext(reqName string) (ctx context.Context, cancel context.CancelFunc) {
@ -2378,3 +2382,16 @@ func (k *kataAgent) load(s persistapi.AgentState) {
k.state.ProxyPid = s.ProxyPid
k.state.URL = s.URL
}
func (k *kataAgent) getOOMEvent() (string, error) {
req := &grpc.GetOOMEventRequest{}
result, err := k.sendReq(req)
if err != nil {
return "", err
}
oomEvent, ok := result.(*grpc.OOMEvent)
if ok {
return oomEvent.ContainerId, err
}
return "", err
}

View File

@ -350,6 +350,9 @@ func TestKataAgentSendReq(t *testing.T) {
_, err = k.readProcessStderr(container, execid, []byte{})
assert.Nil(err)
_, err = k.getOOMEvent()
assert.Nil(err)
}
func TestHandleEphemeralStorage(t *testing.T) {

View File

@ -236,3 +236,7 @@ func (n *noopAgent) save() (s persistapi.AgentState) {
// load is the Noop agent state loader. It does nothing.
func (n *noopAgent) load(s persistapi.AgentState) {}
func (n *noopAgent) getOOMEvent() (string, error) {
return "", nil
}

View File

@ -237,3 +237,12 @@ func TestNoopCopyFile(t *testing.T) {
err := n.copyFile("", "")
assert.Nil(err)
}
func TestNoopGetOOMEvent(t *testing.T) {
assert := assert.New(t)
n := &noopAgent{}
containerID, err := n.getOOMEvent()
assert.Nil(err)
assert.Empty(containerID)
}

View File

@ -212,3 +212,7 @@ func (s *Sandbox) UpdateRoutes(routes []*vcTypes.Route) ([]*vcTypes.Route, error
func (s *Sandbox) ListRoutes() ([]*vcTypes.Route, error) {
return nil, nil
}
func (s *Sandbox) GetOOMEvent() (string, error) {
return "", nil
}

View File

@ -2201,3 +2201,7 @@ func (s *Sandbox) GetPatchedOCISpec() *specs.Spec {
return nil
}
func (s *Sandbox) GetOOMEvent() (string, error) {
return s.agent.getOOMEvent()
}