diff --git a/client.go b/client.go index 50f95eb1a..b15f4e20c 100644 --- a/client.go +++ b/client.go @@ -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] } diff --git a/pkg/cri/server/podsandbox/controller.go b/pkg/cri/server/podsandbox/controller.go index beac42508..13ab1f9ab 100644 --- a/pkg/cri/server/podsandbox/controller.go +++ b/pkg/cri/server/podsandbox/controller.go @@ -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) diff --git a/pkg/cri/server/service.go b/pkg/cri/server/service.go index a186eeefb..3e3ec68a6 100644 --- a/pkg/cri/server/service.go +++ b/pkg/cri/server/service.go @@ -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