sandbox: add sandbox controller v2
Signed-off-by: Abel Feng <fshb1988@gmail.com>
This commit is contained in:
parent
37943cf6e4
commit
e4df672ab8
@ -753,7 +753,7 @@ func (c *Client) SandboxController(name string) sandbox.Controller {
|
||||
}
|
||||
c.connMu.Lock()
|
||||
defer c.connMu.Unlock()
|
||||
return sandboxproxy.NewSandboxController(sandboxsapi.NewControllerClient(c.conn))
|
||||
return sandboxproxy.NewSandboxController(sandboxsapi.NewControllerClient(c.conn), name)
|
||||
}
|
||||
|
||||
// VersionService returns the underlying VersionClient
|
||||
|
@ -233,14 +233,23 @@ func WithInMemoryServices(ic *plugin.InitContext) Opt {
|
||||
|
||||
func WithInMemorySandboxControllers(ic *plugin.InitContext) Opt {
|
||||
return func(c *clientOpts) error {
|
||||
sc := make(map[string]sandbox.Controller)
|
||||
sandboxers, err := ic.GetByType(plugins.SandboxControllerPlugin)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sc := make(map[string]sandbox.Controller)
|
||||
for name, p := range sandboxers {
|
||||
sc[name] = p.(sandbox.Controller)
|
||||
}
|
||||
|
||||
podSandboxers, err := ic.GetByType(plugins.PodSandboxPlugin)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for name, p := range podSandboxers {
|
||||
sc[name] = p.(sandbox.Controller)
|
||||
}
|
||||
|
||||
c.services.sandboxers = sc
|
||||
return nil
|
||||
}
|
||||
|
@ -510,7 +510,7 @@ func LoadPlugins(ctx context.Context, config *srvconfig.Config) ([]plugin.Regist
|
||||
case string(plugins.SandboxControllerPlugin), "sandbox":
|
||||
t = plugins.SandboxControllerPlugin
|
||||
f = func(conn *grpc.ClientConn) interface{} {
|
||||
return sbproxy.NewSandboxController(sbapi.NewControllerClient(conn))
|
||||
return sbproxy.NewSandboxController(sbapi.NewControllerClient(conn), name)
|
||||
}
|
||||
case string(plugins.DiffPlugin), "diff":
|
||||
t = plugins.DiffPlugin
|
||||
|
@ -31,14 +31,15 @@ import (
|
||||
|
||||
// remoteSandboxController is a low level GRPC client for containerd's sandbox controller service
|
||||
type remoteSandboxController struct {
|
||||
client api.ControllerClient
|
||||
client api.ControllerClient
|
||||
sandboxerName string
|
||||
}
|
||||
|
||||
var _ sandbox.Controller = (*remoteSandboxController)(nil)
|
||||
|
||||
// NewSandboxController creates a client for a sandbox controller
|
||||
func NewSandboxController(client api.ControllerClient) sandbox.Controller {
|
||||
return &remoteSandboxController{client: client}
|
||||
func NewSandboxController(client api.ControllerClient, name string) sandbox.Controller {
|
||||
return &remoteSandboxController{client: client, sandboxerName: name}
|
||||
}
|
||||
|
||||
func (s *remoteSandboxController) Create(ctx context.Context, sandboxInfo sandbox.Sandbox, opts ...sandbox.CreateOpt) error {
|
||||
@ -54,6 +55,7 @@ func (s *remoteSandboxController) Create(ctx context.Context, sandboxInfo sandbo
|
||||
NetnsPath: options.NetNSPath,
|
||||
Annotations: options.Annotations,
|
||||
Sandbox: apiSandbox,
|
||||
Sandboxer: s.sandboxerName,
|
||||
})
|
||||
if err != nil {
|
||||
return errdefs.FromGRPC(err)
|
||||
@ -63,7 +65,10 @@ func (s *remoteSandboxController) Create(ctx context.Context, sandboxInfo sandbo
|
||||
}
|
||||
|
||||
func (s *remoteSandboxController) Start(ctx context.Context, sandboxID string) (sandbox.ControllerInstance, error) {
|
||||
resp, err := s.client.Start(ctx, &api.ControllerStartRequest{SandboxID: sandboxID})
|
||||
resp, err := s.client.Start(ctx, &api.ControllerStartRequest{
|
||||
SandboxID: sandboxID,
|
||||
Sandboxer: s.sandboxerName,
|
||||
})
|
||||
if err != nil {
|
||||
return sandbox.ControllerInstance{}, errdefs.FromGRPC(err)
|
||||
}
|
||||
@ -79,7 +84,10 @@ func (s *remoteSandboxController) Start(ctx context.Context, sandboxID string) (
|
||||
}
|
||||
|
||||
func (s *remoteSandboxController) Platform(ctx context.Context, sandboxID string) (imagespec.Platform, error) {
|
||||
resp, err := s.client.Platform(ctx, &api.ControllerPlatformRequest{SandboxID: sandboxID})
|
||||
resp, err := s.client.Platform(ctx, &api.ControllerPlatformRequest{
|
||||
SandboxID: sandboxID,
|
||||
Sandboxer: s.sandboxerName,
|
||||
})
|
||||
if err != nil {
|
||||
return imagespec.Platform{}, errdefs.FromGRPC(err)
|
||||
}
|
||||
@ -97,7 +105,10 @@ func (s *remoteSandboxController) Stop(ctx context.Context, sandboxID string, op
|
||||
for _, opt := range opts {
|
||||
opt(&soptions)
|
||||
}
|
||||
req := &api.ControllerStopRequest{SandboxID: sandboxID}
|
||||
req := &api.ControllerStopRequest{
|
||||
SandboxID: sandboxID,
|
||||
Sandboxer: s.sandboxerName,
|
||||
}
|
||||
if soptions.Timeout != nil {
|
||||
req.TimeoutSecs = uint32(soptions.Timeout.Seconds())
|
||||
}
|
||||
@ -110,7 +121,10 @@ func (s *remoteSandboxController) Stop(ctx context.Context, sandboxID string, op
|
||||
}
|
||||
|
||||
func (s *remoteSandboxController) Shutdown(ctx context.Context, sandboxID string) error {
|
||||
_, err := s.client.Shutdown(ctx, &api.ControllerShutdownRequest{SandboxID: sandboxID})
|
||||
_, err := s.client.Shutdown(ctx, &api.ControllerShutdownRequest{
|
||||
SandboxID: sandboxID,
|
||||
Sandboxer: s.sandboxerName,
|
||||
})
|
||||
if err != nil {
|
||||
return errdefs.FromGRPC(err)
|
||||
}
|
||||
@ -127,7 +141,10 @@ func (s *remoteSandboxController) Wait(ctx context.Context, sandboxID string) (s
|
||||
retryInterval time.Duration = 128
|
||||
)
|
||||
for {
|
||||
resp, err = s.client.Wait(ctx, &api.ControllerWaitRequest{SandboxID: sandboxID})
|
||||
resp, err = s.client.Wait(ctx, &api.ControllerWaitRequest{
|
||||
SandboxID: sandboxID,
|
||||
Sandboxer: s.sandboxerName,
|
||||
})
|
||||
if err != nil {
|
||||
grpcErr := errdefs.FromGRPC(err)
|
||||
if !errdefs.IsUnavailable(grpcErr) {
|
||||
@ -153,7 +170,11 @@ func (s *remoteSandboxController) Wait(ctx context.Context, sandboxID string) (s
|
||||
}
|
||||
|
||||
func (s *remoteSandboxController) Status(ctx context.Context, sandboxID string, verbose bool) (sandbox.ControllerStatus, error) {
|
||||
resp, err := s.client.Status(ctx, &api.ControllerStatusRequest{SandboxID: sandboxID, Verbose: verbose})
|
||||
resp, err := s.client.Status(ctx, &api.ControllerStatusRequest{
|
||||
SandboxID: sandboxID,
|
||||
Verbose: verbose,
|
||||
Sandboxer: s.sandboxerName,
|
||||
})
|
||||
if err != nil {
|
||||
return sandbox.ControllerStatus{}, errdefs.FromGRPC(err)
|
||||
}
|
||||
@ -171,7 +192,10 @@ func (s *remoteSandboxController) Status(ctx context.Context, sandboxID string,
|
||||
}
|
||||
|
||||
func (s *remoteSandboxController) Metrics(ctx context.Context, sandboxID string) (*types.Metric, error) {
|
||||
resp, err := s.client.Metrics(ctx, &api.ControllerMetricsRequest{SandboxID: sandboxID})
|
||||
resp, err := s.client.Metrics(ctx, &api.ControllerMetricsRequest{
|
||||
SandboxID: sandboxID,
|
||||
Sandboxer: s.sandboxerName,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errdefs.FromGRPC(err)
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ import (
|
||||
|
||||
func init() {
|
||||
registry.Register(&plugin.Registration{
|
||||
Type: plugins.SandboxControllerPlugin,
|
||||
Type: plugins.PodSandboxPlugin,
|
||||
ID: "podsandbox",
|
||||
Requires: []plugin.Type{
|
||||
plugins.EventPlugin,
|
||||
|
@ -48,6 +48,7 @@ func init() {
|
||||
ID: "cri",
|
||||
Requires: []plugin.Type{
|
||||
plugins.CRIServicePlugin,
|
||||
plugins.PodSandboxPlugin,
|
||||
plugins.SandboxControllerPlugin,
|
||||
plugins.NRIApiPlugin,
|
||||
plugins.EventPlugin,
|
||||
@ -237,13 +238,21 @@ func getNRIAPI(ic *plugin.InitContext) nriservice.API {
|
||||
}
|
||||
|
||||
func getSandboxControllers(ic *plugin.InitContext) (map[string]sandbox.Controller, error) {
|
||||
sc := make(map[string]sandbox.Controller)
|
||||
sandboxers, err := ic.GetByType(plugins.SandboxControllerPlugin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
sc := make(map[string]sandbox.Controller)
|
||||
for name, p := range sandboxers {
|
||||
sc[name] = p.(sandbox.Controller)
|
||||
}
|
||||
|
||||
podSandboxers, err := ic.GetByType(plugins.PodSandboxPlugin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for name, p := range podSandboxers {
|
||||
sc[name] = p.(sandbox.Controller)
|
||||
}
|
||||
return sc, nil
|
||||
}
|
||||
|
@ -41,20 +41,29 @@ func init() {
|
||||
Type: plugins.GRPCPlugin,
|
||||
ID: "sandbox-controllers",
|
||||
Requires: []plugin.Type{
|
||||
plugins.PodSandboxPlugin,
|
||||
plugins.SandboxControllerPlugin,
|
||||
plugins.EventPlugin,
|
||||
},
|
||||
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
|
||||
sandboxers, err := ic.GetByType(plugins.SandboxControllerPlugin)
|
||||
sc := make(map[string]sandbox.Controller)
|
||||
|
||||
sandboxers, err := ic.GetByType(plugins.PodSandboxPlugin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sc := make(map[string]sandbox.Controller)
|
||||
for name, p := range sandboxers {
|
||||
sc[name] = p.(sandbox.Controller)
|
||||
}
|
||||
|
||||
sandboxersV2, err := ic.GetByType(plugins.SandboxControllerPlugin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for name, p := range sandboxersV2 {
|
||||
sc[name] = p.(sandbox.Controller)
|
||||
}
|
||||
|
||||
ep, err := ic.GetSingle(plugins.EventPlugin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -63,6 +63,8 @@ const (
|
||||
TransferPlugin plugin.Type = "io.containerd.transfer.v1"
|
||||
// SandboxStorePlugin implements a sandbox store
|
||||
SandboxStorePlugin plugin.Type = "io.containerd.sandbox.store.v1"
|
||||
// PodSandboxPlugin is a special sandbox controller which use pause container as a sandbox.
|
||||
PodSandboxPlugin plugin.Type = "io.containerd.podsandbox.controller.v1"
|
||||
// SandboxControllerPlugin implements a sandbox controller
|
||||
SandboxControllerPlugin plugin.Type = "io.containerd.sandbox.controller.v1"
|
||||
// ImageVerifierPlugin implements an image verifier service
|
||||
|
Loading…
Reference in New Issue
Block a user