diff --git a/client/services.go b/client/services.go index 03da25246..2c9a009f7 100644 --- a/client/services.go +++ b/client/services.go @@ -87,16 +87,6 @@ func WithSnapshotters(snapshotters map[string]snapshots.Snapshotter) ServicesOpt } } -// WithSandboxers sets the sandbox controllers. -func WithSandboxers(sandboxers map[string]sandbox.Controller) ServicesOpt { - return func(s *services) { - s.sandboxers = make(map[string]sandbox.Controller) - for n, sn := range sandboxers { - s.sandboxers[n] = sn - } - } -} - // WithContainerClient sets the container service to use using a containers client. func WithContainerClient(containerService containersapi.ContainersClient) ServicesOpt { return func(s *services) { @@ -249,15 +239,17 @@ func WithInMemoryServices(ic *plugin.InitContext) Opt { } } -func WithSandboxersService(ic *plugin.InitContext) ClientOpt { +func WithSandboxers(ic *plugin.InitContext) Opt { return func(c *clientOpts) error { - sandboxesPlugin, err := ic.GetByID(plugins.SandboxesServicePlugin, srv.SandboxControllersService) + sandboxers, err := ic.GetByType(plugins.SandboxControllerPlugin) if err != nil { return err } - - sbs := sandboxesPlugin.(map[string]sandbox.Controller) - c.services.sandboxers = sbs + sc := make(map[string]sandbox.Controller) + for name, p := range sandboxers { + sc[name] = p.(sandbox.Controller) + } + c.services.sandboxers = sc return nil } } diff --git a/integration/build_local_containerd_helper_test.go b/integration/build_local_containerd_helper_test.go index cbd3fcb89..104942153 100644 --- a/integration/build_local_containerd_helper_test.go +++ b/integration/build_local_containerd_helper_test.go @@ -118,6 +118,7 @@ func buildLocalContainerdClient(t *testing.T, tmpDir string) *containerd.Client containerd.WithDefaultNamespace(constants.K8sContainerdNamespace), containerd.WithDefaultPlatform(platforms.Default()), containerd.WithInMemoryServices(lastInitContext), + containerd.WithSandboxers(lastInitContext), ) assert.NoError(t, err) diff --git a/pkg/cri/cri.go b/pkg/cri/cri.go index 8544230fb..de366503d 100644 --- a/pkg/cri/cri.go +++ b/pkg/cri/cri.go @@ -50,6 +50,7 @@ func init() { plugins.ServicePlugin, plugins.NRIApiPlugin, plugins.WarningPlugin, + plugins.SandboxControllerPlugin, }, InitFn: initCRIService, }) @@ -92,7 +93,7 @@ func initCRIService(ic *plugin.InitContext) (interface{}, error) { containerd.WithDefaultNamespace(constants.K8sContainerdNamespace), containerd.WithDefaultPlatform(platforms.Default()), containerd.WithInMemoryServices(ic), - containerd.WithSandboxersService(ic), + containerd.WithSandboxers(ic), ) if err != nil { return nil, fmt.Errorf("failed to create containerd client: %w", err) diff --git a/pkg/cri/server/service.go b/pkg/cri/server/service.go index 10c8a3882..498a8f5ae 100644 --- a/pkg/cri/server/service.go +++ b/pkg/cri/server/service.go @@ -138,11 +138,6 @@ func NewCRIService(config criconfig.Config, client *containerd.Client, nri *nri. return nil, fmt.Errorf("failed to find snapshotter %q", config.ContainerdConfig.Snapshotter) } - // TODO(dmcgowan): Get the full list directly from configured plugins - sbControllers := map[string]sandbox.Controller{ - string(criconfig.ModePodSandbox): client.SandboxController(string(criconfig.ModePodSandbox)), - string(criconfig.ModeShim): client.SandboxController(string(criconfig.ModeShim)), - } imageFSPaths := map[string]string{} for _, ociRuntime := range config.ContainerdConfig.Runtimes { // Can not use `c.RuntimeSnapshotter() yet, so hard-coding here.` @@ -151,10 +146,8 @@ func NewCRIService(config criconfig.Config, client *containerd.Client, nri *nri. imageFSPaths[snapshotter] = imageFSPath(config.ContainerdRootDir, snapshotter) log.L.Infof("Get image filesystem path %q for snapshotter %q", imageFSPaths[snapshotter], snapshotter) } - if _, ok := sbControllers[ociRuntime.Sandboxer]; !ok { - sbControllers[ociRuntime.Sandboxer] = client.SandboxController(ociRuntime.Sandboxer) - } } + snapshotter := config.ContainerdConfig.Snapshotter imageFSPaths[snapshotter] = imageFSPath(config.ContainerdRootDir, snapshotter) log.L.Infof("Get image filesystem path %q for snapshotter %q", imageFSPaths[snapshotter], snapshotter) @@ -217,8 +210,9 @@ func NewCRIService(config criconfig.Config, client *containerd.Client, nri *nri. return nil, err } + podSandboxController := client.SandboxController(string(criconfig.ModePodSandbox)).(*podsandbox.Controller) // Initialize pod sandbox controller - sbControllers[string(criconfig.ModePodSandbox)].(*podsandbox.Controller).Init(config, c.sandboxStore, c.os, c, c.imageService, c.baseOCISpecs) + podSandboxController.Init(config, c.sandboxStore, c.os, c, c.imageService, c.baseOCISpecs) c.nri = nri diff --git a/plugins/types.go b/plugins/types.go index eea2095bc..1ac4a2737 100644 --- a/plugins/types.go +++ b/plugins/types.go @@ -67,8 +67,6 @@ const ( ImageVerifierPlugin plugin.Type = "io.containerd.image-verifier.v1" // WarningPlugin implements a warning service WarningPlugin plugin.Type = "io.containerd.warning.v1" - // SandboxesServicePlugin implements sandboxes service - SandboxesServicePlugin plugin.Type = "io.containerd.service.sandboxes.v1" ) const ( diff --git a/services/sandbox/controller_service.go b/services/sandbox/controller_service.go index 8ef2736e7..84a5367e8 100644 --- a/services/sandbox/controller_service.go +++ b/services/sandbox/controller_service.go @@ -31,7 +31,6 @@ import ( "github.com/containerd/containerd/v2/plugins" "github.com/containerd/containerd/v2/protobuf" "github.com/containerd/containerd/v2/sandbox" - "github.com/containerd/containerd/v2/services" "github.com/containerd/log" "github.com/containerd/plugin" "github.com/containerd/plugin/registry" @@ -42,15 +41,20 @@ func init() { Type: plugins.GRPCPlugin, ID: "sandbox-controllers", Requires: []plugin.Type{ - plugins.SandboxesServicePlugin, + plugins.SandboxControllerPlugin, plugins.EventPlugin, }, InitFn: func(ic *plugin.InitContext) (interface{}, error) { - i, err := ic.GetByID(plugins.SandboxesServicePlugin, services.SandboxControllersService) + sandboxers, err := ic.GetByType(plugins.SandboxControllerPlugin) if err != nil { return nil, err } - sc := i.(map[string]sandbox.Controller) + + sc := make(map[string]sandbox.Controller) + for name, p := range sandboxers { + sc[name] = p.(sandbox.Controller) + } + ep, err := ic.GetSingle(plugins.EventPlugin) if err != nil { return nil, err diff --git a/services/sandbox/sandboxers.go b/services/sandbox/sandboxers.go deleted file mode 100644 index df09a800a..000000000 --- a/services/sandbox/sandboxers.go +++ /dev/null @@ -1,46 +0,0 @@ -/* - Copyright The containerd Authors. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package sandbox - -import ( - "github.com/containerd/containerd/v2/plugins" - "github.com/containerd/containerd/v2/sandbox" - "github.com/containerd/containerd/v2/services" - "github.com/containerd/plugin" - "github.com/containerd/plugin/registry" -) - -func init() { - registry.Register(&plugin.Registration{ - Type: plugins.SandboxesServicePlugin, - ID: services.SandboxControllersService, - Requires: []plugin.Type{ - plugins.SandboxControllerPlugin, - }, - InitFn: func(ic *plugin.InitContext) (interface{}, error) { - sandboxesRaw, err := ic.GetByType(plugins.SandboxControllerPlugin) - if err != nil { - return nil, err - } - sandboxers := make(map[string]sandbox.Controller) - for name, srv := range sandboxesRaw { - sandboxers[name] = srv.(sandbox.Controller) - } - return sandboxers, nil - }, - }) -}