sandbox: remove SandboxersServicePlugin
Signed-off-by: Abel Feng <fshb1988@gmail.com>
This commit is contained in:
parent
0cf48bab2c
commit
25a4c3d235
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
||||
|
@ -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 (
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
},
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue
Block a user