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
func (c *Client) SandboxController(name string) sandbox.Controller {
// default sandboxer is shim
if len(name) == 0 {
name = "shim"
}
if c.sandboxers != nil {
return c.sandboxers[name]
}

View File

@ -49,7 +49,7 @@ func init() {
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
return &Controller{}, nil
},
})
}
@ -69,11 +69,6 @@ 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
@ -93,7 +88,7 @@ type Controller struct {
store *Store
}
func Init(
func (c *Controller) Init(
config criconfig.Config,
client *containerd.Client,
sandboxStore *sandboxstore.Store,
@ -102,14 +97,14 @@ func Init(
imageService ImageService,
baseOCISpecs map[string]*oci.Spec,
) {
controller.cri = cri
controller.client = client
controller.config = config
controller.sandboxStore = sandboxStore
controller.os = os
controller.baseOCISpecs = baseOCISpecs
controller.store = NewStore()
controller.imageService = imageService
c.cri = cri
c.client = client
c.config = config
c.sandboxStore = sandboxStore
c.os = os
c.baseOCISpecs = baseOCISpecs
c.store = NewStore()
c.imageService = imageService
}
var _ sandbox.Controller = (*Controller)(nil)

View File

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