mirror of
				https://github.com/kata-containers/kata-containers.git
				synced 2025-10-31 17:37:20 +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:
		| @@ -259,4 +259,8 @@ type agent interface { | |||||||
|  |  | ||||||
| 	// load data from disk | 	// load data from disk | ||||||
| 	load(persistapi.AgentState) | 	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) | ||||||
| } | } | ||||||
|   | |||||||
| @@ -98,6 +98,8 @@ type VCSandbox interface { | |||||||
| 	ListInterfaces() ([]*vcTypes.Interface, error) | 	ListInterfaces() ([]*vcTypes.Interface, error) | ||||||
| 	UpdateRoutes(routes []*vcTypes.Route) ([]*vcTypes.Route, error) | 	UpdateRoutes(routes []*vcTypes.Route) ([]*vcTypes.Route, error) | ||||||
| 	ListRoutes() ([]*vcTypes.Route, error) | 	ListRoutes() ([]*vcTypes.Route, error) | ||||||
|  |  | ||||||
|  | 	GetOOMEvent() (string, error) | ||||||
| } | } | ||||||
|  |  | ||||||
| // VCContainer is the Container interface | // VCContainer is the Container interface | ||||||
|   | |||||||
| @@ -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/api" | ||||||
| 	"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config" | 	"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config" | ||||||
| 	persistapi "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/persist/api" | 	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" | 	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" | 	"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" | 	vcAnnotations "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/annotations" | ||||||
| 	vccgroups "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/cgroups" | 	vccgroups "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/cgroups" | ||||||
| 	ns "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/nsenter" | 	ns "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/nsenter" | ||||||
| @@ -127,6 +127,7 @@ const ( | |||||||
| 	grpcSetGuestDateTimeRequest  = "grpc.SetGuestDateTimeRequest" | 	grpcSetGuestDateTimeRequest  = "grpc.SetGuestDateTimeRequest" | ||||||
| 	grpcStartTracingRequest      = "grpc.StartTracingRequest" | 	grpcStartTracingRequest      = "grpc.StartTracingRequest" | ||||||
| 	grpcStopTracingRequest       = "grpc.StopTracingRequest" | 	grpcStopTracingRequest       = "grpc.StopTracingRequest" | ||||||
|  | 	grpcGetOOMEventRequest       = "grpc.GetOOMEventRequest" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| // The function is declared this way for mocking in unit tests | // 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) { | 	k.reqHandlers[grpcStopTracingRequest] = func(ctx context.Context, req interface{}) (interface{}, error) { | ||||||
| 		return k.client.AgentServiceClient.StopTracing(ctx, req.(*grpc.StopTracingRequest)) | 		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) { | 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.ProxyPid = s.ProxyPid | ||||||
| 	k.state.URL = s.URL | 	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 | ||||||
|  | } | ||||||
|   | |||||||
| @@ -350,6 +350,9 @@ func TestKataAgentSendReq(t *testing.T) { | |||||||
|  |  | ||||||
| 	_, err = k.readProcessStderr(container, execid, []byte{}) | 	_, err = k.readProcessStderr(container, execid, []byte{}) | ||||||
| 	assert.Nil(err) | 	assert.Nil(err) | ||||||
|  |  | ||||||
|  | 	_, err = k.getOOMEvent() | ||||||
|  | 	assert.Nil(err) | ||||||
| } | } | ||||||
|  |  | ||||||
| func TestHandleEphemeralStorage(t *testing.T) { | func TestHandleEphemeralStorage(t *testing.T) { | ||||||
|   | |||||||
| @@ -236,3 +236,7 @@ func (n *noopAgent) save() (s persistapi.AgentState) { | |||||||
|  |  | ||||||
| // load is the Noop agent state loader. It does nothing. | // load is the Noop agent state loader. It does nothing. | ||||||
| func (n *noopAgent) load(s persistapi.AgentState) {} | func (n *noopAgent) load(s persistapi.AgentState) {} | ||||||
|  |  | ||||||
|  | func (n *noopAgent) getOOMEvent() (string, error) { | ||||||
|  | 	return "", nil | ||||||
|  | } | ||||||
|   | |||||||
| @@ -237,3 +237,12 @@ func TestNoopCopyFile(t *testing.T) { | |||||||
| 	err := n.copyFile("", "") | 	err := n.copyFile("", "") | ||||||
| 	assert.Nil(err) | 	assert.Nil(err) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func TestNoopGetOOMEvent(t *testing.T) { | ||||||
|  | 	assert := assert.New(t) | ||||||
|  | 	n := &noopAgent{} | ||||||
|  |  | ||||||
|  | 	containerID, err := n.getOOMEvent() | ||||||
|  | 	assert.Nil(err) | ||||||
|  | 	assert.Empty(containerID) | ||||||
|  | } | ||||||
|   | |||||||
| @@ -212,3 +212,7 @@ func (s *Sandbox) UpdateRoutes(routes []*vcTypes.Route) ([]*vcTypes.Route, error | |||||||
| func (s *Sandbox) ListRoutes() ([]*vcTypes.Route, error) { | func (s *Sandbox) ListRoutes() ([]*vcTypes.Route, error) { | ||||||
| 	return nil, nil | 	return nil, nil | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func (s *Sandbox) GetOOMEvent() (string, error) { | ||||||
|  | 	return "", nil | ||||||
|  | } | ||||||
|   | |||||||
| @@ -2201,3 +2201,7 @@ func (s *Sandbox) GetPatchedOCISpec() *specs.Spec { | |||||||
|  |  | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func (s *Sandbox) GetOOMEvent() (string, error) { | ||||||
|  | 	return s.agent.getOOMEvent() | ||||||
|  | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user