sandbox: remove global variable of podsandbox controller

Signed-off-by: Abel Feng <fshb1988@gmail.com>
This commit is contained in:
Abel Feng 2023-09-17 22:58:45 +08:00 committed by f00589305
parent 7bca70c0c3
commit 3ef300ca75
3 changed files with 12 additions and 20 deletions

View File

@ -721,9 +721,6 @@ func (c *Client) SandboxStore() sandbox.Store {
// SandboxController returns the underlying sandbox controller client // SandboxController returns the underlying sandbox controller client
func (c *Client) SandboxController(name string) sandbox.Controller { func (c *Client) SandboxController(name string) sandbox.Controller {
// default sandboxer is shim // default sandboxer is shim
if len(name) == 0 {
name = "shim"
}
if c.sandboxers != nil { if c.sandboxers != nil {
return c.sandboxers[name] return c.sandboxers[name]
} }

View File

@ -49,7 +49,7 @@ func init() {
InitFn: func(ic *plugin.InitContext) (interface{}, error) { InitFn: func(ic *plugin.InitContext) (interface{}, error) {
// register the global controller to containerd plugin manager, // register the global controller to containerd plugin manager,
// the global controller will be initialized when cri plugin is initializing // the global controller will be initialized when cri plugin is initializing
return controller, nil return &Controller{}, nil
}, },
}) })
} }
@ -69,11 +69,6 @@ type ImageService interface {
GetImage(id string) (imagestore.Image, error) 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 { type Controller struct {
// config contains all configurations. // config contains all configurations.
config criconfig.Config config criconfig.Config
@ -93,7 +88,7 @@ type Controller struct {
store *Store store *Store
} }
func Init( func (c *Controller) Init(
config criconfig.Config, config criconfig.Config,
client *containerd.Client, client *containerd.Client,
sandboxStore *sandboxstore.Store, sandboxStore *sandboxstore.Store,
@ -102,14 +97,14 @@ func Init(
imageService ImageService, imageService ImageService,
baseOCISpecs map[string]*oci.Spec, baseOCISpecs map[string]*oci.Spec,
) { ) {
controller.cri = cri c.cri = cri
controller.client = client c.client = client
controller.config = config c.config = config
controller.sandboxStore = sandboxStore c.sandboxStore = sandboxStore
controller.os = os c.os = os
controller.baseOCISpecs = baseOCISpecs c.baseOCISpecs = baseOCISpecs
controller.store = NewStore() c.store = NewStore()
controller.imageService = imageService c.imageService = imageService
} }
var _ sandbox.Controller = (*Controller)(nil) var _ sandbox.Controller = (*Controller)(nil)

View File

@ -196,8 +196,8 @@ func NewCRIService(config criconfig.Config, client *containerd.Client, nri *nri.
return nil, err return nil, err
} }
// init the global podsandbox controller podSandboxController := c.client.SandboxController(string(criconfig.ModePodSandbox)).(*podsandbox.Controller)
podsandbox.Init(config, client, c.sandboxStore, c.os, c, c.imageService, c.baseOCISpecs) podSandboxController.Init(config, client, c.sandboxStore, c.os, c, c.imageService, c.baseOCISpecs)
c.nri = nri c.nri = nri