sandbox: support more sandbox controllers
make containerd extensible to support more sandbox controllers registered into containerd by config. we change the default sandbox controller plugin's name from "local" to "shim". to make sure we can get the controller by the plugin name it registered into containerd. Signed-off-by: Abel Feng <fshb1988@gmail.com>
This commit is contained in:
@@ -34,10 +34,26 @@ import (
|
||||
ctrdutil "github.com/containerd/containerd/pkg/cri/util"
|
||||
osinterface "github.com/containerd/containerd/pkg/os"
|
||||
"github.com/containerd/containerd/platforms"
|
||||
"github.com/containerd/containerd/plugin"
|
||||
"github.com/containerd/containerd/plugin/registry"
|
||||
"github.com/containerd/containerd/plugins"
|
||||
"github.com/containerd/containerd/protobuf"
|
||||
"github.com/containerd/containerd/sandbox"
|
||||
)
|
||||
|
||||
func init() {
|
||||
registry.Register(&plugin.Registration{
|
||||
Type: plugins.SandboxControllerPlugin,
|
||||
ID: "podsandbox",
|
||||
Requires: []plugin.Type{},
|
||||
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
|
||||
// register the global controller to containerd plugin manager,
|
||||
// the global controller will be initialized when cri plugin is initializing
|
||||
return controller, nil
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// CRIService interface contains things required by controller, but not yet refactored from criService.
|
||||
// TODO: this will be removed in subsequent iterations.
|
||||
type CRIService interface {
|
||||
@@ -53,6 +69,11 @@ type ImageService interface {
|
||||
GetImage(id string) (imagestore.Image, error)
|
||||
}
|
||||
|
||||
// As the dependency from this controller to cri plugin is hard to decouple,
|
||||
// we define a global podsandbox controller and register it to containerd plugin manager first,
|
||||
// we will initialize this controller when we initialize the cri plugin.
|
||||
var controller = &Controller{}
|
||||
|
||||
type Controller struct {
|
||||
// config contains all configurations.
|
||||
config criconfig.Config
|
||||
@@ -72,7 +93,7 @@ type Controller struct {
|
||||
store *Store
|
||||
}
|
||||
|
||||
func New(
|
||||
func Init(
|
||||
config criconfig.Config,
|
||||
client *containerd.Client,
|
||||
sandboxStore *sandboxstore.Store,
|
||||
@@ -80,17 +101,15 @@ func New(
|
||||
cri CRIService,
|
||||
imageService ImageService,
|
||||
baseOCISpecs map[string]*oci.Spec,
|
||||
) *Controller {
|
||||
return &Controller{
|
||||
config: config,
|
||||
client: client,
|
||||
imageService: imageService,
|
||||
sandboxStore: sandboxStore,
|
||||
os: os,
|
||||
cri: cri,
|
||||
baseOCISpecs: baseOCISpecs,
|
||||
store: NewStore(),
|
||||
}
|
||||
) {
|
||||
controller.cri = cri
|
||||
controller.client = client
|
||||
controller.config = config
|
||||
controller.sandboxStore = sandboxStore
|
||||
controller.os = os
|
||||
controller.baseOCISpecs = baseOCISpecs
|
||||
controller.store = NewStore()
|
||||
controller.imageService = imageService
|
||||
}
|
||||
|
||||
var _ sandbox.Controller = (*Controller)(nil)
|
||||
|
||||
Reference in New Issue
Block a user