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()
|
c.connMu.Lock()
|
||||||
defer c.connMu.Unlock()
|
defer c.connMu.Unlock()
|
||||||
return sandboxproxy.NewSandboxController(sandboxsapi.NewControllerClient(c.conn))
|
return sandboxproxy.NewSandboxController(sandboxsapi.NewControllerClient(c.conn), name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// VersionService returns the underlying VersionClient
|
// VersionService returns the underlying VersionClient
|
||||||
|
@ -233,14 +233,23 @@ func WithInMemoryServices(ic *plugin.InitContext) Opt {
|
|||||||
|
|
||||||
func WithInMemorySandboxControllers(ic *plugin.InitContext) Opt {
|
func WithInMemorySandboxControllers(ic *plugin.InitContext) Opt {
|
||||||
return func(c *clientOpts) error {
|
return func(c *clientOpts) error {
|
||||||
|
sc := make(map[string]sandbox.Controller)
|
||||||
sandboxers, err := ic.GetByType(plugins.SandboxControllerPlugin)
|
sandboxers, err := ic.GetByType(plugins.SandboxControllerPlugin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
sc := make(map[string]sandbox.Controller)
|
|
||||||
for name, p := range sandboxers {
|
for name, p := range sandboxers {
|
||||||
sc[name] = p.(sandbox.Controller)
|
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
|
c.services.sandboxers = sc
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -510,7 +510,7 @@ func LoadPlugins(ctx context.Context, config *srvconfig.Config) ([]plugin.Regist
|
|||||||
case string(plugins.SandboxControllerPlugin), "sandbox":
|
case string(plugins.SandboxControllerPlugin), "sandbox":
|
||||||
t = plugins.SandboxControllerPlugin
|
t = plugins.SandboxControllerPlugin
|
||||||
f = func(conn *grpc.ClientConn) interface{} {
|
f = func(conn *grpc.ClientConn) interface{} {
|
||||||
return sbproxy.NewSandboxController(sbapi.NewControllerClient(conn))
|
return sbproxy.NewSandboxController(sbapi.NewControllerClient(conn), name)
|
||||||
}
|
}
|
||||||
case string(plugins.DiffPlugin), "diff":
|
case string(plugins.DiffPlugin), "diff":
|
||||||
t = plugins.DiffPlugin
|
t = plugins.DiffPlugin
|
||||||
|
@ -31,14 +31,15 @@ import (
|
|||||||
|
|
||||||
// remoteSandboxController is a low level GRPC client for containerd's sandbox controller service
|
// remoteSandboxController is a low level GRPC client for containerd's sandbox controller service
|
||||||
type remoteSandboxController struct {
|
type remoteSandboxController struct {
|
||||||
client api.ControllerClient
|
client api.ControllerClient
|
||||||
|
sandboxerName string
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ sandbox.Controller = (*remoteSandboxController)(nil)
|
var _ sandbox.Controller = (*remoteSandboxController)(nil)
|
||||||
|
|
||||||
// NewSandboxController creates a client for a sandbox controller
|
// NewSandboxController creates a client for a sandbox controller
|
||||||
func NewSandboxController(client api.ControllerClient) sandbox.Controller {
|
func NewSandboxController(client api.ControllerClient, name string) sandbox.Controller {
|
||||||
return &remoteSandboxController{client: client}
|
return &remoteSandboxController{client: client, sandboxerName: name}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *remoteSandboxController) Create(ctx context.Context, sandboxInfo sandbox.Sandbox, opts ...sandbox.CreateOpt) error {
|
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,
|
NetnsPath: options.NetNSPath,
|
||||||
Annotations: options.Annotations,
|
Annotations: options.Annotations,
|
||||||
Sandbox: apiSandbox,
|
Sandbox: apiSandbox,
|
||||||
|
Sandboxer: s.sandboxerName,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errdefs.FromGRPC(err)
|
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) {
|
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 {
|
if err != nil {
|
||||||
return sandbox.ControllerInstance{}, errdefs.FromGRPC(err)
|
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) {
|
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 {
|
if err != nil {
|
||||||
return imagespec.Platform{}, errdefs.FromGRPC(err)
|
return imagespec.Platform{}, errdefs.FromGRPC(err)
|
||||||
}
|
}
|
||||||
@ -97,7 +105,10 @@ func (s *remoteSandboxController) Stop(ctx context.Context, sandboxID string, op
|
|||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
opt(&soptions)
|
opt(&soptions)
|
||||||
}
|
}
|
||||||
req := &api.ControllerStopRequest{SandboxID: sandboxID}
|
req := &api.ControllerStopRequest{
|
||||||
|
SandboxID: sandboxID,
|
||||||
|
Sandboxer: s.sandboxerName,
|
||||||
|
}
|
||||||
if soptions.Timeout != nil {
|
if soptions.Timeout != nil {
|
||||||
req.TimeoutSecs = uint32(soptions.Timeout.Seconds())
|
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 {
|
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 {
|
if err != nil {
|
||||||
return errdefs.FromGRPC(err)
|
return errdefs.FromGRPC(err)
|
||||||
}
|
}
|
||||||
@ -127,7 +141,10 @@ func (s *remoteSandboxController) Wait(ctx context.Context, sandboxID string) (s
|
|||||||
retryInterval time.Duration = 128
|
retryInterval time.Duration = 128
|
||||||
)
|
)
|
||||||
for {
|
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 {
|
if err != nil {
|
||||||
grpcErr := errdefs.FromGRPC(err)
|
grpcErr := errdefs.FromGRPC(err)
|
||||||
if !errdefs.IsUnavailable(grpcErr) {
|
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) {
|
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 {
|
if err != nil {
|
||||||
return sandbox.ControllerStatus{}, errdefs.FromGRPC(err)
|
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) {
|
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 {
|
if err != nil {
|
||||||
return nil, errdefs.FromGRPC(err)
|
return nil, errdefs.FromGRPC(err)
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ import (
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registry.Register(&plugin.Registration{
|
registry.Register(&plugin.Registration{
|
||||||
Type: plugins.SandboxControllerPlugin,
|
Type: plugins.PodSandboxPlugin,
|
||||||
ID: "podsandbox",
|
ID: "podsandbox",
|
||||||
Requires: []plugin.Type{
|
Requires: []plugin.Type{
|
||||||
plugins.EventPlugin,
|
plugins.EventPlugin,
|
||||||
|
@ -48,6 +48,7 @@ func init() {
|
|||||||
ID: "cri",
|
ID: "cri",
|
||||||
Requires: []plugin.Type{
|
Requires: []plugin.Type{
|
||||||
plugins.CRIServicePlugin,
|
plugins.CRIServicePlugin,
|
||||||
|
plugins.PodSandboxPlugin,
|
||||||
plugins.SandboxControllerPlugin,
|
plugins.SandboxControllerPlugin,
|
||||||
plugins.NRIApiPlugin,
|
plugins.NRIApiPlugin,
|
||||||
plugins.EventPlugin,
|
plugins.EventPlugin,
|
||||||
@ -237,13 +238,21 @@ func getNRIAPI(ic *plugin.InitContext) nriservice.API {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getSandboxControllers(ic *plugin.InitContext) (map[string]sandbox.Controller, error) {
|
func getSandboxControllers(ic *plugin.InitContext) (map[string]sandbox.Controller, error) {
|
||||||
|
sc := make(map[string]sandbox.Controller)
|
||||||
sandboxers, err := ic.GetByType(plugins.SandboxControllerPlugin)
|
sandboxers, err := ic.GetByType(plugins.SandboxControllerPlugin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
sc := make(map[string]sandbox.Controller)
|
|
||||||
for name, p := range sandboxers {
|
for name, p := range sandboxers {
|
||||||
sc[name] = p.(sandbox.Controller)
|
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
|
return sc, nil
|
||||||
}
|
}
|
||||||
|
@ -41,20 +41,29 @@ func init() {
|
|||||||
Type: plugins.GRPCPlugin,
|
Type: plugins.GRPCPlugin,
|
||||||
ID: "sandbox-controllers",
|
ID: "sandbox-controllers",
|
||||||
Requires: []plugin.Type{
|
Requires: []plugin.Type{
|
||||||
|
plugins.PodSandboxPlugin,
|
||||||
plugins.SandboxControllerPlugin,
|
plugins.SandboxControllerPlugin,
|
||||||
plugins.EventPlugin,
|
plugins.EventPlugin,
|
||||||
},
|
},
|
||||||
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
sc := make(map[string]sandbox.Controller)
|
|
||||||
for name, p := range sandboxers {
|
for name, p := range sandboxers {
|
||||||
sc[name] = p.(sandbox.Controller)
|
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)
|
ep, err := ic.GetSingle(plugins.EventPlugin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -63,6 +63,8 @@ const (
|
|||||||
TransferPlugin plugin.Type = "io.containerd.transfer.v1"
|
TransferPlugin plugin.Type = "io.containerd.transfer.v1"
|
||||||
// SandboxStorePlugin implements a sandbox store
|
// SandboxStorePlugin implements a sandbox store
|
||||||
SandboxStorePlugin plugin.Type = "io.containerd.sandbox.store.v1"
|
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 implements a sandbox controller
|
||||||
SandboxControllerPlugin plugin.Type = "io.containerd.sandbox.controller.v1"
|
SandboxControllerPlugin plugin.Type = "io.containerd.sandbox.controller.v1"
|
||||||
// ImageVerifierPlugin implements an image verifier service
|
// ImageVerifierPlugin implements an image verifier service
|
||||||
|
Loading…
Reference in New Issue
Block a user