Publish sandbox events
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
This commit is contained in:
parent
65906335bf
commit
45dbb4e542
@ -19,14 +19,17 @@ package sandbox
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"google.golang.org/grpc"
|
||||||
|
"google.golang.org/protobuf/types/known/anypb"
|
||||||
|
|
||||||
|
eventtypes "github.com/containerd/containerd/api/events"
|
||||||
api "github.com/containerd/containerd/api/services/sandbox/v1"
|
api "github.com/containerd/containerd/api/services/sandbox/v1"
|
||||||
"github.com/containerd/containerd/errdefs"
|
"github.com/containerd/containerd/errdefs"
|
||||||
|
"github.com/containerd/containerd/events"
|
||||||
"github.com/containerd/containerd/log"
|
"github.com/containerd/containerd/log"
|
||||||
"github.com/containerd/containerd/plugin"
|
"github.com/containerd/containerd/plugin"
|
||||||
"github.com/containerd/containerd/protobuf"
|
"github.com/containerd/containerd/protobuf"
|
||||||
"github.com/containerd/containerd/sandbox"
|
"github.com/containerd/containerd/sandbox"
|
||||||
"google.golang.org/grpc"
|
|
||||||
"google.golang.org/protobuf/types/known/anypb"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -35,6 +38,7 @@ func init() {
|
|||||||
ID: "sandbox-controllers",
|
ID: "sandbox-controllers",
|
||||||
Requires: []plugin.Type{
|
Requires: []plugin.Type{
|
||||||
plugin.SandboxControllerPlugin,
|
plugin.SandboxControllerPlugin,
|
||||||
|
plugin.EventPlugin,
|
||||||
},
|
},
|
||||||
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
|
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
|
||||||
sc, err := ic.GetByID(plugin.SandboxControllerPlugin, "local")
|
sc, err := ic.GetByID(plugin.SandboxControllerPlugin, "local")
|
||||||
@ -42,8 +46,14 @@ func init() {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ep, err := ic.Get(plugin.EventPlugin)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return &controllerService{
|
return &controllerService{
|
||||||
local: sc.(sandbox.Controller),
|
local: sc.(sandbox.Controller),
|
||||||
|
publisher: ep.(events.Publisher),
|
||||||
}, nil
|
}, nil
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -51,6 +61,7 @@ func init() {
|
|||||||
|
|
||||||
type controllerService struct {
|
type controllerService struct {
|
||||||
local sandbox.Controller
|
local sandbox.Controller
|
||||||
|
publisher events.Publisher
|
||||||
api.UnimplementedControllerServer
|
api.UnimplementedControllerServer
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,6 +79,13 @@ func (s *controllerService) Create(ctx context.Context, req *api.ControllerCreat
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return &api.ControllerCreateResponse{}, errdefs.ToGRPC(err)
|
return &api.ControllerCreateResponse{}, errdefs.ToGRPC(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := s.publisher.Publish(ctx, "sandboxes/create", &eventtypes.SandboxCreate{
|
||||||
|
SandboxID: req.GetSandboxID(),
|
||||||
|
}); err != nil {
|
||||||
|
return &api.ControllerCreateResponse{}, errdefs.ToGRPC(err)
|
||||||
|
}
|
||||||
|
|
||||||
return &api.ControllerCreateResponse{
|
return &api.ControllerCreateResponse{
|
||||||
SandboxID: req.GetSandboxID(),
|
SandboxID: req.GetSandboxID(),
|
||||||
}, nil
|
}, nil
|
||||||
@ -79,6 +97,13 @@ func (s *controllerService) Start(ctx context.Context, req *api.ControllerStartR
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return &api.ControllerStartResponse{}, errdefs.ToGRPC(err)
|
return &api.ControllerStartResponse{}, errdefs.ToGRPC(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := s.publisher.Publish(ctx, "sandboxes/start", &eventtypes.SandboxStart{
|
||||||
|
SandboxID: req.GetSandboxID(),
|
||||||
|
}); err != nil {
|
||||||
|
return &api.ControllerStartResponse{}, errdefs.ToGRPC(err)
|
||||||
|
}
|
||||||
|
|
||||||
return &api.ControllerStartResponse{
|
return &api.ControllerStartResponse{
|
||||||
SandboxID: inst.SandboxID,
|
SandboxID: inst.SandboxID,
|
||||||
Pid: inst.Pid,
|
Pid: inst.Pid,
|
||||||
@ -98,6 +123,15 @@ func (s *controllerService) Wait(ctx context.Context, req *api.ControllerWaitReq
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return &api.ControllerWaitResponse{}, errdefs.ToGRPC(err)
|
return &api.ControllerWaitResponse{}, errdefs.ToGRPC(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := s.publisher.Publish(ctx, "sandboxes/exit", &eventtypes.SandboxExit{
|
||||||
|
SandboxID: req.GetSandboxID(),
|
||||||
|
ExitStatus: exitStatus.ExitStatus,
|
||||||
|
ExitedAt: protobuf.ToTimestamp(exitStatus.ExitedAt),
|
||||||
|
}); err != nil {
|
||||||
|
return &api.ControllerWaitResponse{}, errdefs.ToGRPC(err)
|
||||||
|
}
|
||||||
|
|
||||||
return &api.ControllerWaitResponse{
|
return &api.ControllerWaitResponse{
|
||||||
ExitStatus: exitStatus.ExitStatus,
|
ExitStatus: exitStatus.ExitStatus,
|
||||||
ExitedAt: protobuf.ToTimestamp(exitStatus.ExitedAt),
|
ExitedAt: protobuf.ToTimestamp(exitStatus.ExitedAt),
|
||||||
|
Loading…
Reference in New Issue
Block a user