Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
virtcontainers: add support for getOOMEvent agent endpoint to sandbox
Browse files Browse the repository at this point in the history
This adds support for the getOOMEvent agent endpoint to retrieve OOM
events from the agent.

Signed-off-by: Alex Price <[email protected]>
  • Loading branch information
awprice committed Apr 28, 2020
1 parent ef8624b commit 86686b5
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 0 deletions.
4 changes: 4 additions & 0 deletions virtcontainers/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,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)
}
2 changes: 2 additions & 0 deletions virtcontainers/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions virtcontainers/kata_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1989,6 +1990,9 @@ func (k *kataAgent) installReqFunc(c *kataclient.AgentClient) {
k.reqHandlers[grpcStopTracingRequest] = func(ctx context.Context, req interface{}, opts ...golangGrpc.CallOption) (interface{}, error) {
return k.client.StopTracing(ctx, req.(*grpc.StopTracingRequest), opts...)
}
k.reqHandlers[grpcGetOOMEventRequest] = func(ctx context.Context, req interface{}, opts ...golangGrpc.CallOption) (interface{}, error) {
return k.client.GetOOMEvent(ctx, req.(*grpc.GetOOMEventRequest), opts...)
}
}

func (k *kataAgent) getReqContext(reqName string) (ctx context.Context, cancel context.CancelFunc) {
Expand Down Expand Up @@ -2311,3 +2315,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
}
7 changes: 7 additions & 0 deletions virtcontainers/kata_agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ func (p *gRPCProxy) MemHotplugByProbe(ctx context.Context, req *pb.MemHotplugByP
return &gpb.Empty{}, nil
}

func (p *gRPCProxy) GetOOMEvent(ctx context.Context, req *pb.GetOOMEventRequest) (*pb.OOMEvent, error) {
return &pb.OOMEvent{}, nil
}

func gRPCRegister(s *grpc.Server, srv interface{}) {
switch g := srv.(type) {
case *gRPCProxy:
Expand Down Expand Up @@ -347,6 +351,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) {
Expand Down
4 changes: 4 additions & 0 deletions virtcontainers/noop_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,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
}
9 changes: 9 additions & 0 deletions virtcontainers/noop_agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,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)
}
4 changes: 4 additions & 0 deletions virtcontainers/pkg/vcmock/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 4 additions & 0 deletions virtcontainers/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -2178,3 +2178,7 @@ func (s *Sandbox) GetPatchedOCISpec() *specs.Spec {

return nil
}

func (s *Sandbox) GetOOMEvent() (string, error) {
return s.agent.getOOMEvent()
}

0 comments on commit 86686b5

Please sign in to comment.