From 9db21401c4b54f695001705423aad686407618f5 Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Tue, 31 Oct 2023 21:44:03 -0700 Subject: [PATCH] Switch to github.com/containerd/plugin Signed-off-by: Derek McGowan --- client/services.go | 15 +- cmd/containerd/command/config.go | 2 +- cmd/ctr/commands/plugins/plugins.go | 2 +- diff/lcow/lcow.go | 6 +- diff/walking/plugin/plugin.go | 6 +- diff/windows/windows.go | 6 +- events/plugin/plugin.go | 4 +- gc/scheduler/scheduler.go | 6 +- go.mod | 1 + go.sum | 2 + .../build_local_containerd_helper_test.go | 2 +- .../plugin_linux.go | 4 +- leases/plugin/local.go | 8 +- metadata/plugin/plugin.go | 16 +- metrics/cgroups/cgroups.go | 6 +- pkg/cri/cri.go | 4 +- pkg/cri/server/podsandbox/controller.go | 4 +- pkg/nri/plugin/plugin.go | 4 +- plugin/context.go | 4 +- plugins/imageverifier/plugin.go | 4 +- plugins/sandbox/controller.go | 4 +- plugins/sandbox/store.go | 6 +- plugins/streaming/manager.go | 6 +- plugins/transfer/plugin.go | 29 +-- plugins/types.go | 2 +- runtime/restart/monitor/monitor.go | 4 +- runtime/v2/example/example.go | 4 +- runtime/v2/manager.go | 6 +- runtime/v2/runc/pause/sandbox.go | 7 +- runtime/v2/runc/task/plugin/plugin_linux.go | 4 +- runtime/v2/shim/shim.go | 4 +- services/containers/local.go | 8 +- services/containers/service.go | 15 +- services/content/service.go | 16 +- services/content/store.go | 8 +- services/diff/local.go | 10 +- services/diff/service.go | 15 +- services/events/service.go | 4 +- services/healthcheck/service.go | 4 +- services/images/local.go | 12 +- services/images/service.go | 15 +- services/introspection/local.go | 15 +- services/introspection/service.go | 15 +- services/leases/service.go | 4 +- services/namespaces/local.go | 8 +- services/namespaces/service.go | 15 +- services/opt/service.go | 4 +- services/sandbox/controller_service.go | 17 +- services/sandbox/sandboxers.go | 10 +- services/sandbox/store_service.go | 4 +- services/server/config/config.go | 2 +- services/server/server.go | 12 +- services/server/server_test.go | 4 +- services/snapshots/service.go | 18 +- services/snapshots/snapshotters.go | 6 +- services/streaming/service.go | 4 +- services/tasks/local.go | 10 +- services/tasks/local_darwin.go | 2 +- services/tasks/local_freebsd.go | 2 +- services/tasks/local_unix.go | 2 +- services/tasks/local_windows.go | 2 +- services/tasks/service.go | 15 +- services/transfer/service.go | 10 +- services/version/service.go | 4 +- services/warning/service.go | 4 +- snapshots/blockfile/blockfile.go | 2 +- snapshots/blockfile/plugin/plugin.go | 4 +- snapshots/btrfs/btrfs.go | 2 +- snapshots/btrfs/btrfs_test.go | 2 +- snapshots/btrfs/plugin/plugin.go | 4 +- snapshots/devmapper/plugin/plugin.go | 4 +- snapshots/lcow/lcow.go | 4 +- snapshots/native/plugin/plugin.go | 4 +- snapshots/overlay/plugin/plugin.go | 4 +- snapshots/windows/windows.go | 4 +- tracing/plugin/otlp.go | 19 +- .../containerd/plugin/.golangci.yml | 30 +++ vendor/github.com/containerd/plugin/LICENSE | 191 +++++++++++++++++ vendor/github.com/containerd/plugin/README.md | 19 ++ .../github.com/containerd/plugin/context.go | 199 ++++++++++++++++++ .../containerd/plugin/dynamic/dynamic.go | 37 ++++ .../plugin/dynamic/dynamic_supported.go | 64 ++++++ .../plugin/dynamic/dynamic_unsupported.go | 28 +++ vendor/github.com/containerd/plugin/plugin.go | 178 ++++++++++++++++ .../containerd/plugin/registry/register.go | 50 +++++ vendor/modules.txt | 5 + 86 files changed, 998 insertions(+), 334 deletions(-) create mode 100644 vendor/github.com/containerd/plugin/.golangci.yml create mode 100644 vendor/github.com/containerd/plugin/LICENSE create mode 100644 vendor/github.com/containerd/plugin/README.md create mode 100644 vendor/github.com/containerd/plugin/context.go create mode 100644 vendor/github.com/containerd/plugin/dynamic/dynamic.go create mode 100644 vendor/github.com/containerd/plugin/dynamic/dynamic_supported.go create mode 100644 vendor/github.com/containerd/plugin/dynamic/dynamic_unsupported.go create mode 100644 vendor/github.com/containerd/plugin/plugin.go create mode 100644 vendor/github.com/containerd/plugin/registry/register.go diff --git a/client/services.go b/client/services.go index 392d3d7200c7..3ca357eb335d 100644 --- a/client/services.go +++ b/client/services.go @@ -30,12 +30,12 @@ import ( "github.com/containerd/containerd/v2/images" "github.com/containerd/containerd/v2/leases" "github.com/containerd/containerd/v2/namespaces" - "github.com/containerd/containerd/v2/plugin" "github.com/containerd/containerd/v2/plugins" "github.com/containerd/containerd/v2/sandbox" srv "github.com/containerd/containerd/v2/services" "github.com/containerd/containerd/v2/services/introspection" "github.com/containerd/containerd/v2/snapshots" + "github.com/containerd/plugin" ) type services struct { @@ -197,7 +197,7 @@ func WithInMemoryServices(ic *plugin.InitContext) Opt { return WithSandboxStore(i.(sandbox.Store)) }, } { - i, err := ic.Get(t) + i, err := ic.GetSingle(t) if err != nil { return fmt.Errorf("failed to get %q plugin: %w", t, err) } @@ -237,16 +237,9 @@ func WithInMemoryServices(ic *plugin.InitContext) Opt { return WithIntrospectionClient(s.(introspectionapi.IntrospectionClient)) }, } { - p := plugins[s] - if p == nil { - return fmt.Errorf("service %q not found", s) - } - i, err := p.Instance() - if err != nil { - return fmt.Errorf("failed to get instance of service %q: %w", s, err) - } + i := plugins[s] if i == nil { - return fmt.Errorf("instance of service %q not found", s) + return fmt.Errorf("service %q not found", s) } opts = append(opts, fn(i)) } diff --git a/cmd/containerd/command/config.go b/cmd/containerd/command/config.go index 7af5473d9572..9bd72c60c7ca 100644 --- a/cmd/containerd/command/config.go +++ b/cmd/containerd/command/config.go @@ -24,9 +24,9 @@ import ( "github.com/containerd/containerd/v2/defaults" "github.com/containerd/containerd/v2/images" "github.com/containerd/containerd/v2/pkg/timeout" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/services/server" srvconfig "github.com/containerd/containerd/v2/services/server/config" + "github.com/containerd/plugin/registry" ocispec "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pelletier/go-toml/v2" "github.com/urfave/cli" diff --git a/cmd/ctr/commands/plugins/plugins.go b/cmd/ctr/commands/plugins/plugins.go index 42788c473f38..7702518960df 100644 --- a/cmd/ctr/commands/plugins/plugins.go +++ b/cmd/ctr/commands/plugins/plugins.go @@ -26,7 +26,7 @@ import ( "github.com/containerd/containerd/v2/api/types" "github.com/containerd/containerd/v2/cmd/ctr/commands" "github.com/containerd/containerd/v2/platforms" - pluginutils "github.com/containerd/containerd/v2/plugin" + pluginutils "github.com/containerd/plugin" v1 "github.com/opencontainers/image-spec/specs-go/v1" "github.com/urfave/cli" "google.golang.org/grpc/codes" diff --git a/diff/lcow/lcow.go b/diff/lcow/lcow.go index 6deef33f7e44..8bd142eaf52f 100644 --- a/diff/lcow/lcow.go +++ b/diff/lcow/lcow.go @@ -35,10 +35,10 @@ import ( "github.com/containerd/containerd/v2/errdefs" "github.com/containerd/containerd/v2/metadata" "github.com/containerd/containerd/v2/mount" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" "github.com/containerd/log" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" digest "github.com/opencontainers/go-digest" ocispec "github.com/opencontainers/image-spec/specs-go/v1" ) @@ -56,7 +56,7 @@ func init() { plugins.MetadataPlugin, }, InitFn: func(ic *plugin.InitContext) (interface{}, error) { - md, err := ic.Get(plugins.MetadataPlugin) + md, err := ic.GetSingle(plugins.MetadataPlugin) if err != nil { return nil, err } diff --git a/diff/walking/plugin/plugin.go b/diff/walking/plugin/plugin.go index 2604ed7a7165..c1cdeec05518 100644 --- a/diff/walking/plugin/plugin.go +++ b/diff/walking/plugin/plugin.go @@ -22,9 +22,9 @@ import ( "github.com/containerd/containerd/v2/diff/walking" "github.com/containerd/containerd/v2/metadata" "github.com/containerd/containerd/v2/platforms" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" ) func init() { @@ -35,7 +35,7 @@ func init() { plugins.MetadataPlugin, }, InitFn: func(ic *plugin.InitContext) (interface{}, error) { - md, err := ic.Get(plugins.MetadataPlugin) + md, err := ic.GetSingle(plugins.MetadataPlugin) if err != nil { return nil, err } diff --git a/diff/windows/windows.go b/diff/windows/windows.go index 798f0f077868..632eb9e68d2e 100644 --- a/diff/windows/windows.go +++ b/diff/windows/windows.go @@ -38,10 +38,10 @@ import ( "github.com/containerd/containerd/v2/mount" "github.com/containerd/containerd/v2/pkg/epoch" "github.com/containerd/containerd/v2/platforms" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" "github.com/containerd/log" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" "github.com/opencontainers/go-digest" ocispec "github.com/opencontainers/image-spec/specs-go/v1" ) @@ -54,7 +54,7 @@ func init() { plugins.MetadataPlugin, }, InitFn: func(ic *plugin.InitContext) (interface{}, error) { - md, err := ic.Get(plugins.MetadataPlugin) + md, err := ic.GetSingle(plugins.MetadataPlugin) if err != nil { return nil, err } diff --git a/events/plugin/plugin.go b/events/plugin/plugin.go index 33025cf77029..09efb2be3a30 100644 --- a/events/plugin/plugin.go +++ b/events/plugin/plugin.go @@ -18,9 +18,9 @@ package plugin import ( "github.com/containerd/containerd/v2/events/exchange" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" ) func init() { diff --git a/gc/scheduler/scheduler.go b/gc/scheduler/scheduler.go index 6b15eb014c19..c19f0a2db888 100644 --- a/gc/scheduler/scheduler.go +++ b/gc/scheduler/scheduler.go @@ -24,10 +24,10 @@ import ( "time" "github.com/containerd/containerd/v2/gc" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" "github.com/containerd/log" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" ) // config configures the garbage collection policies. @@ -112,7 +112,7 @@ func init() { StartupDelay: duration(100 * time.Millisecond), }, InitFn: func(ic *plugin.InitContext) (interface{}, error) { - md, err := ic.Get(plugins.MetadataPlugin) + md, err := ic.GetSingle(plugins.MetadataPlugin) if err != nil { return nil, err } diff --git a/go.mod b/go.mod index f0c8d42a114d..34c974808cae 100644 --- a/go.mod +++ b/go.mod @@ -19,6 +19,7 @@ require ( github.com/containerd/go-runc v1.1.0 github.com/containerd/log v0.1.0 github.com/containerd/nri v0.5.0 + github.com/containerd/plugin v0.0.0-20231101173250-7ec69893e1e7 github.com/containerd/ttrpc v1.2.2 github.com/containerd/typeurl/v2 v2.1.1 github.com/containernetworking/cni v1.1.2 diff --git a/go.sum b/go.sum index dd46d3ea0286..712fc00101f7 100644 --- a/go.sum +++ b/go.sum @@ -188,6 +188,8 @@ github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3 github.com/containerd/nri v0.0.0-20201007170849-eb1350a75164/go.mod h1:+2wGSDGFYfE5+So4M5syatU0N0f0LbWpuqyMi4/BE8c= github.com/containerd/nri v0.5.0 h1:bwCtKpi8i5FCA8g8WjIZNod91CEfIloYpV0+TH2prnQ= github.com/containerd/nri v0.5.0/go.mod h1:qIu2NlP3r/qK4YGnNuQf0De4VPqQWP2i2CVBfAZbGzg= +github.com/containerd/plugin v0.0.0-20231101173250-7ec69893e1e7 h1:MUbtIMHEcMzj+8mPgHd5ett0WVbY/KYHa5tMvFs5Ejs= +github.com/containerd/plugin v0.0.0-20231101173250-7ec69893e1e7/go.mod h1:j6HlpMtkiZMgT4UsfVNxPBUkwdw9KQGU6nCLfRxnq+w= github.com/containerd/ttrpc v0.0.0-20190828154514-0e0f228740de/go.mod h1:PvCDdDGpgqzQIzDW1TphrGLssLDZp2GuS+X5DkEJB8o= github.com/containerd/ttrpc v0.0.0-20190828172938-92c8520ef9f8/go.mod h1:PvCDdDGpgqzQIzDW1TphrGLssLDZp2GuS+X5DkEJB8o= github.com/containerd/ttrpc v0.0.0-20191028202541-4f1b8fe65a5c/go.mod h1:LPm1u0xBw8r8NOKoOdNMeVHSawSsltak+Ihv+etqsE8= diff --git a/integration/build_local_containerd_helper_test.go b/integration/build_local_containerd_helper_test.go index 95b2bb7fda29..cbd3fcb8967f 100644 --- a/integration/build_local_containerd_helper_test.go +++ b/integration/build_local_containerd_helper_test.go @@ -25,11 +25,11 @@ import ( containerd "github.com/containerd/containerd/v2/client" "github.com/containerd/containerd/v2/pkg/cri/constants" "github.com/containerd/containerd/v2/platforms" - "github.com/containerd/containerd/v2/plugin" "github.com/containerd/containerd/v2/plugins" ctrdsrv "github.com/containerd/containerd/v2/services/server" srvconfig "github.com/containerd/containerd/v2/services/server/config" "github.com/containerd/log/logtest" + "github.com/containerd/plugin" _ "github.com/containerd/containerd/v2/diff/walking/plugin" _ "github.com/containerd/containerd/v2/events/plugin" diff --git a/integration/failpoint/cmd/containerd-shim-runc-fp-v1/plugin_linux.go b/integration/failpoint/cmd/containerd-shim-runc-fp-v1/plugin_linux.go index 1f75e72b6d9e..f67de2a3e752 100644 --- a/integration/failpoint/cmd/containerd-shim-runc-fp-v1/plugin_linux.go +++ b/integration/failpoint/cmd/containerd-shim-runc-fp-v1/plugin_linux.go @@ -27,11 +27,11 @@ import ( "github.com/containerd/containerd/v2/oci" "github.com/containerd/containerd/v2/pkg/failpoint" "github.com/containerd/containerd/v2/pkg/shutdown" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" "github.com/containerd/containerd/v2/runtime/v2/runc/task" "github.com/containerd/containerd/v2/runtime/v2/shim" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" "github.com/containerd/ttrpc" ) diff --git a/leases/plugin/local.go b/leases/plugin/local.go index b496396ff34e..54ef11c653fe 100644 --- a/leases/plugin/local.go +++ b/leases/plugin/local.go @@ -22,9 +22,9 @@ import ( "github.com/containerd/containerd/v2/gc" "github.com/containerd/containerd/v2/leases" "github.com/containerd/containerd/v2/metadata" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" ) func init() { @@ -36,11 +36,11 @@ func init() { plugins.GCPlugin, }, InitFn: func(ic *plugin.InitContext) (interface{}, error) { - m, err := ic.Get(plugins.MetadataPlugin) + m, err := ic.GetSingle(plugins.MetadataPlugin) if err != nil { return nil, err } - g, err := ic.Get(plugins.GCPlugin) + g, err := ic.GetSingle(plugins.GCPlugin) if err != nil { return nil, err } diff --git a/metadata/plugin/plugin.go b/metadata/plugin/plugin.go index 90f5d04661ed..babae1a7be71 100644 --- a/metadata/plugin/plugin.go +++ b/metadata/plugin/plugin.go @@ -27,11 +27,11 @@ import ( "github.com/containerd/containerd/v2/events" "github.com/containerd/containerd/v2/metadata" "github.com/containerd/containerd/v2/pkg/timeout" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" "github.com/containerd/containerd/v2/snapshots" "github.com/containerd/log" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" bolt "go.etcd.io/bbolt" ) @@ -99,7 +99,7 @@ func init() { if err := os.MkdirAll(root, 0711); err != nil { return nil, err } - cs, err := ic.Get(plugins.ContentPlugin) + cs, err := ic.GetSingle(plugins.ContentPlugin) if err != nil { return nil, err } @@ -111,18 +111,10 @@ func init() { snapshotters := make(map[string]snapshots.Snapshotter) for name, sn := range snapshottersRaw { - sn, err := sn.Instance() - if err != nil { - if !plugin.IsSkipPlugin(err) { - log.G(ic.Context).WithError(err). - Warnf("could not use snapshotter %v in metadata plugin", name) - } - continue - } snapshotters[name] = sn.(snapshots.Snapshotter) } - ep, err := ic.Get(plugins.EventPlugin) + ep, err := ic.GetSingle(plugins.EventPlugin) if err != nil { return nil, err } diff --git a/metrics/cgroups/cgroups.go b/metrics/cgroups/cgroups.go index 36483203e3cb..aee7af01135c 100644 --- a/metrics/cgroups/cgroups.go +++ b/metrics/cgroups/cgroups.go @@ -24,10 +24,10 @@ import ( v1 "github.com/containerd/containerd/v2/metrics/cgroups/v1" v2 "github.com/containerd/containerd/v2/metrics/cgroups/v2" "github.com/containerd/containerd/v2/platforms" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" "github.com/containerd/containerd/v2/runtime" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" metrics "github.com/docker/go-metrics" ) @@ -60,7 +60,7 @@ func New(ic *plugin.InitContext) (interface{}, error) { err error ) - ep, err := ic.Get(plugins.EventPlugin) + ep, err := ic.GetSingle(plugins.EventPlugin) if err != nil { return nil, err } diff --git a/pkg/cri/cri.go b/pkg/cri/cri.go index faf21af5b06a..c64d7b8dc5b9 100644 --- a/pkg/cri/cri.go +++ b/pkg/cri/cri.go @@ -26,10 +26,10 @@ import ( "github.com/containerd/containerd/v2/pkg/cri/server" nriservice "github.com/containerd/containerd/v2/pkg/nri" "github.com/containerd/containerd/v2/platforms" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" "github.com/containerd/log" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" imagespec "github.com/opencontainers/image-spec/specs-go/v1" "k8s.io/klog/v2" diff --git a/pkg/cri/server/podsandbox/controller.go b/pkg/cri/server/podsandbox/controller.go index 5c376bec17fe..45b3faf7d16a 100644 --- a/pkg/cri/server/podsandbox/controller.go +++ b/pkg/cri/server/podsandbox/controller.go @@ -34,11 +34,11 @@ import ( ctrdutil "github.com/containerd/containerd/v2/pkg/cri/util" osinterface "github.com/containerd/containerd/v2/pkg/os" "github.com/containerd/containerd/v2/platforms" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" "github.com/containerd/containerd/v2/protobuf" "github.com/containerd/containerd/v2/sandbox" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" ) func init() { diff --git a/pkg/nri/plugin/plugin.go b/pkg/nri/plugin/plugin.go index 4c564c94b7d5..a918b0917bb7 100644 --- a/pkg/nri/plugin/plugin.go +++ b/pkg/nri/plugin/plugin.go @@ -18,9 +18,9 @@ package plugin import ( "github.com/containerd/containerd/v2/pkg/nri" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" ) func init() { diff --git a/plugin/context.go b/plugin/context.go index 3f3364aaad8c..70d2d84bce53 100644 --- a/plugin/context.go +++ b/plugin/context.go @@ -51,8 +51,8 @@ func NewContext(ctx context.Context, plugins *Set, properties map[string]string) } } -// Get returns the first plugin by its type -func (i *InitContext) Get(t Type) (interface{}, error) { +// GetSingle returns the first plugin by its type +func (i *InitContext) GetSingle(t Type) (interface{}, error) { return i.plugins.Get(t) } diff --git a/plugins/imageverifier/plugin.go b/plugins/imageverifier/plugin.go index 7e9261395af2..94f559b04d7b 100644 --- a/plugins/imageverifier/plugin.go +++ b/plugins/imageverifier/plugin.go @@ -21,9 +21,9 @@ import ( "github.com/containerd/containerd/v2/pkg/imageverifier/bindir" "github.com/containerd/containerd/v2/pkg/tomlext" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" ) // Register default image verifier service plugin diff --git a/plugins/sandbox/controller.go b/plugins/sandbox/controller.go index 4ea68eee970d..f833e62a2e66 100644 --- a/plugins/sandbox/controller.go +++ b/plugins/sandbox/controller.go @@ -28,13 +28,13 @@ import ( "github.com/containerd/containerd/v2/events/exchange" "github.com/containerd/containerd/v2/mount" "github.com/containerd/containerd/v2/platforms" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" "github.com/containerd/containerd/v2/runtime" v2 "github.com/containerd/containerd/v2/runtime/v2" "github.com/containerd/containerd/v2/sandbox" "github.com/containerd/log" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" "google.golang.org/protobuf/types/known/anypb" ) diff --git a/plugins/sandbox/store.go b/plugins/sandbox/store.go index 811a35ddb679..7f5920324e72 100644 --- a/plugins/sandbox/store.go +++ b/plugins/sandbox/store.go @@ -18,9 +18,9 @@ package sandbox import ( "github.com/containerd/containerd/v2/metadata" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" ) func init() { @@ -31,7 +31,7 @@ func init() { plugins.MetadataPlugin, }, InitFn: func(ic *plugin.InitContext) (interface{}, error) { - m, err := ic.Get(plugins.MetadataPlugin) + m, err := ic.GetSingle(plugins.MetadataPlugin) if err != nil { return nil, err } diff --git a/plugins/streaming/manager.go b/plugins/streaming/manager.go index bdbb8a62c2b0..0c0c301fc967 100644 --- a/plugins/streaming/manager.go +++ b/plugins/streaming/manager.go @@ -27,9 +27,9 @@ import ( "github.com/containerd/containerd/v2/metadata" "github.com/containerd/containerd/v2/namespaces" "github.com/containerd/containerd/v2/pkg/streaming" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" ) func init() { @@ -40,7 +40,7 @@ func init() { plugins.MetadataPlugin, }, InitFn: func(ic *plugin.InitContext) (interface{}, error) { - md, err := ic.Get(plugins.MetadataPlugin) + md, err := ic.GetSingle(plugins.MetadataPlugin) if err != nil { return nil, err } diff --git a/plugins/transfer/plugin.go b/plugins/transfer/plugin.go index 73d215f81eae..865698246083 100644 --- a/plugins/transfer/plugin.go +++ b/plugins/transfer/plugin.go @@ -28,10 +28,10 @@ import ( "github.com/containerd/containerd/v2/pkg/transfer/local" "github.com/containerd/containerd/v2/pkg/unpack" "github.com/containerd/containerd/v2/platforms" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" "github.com/containerd/log" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" // Load packages with type registrations _ "github.com/containerd/containerd/v2/pkg/transfer/archive" @@ -53,12 +53,12 @@ func init() { Config: defaultConfig(), InitFn: func(ic *plugin.InitContext) (interface{}, error) { config := ic.Config.(*transferConfig) - m, err := ic.Get(plugins.MetadataPlugin) + m, err := ic.GetSingle(plugins.MetadataPlugin) if err != nil { return nil, err } ms := m.(*metadata.DB) - l, err := ic.Get(plugins.LeasePlugin) + l, err := ic.GetSingle(plugins.LeasePlugin) if err != nil { return nil, err } @@ -70,11 +70,7 @@ func init() { } for name, vp := range vps { - inst, err := vp.Instance() - if err != nil { - return nil, err - } - vfs[name] = inst.(imageverifier.ImageVerifier) + vfs[name] = vp.(imageverifier.ImageVerifier) } // Set configuration based on default or user input @@ -92,24 +88,19 @@ func init() { return nil, fmt.Errorf("snapshotter %q not found: %w", uc.Snapshotter, errdefs.ErrNotFound) } - diffPlugins, err := ic.GetByType(plugins.DiffPlugin) - if err != nil { - return nil, fmt.Errorf("error loading diff plugins: %w", err) - } var applier diff.Applier target := platforms.OnlyStrict(p) if uc.Differ != "" { - plugin, ok := diffPlugins[uc.Differ] - if !ok { - return nil, fmt.Errorf("diff plugin %q: %w", uc.Differ, errdefs.ErrNotFound) - } - inst, err := plugin.Instance() + inst, err := ic.GetByID(plugins.DiffPlugin, uc.Differ) if err != nil { return nil, fmt.Errorf("failed to get instance for diff plugin %q: %w", uc.Differ, err) } applier = inst.(diff.Applier) } else { - for name, plugin := range diffPlugins { + for name, plugin := range ic.GetAll() { + if plugin.Registration.Type != plugins.DiffPlugin { + continue + } var matched bool for _, p := range plugin.Meta.Platforms { if target.Match(p) { diff --git a/plugins/types.go b/plugins/types.go index 2e04a6fe76b8..1ac4a27375e9 100644 --- a/plugins/types.go +++ b/plugins/types.go @@ -20,7 +20,7 @@ // package. package plugins -import "github.com/containerd/containerd/v2/plugin" +import "github.com/containerd/plugin" const ( // InternalPlugin implements an internal plugin to containerd diff --git a/runtime/restart/monitor/monitor.go b/runtime/restart/monitor/monitor.go index 1b36f28bafc3..e73311779c9b 100644 --- a/runtime/restart/monitor/monitor.go +++ b/runtime/restart/monitor/monitor.go @@ -25,11 +25,11 @@ import ( containerd "github.com/containerd/containerd/v2/client" "github.com/containerd/containerd/v2/namespaces" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" "github.com/containerd/containerd/v2/runtime/restart" "github.com/containerd/log" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" ) type duration struct { diff --git a/runtime/v2/example/example.go b/runtime/v2/example/example.go index 0f56dd34e689..cef6df162230 100644 --- a/runtime/v2/example/example.go +++ b/runtime/v2/example/example.go @@ -23,11 +23,11 @@ import ( taskAPI "github.com/containerd/containerd/v2/api/runtime/task/v2" "github.com/containerd/containerd/v2/errdefs" "github.com/containerd/containerd/v2/pkg/shutdown" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" ptypes "github.com/containerd/containerd/v2/protobuf/types" "github.com/containerd/containerd/v2/runtime/v2/shim" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" "github.com/containerd/ttrpc" ) diff --git a/runtime/v2/manager.go b/runtime/v2/manager.go index 673c827726e8..072b167678f5 100644 --- a/runtime/v2/manager.go +++ b/runtime/v2/manager.go @@ -34,14 +34,14 @@ import ( "github.com/containerd/containerd/v2/pkg/cleanup" "github.com/containerd/containerd/v2/pkg/timeout" "github.com/containerd/containerd/v2/platforms" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" "github.com/containerd/containerd/v2/protobuf" "github.com/containerd/containerd/v2/runtime" shimbinary "github.com/containerd/containerd/v2/runtime/v2/shim" "github.com/containerd/containerd/v2/sandbox" "github.com/containerd/log" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" ) // Config for the v2 runtime @@ -72,7 +72,7 @@ func init() { ic.Meta.Platforms = supportedPlatforms - m, err := ic.Get(plugins.MetadataPlugin) + m, err := ic.GetSingle(plugins.MetadataPlugin) if err != nil { return nil, err } diff --git a/runtime/v2/runc/pause/sandbox.go b/runtime/v2/runc/pause/sandbox.go index 04822de6cf28..4aacd3b85b7c 100644 --- a/runtime/v2/runc/pause/sandbox.go +++ b/runtime/v2/runc/pause/sandbox.go @@ -22,16 +22,15 @@ import ( "context" "runtime" + api "github.com/containerd/containerd/v2/api/runtime/sandbox/v1" "github.com/containerd/containerd/v2/api/types" "github.com/containerd/containerd/v2/pkg/shutdown" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" "github.com/containerd/containerd/v2/runtime/v2/shim" "github.com/containerd/log" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" "github.com/containerd/ttrpc" - - api "github.com/containerd/containerd/v2/api/runtime/sandbox/v1" - "github.com/containerd/containerd/v2/plugin" ) func init() { diff --git a/runtime/v2/runc/task/plugin/plugin_linux.go b/runtime/v2/runc/task/plugin/plugin_linux.go index 306cba198983..2cf99243c9dc 100644 --- a/runtime/v2/runc/task/plugin/plugin_linux.go +++ b/runtime/v2/runc/task/plugin/plugin_linux.go @@ -18,11 +18,11 @@ package plugin import ( "github.com/containerd/containerd/v2/pkg/shutdown" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" "github.com/containerd/containerd/v2/runtime/v2/runc/task" "github.com/containerd/containerd/v2/runtime/v2/shim" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" ) func init() { diff --git a/runtime/v2/shim/shim.go b/runtime/v2/shim/shim.go index 366b63e8eb66..18d28a145a07 100644 --- a/runtime/v2/shim/shim.go +++ b/runtime/v2/shim/shim.go @@ -34,13 +34,13 @@ import ( "github.com/containerd/containerd/v2/events" "github.com/containerd/containerd/v2/namespaces" "github.com/containerd/containerd/v2/pkg/shutdown" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" "github.com/containerd/containerd/v2/protobuf" "github.com/containerd/containerd/v2/protobuf/proto" "github.com/containerd/containerd/v2/version" "github.com/containerd/log" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" "github.com/containerd/ttrpc" "github.com/sirupsen/logrus" ) diff --git a/services/containers/local.go b/services/containers/local.go index 27773924fb11..479c98219f26 100644 --- a/services/containers/local.go +++ b/services/containers/local.go @@ -26,11 +26,11 @@ import ( "github.com/containerd/containerd/v2/errdefs" "github.com/containerd/containerd/v2/events" "github.com/containerd/containerd/v2/metadata" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" ptypes "github.com/containerd/containerd/v2/protobuf/types" "github.com/containerd/containerd/v2/services" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" bolt "go.etcd.io/bbolt" "google.golang.org/grpc" "google.golang.org/grpc/codes" @@ -47,11 +47,11 @@ func init() { plugins.MetadataPlugin, }, InitFn: func(ic *plugin.InitContext) (interface{}, error) { - m, err := ic.Get(plugins.MetadataPlugin) + m, err := ic.GetSingle(plugins.MetadataPlugin) if err != nil { return nil, err } - ep, err := ic.Get(plugins.EventPlugin) + ep, err := ic.GetSingle(plugins.EventPlugin) if err != nil { return nil, err } diff --git a/services/containers/service.go b/services/containers/service.go index d140b3d36fbc..d78017968034 100644 --- a/services/containers/service.go +++ b/services/containers/service.go @@ -18,15 +18,14 @@ package containers import ( "context" - "errors" "io" api "github.com/containerd/containerd/v2/api/services/containers/v1" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" ptypes "github.com/containerd/containerd/v2/protobuf/types" "github.com/containerd/containerd/v2/services" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" "google.golang.org/grpc" ) @@ -38,15 +37,7 @@ func init() { plugins.ServicePlugin, }, InitFn: func(ic *plugin.InitContext) (interface{}, error) { - sps, err := ic.GetByType(plugins.ServicePlugin) - if err != nil { - return nil, err - } - p, ok := sps[services.ContainersService] - if !ok { - return nil, errors.New("containers service not found") - } - i, err := p.Instance() + i, err := ic.GetByID(plugins.ServicePlugin, services.ContainersService) if err != nil { return nil, err } diff --git a/services/content/service.go b/services/content/service.go index d72bbef1b943..2d8b810d6a54 100644 --- a/services/content/service.go +++ b/services/content/service.go @@ -17,14 +17,12 @@ package content import ( - "errors" - "github.com/containerd/containerd/v2/content" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" "github.com/containerd/containerd/v2/services" "github.com/containerd/containerd/v2/services/content/contentserver" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" ) func init() { @@ -35,15 +33,7 @@ func init() { plugins.ServicePlugin, }, InitFn: func(ic *plugin.InitContext) (interface{}, error) { - plugins, err := ic.GetByType(plugins.ServicePlugin) - if err != nil { - return nil, err - } - p, ok := plugins[services.ContentService] - if !ok { - return nil, errors.New("content store service not found") - } - cs, err := p.Instance() + cs, err := ic.GetByID(plugins.ServicePlugin, services.ContentService) if err != nil { return nil, err } diff --git a/services/content/store.go b/services/content/store.go index a48650e09592..85005c8e0fd8 100644 --- a/services/content/store.go +++ b/services/content/store.go @@ -23,10 +23,10 @@ import ( "github.com/containerd/containerd/v2/content" "github.com/containerd/containerd/v2/events" "github.com/containerd/containerd/v2/metadata" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" "github.com/containerd/containerd/v2/services" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" digest "github.com/opencontainers/go-digest" ) @@ -45,11 +45,11 @@ func init() { plugins.MetadataPlugin, }, InitFn: func(ic *plugin.InitContext) (interface{}, error) { - m, err := ic.Get(plugins.MetadataPlugin) + m, err := ic.GetSingle(plugins.MetadataPlugin) if err != nil { return nil, err } - ep, err := ic.Get(plugins.EventPlugin) + ep, err := ic.GetSingle(plugins.EventPlugin) if err != nil { return nil, err } diff --git a/services/diff/local.go b/services/diff/local.go index f79ef4401cf1..8fa3a43d7140 100644 --- a/services/diff/local.go +++ b/services/diff/local.go @@ -25,10 +25,10 @@ import ( "github.com/containerd/containerd/v2/errdefs" "github.com/containerd/containerd/v2/mount" "github.com/containerd/containerd/v2/oci" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" "github.com/containerd/containerd/v2/services" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" "github.com/containerd/typeurl/v2" ocispec "github.com/opencontainers/image-spec/specs-go/v1" "google.golang.org/grpc" @@ -66,14 +66,10 @@ func init() { orderedNames := ic.Config.(*config).Order ordered := make([]differ, len(orderedNames)) for i, n := range orderedNames { - differp, ok := differs[n] + d, ok := differs[n] if !ok { return nil, fmt.Errorf("needed differ not loaded: %s", n) } - d, err := differp.Instance() - if err != nil { - return nil, fmt.Errorf("could not load required differ due plugin init error: %s: %w", n, err) - } ordered[i], ok = d.(differ) if !ok { diff --git a/services/diff/service.go b/services/diff/service.go index 07035e2afab3..9144aebfaa70 100644 --- a/services/diff/service.go +++ b/services/diff/service.go @@ -18,13 +18,12 @@ package diff import ( "context" - "errors" diffapi "github.com/containerd/containerd/v2/api/services/diff/v1" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" "github.com/containerd/containerd/v2/services" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" "google.golang.org/grpc" ) @@ -36,15 +35,7 @@ func init() { plugins.ServicePlugin, }, InitFn: func(ic *plugin.InitContext) (interface{}, error) { - sps, err := ic.GetByType(plugins.ServicePlugin) - if err != nil { - return nil, err - } - p, ok := sps[services.DiffService] - if !ok { - return nil, errors.New("diff service not found") - } - i, err := p.Instance() + i, err := ic.GetByID(plugins.ServicePlugin, services.DiffService) if err != nil { return nil, err } diff --git a/services/events/service.go b/services/events/service.go index 52cc5a40c26d..b171ef6e5b1a 100644 --- a/services/events/service.go +++ b/services/events/service.go @@ -25,11 +25,11 @@ import ( "github.com/containerd/containerd/v2/errdefs" "github.com/containerd/containerd/v2/events" "github.com/containerd/containerd/v2/events/exchange" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" "github.com/containerd/containerd/v2/protobuf" ptypes "github.com/containerd/containerd/v2/protobuf/types" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" "github.com/containerd/ttrpc" "google.golang.org/grpc" ) diff --git a/services/healthcheck/service.go b/services/healthcheck/service.go index e17e0d7cf4f8..5da194d931b3 100644 --- a/services/healthcheck/service.go +++ b/services/healthcheck/service.go @@ -17,9 +17,9 @@ package healthcheck import ( - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" "google.golang.org/grpc" "google.golang.org/grpc/health" diff --git a/services/images/local.go b/services/images/local.go index f85c84d78ddb..f0a577328689 100644 --- a/services/images/local.go +++ b/services/images/local.go @@ -33,12 +33,12 @@ import ( "github.com/containerd/containerd/v2/metadata" "github.com/containerd/containerd/v2/pkg/deprecation" "github.com/containerd/containerd/v2/pkg/epoch" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" ptypes "github.com/containerd/containerd/v2/protobuf/types" "github.com/containerd/containerd/v2/services" "github.com/containerd/containerd/v2/services/warning" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" ) func init() { @@ -52,19 +52,19 @@ func init() { plugins.WarningPlugin, }, InitFn: func(ic *plugin.InitContext) (interface{}, error) { - m, err := ic.Get(plugins.MetadataPlugin) + m, err := ic.GetSingle(plugins.MetadataPlugin) if err != nil { return nil, err } - g, err := ic.Get(plugins.GCPlugin) + g, err := ic.GetSingle(plugins.GCPlugin) if err != nil { return nil, err } - ep, err := ic.Get(plugins.EventPlugin) + ep, err := ic.GetSingle(plugins.EventPlugin) if err != nil { return nil, err } - w, err := ic.Get(plugins.WarningPlugin) + w, err := ic.GetSingle(plugins.WarningPlugin) if err != nil { return nil, err } diff --git a/services/images/service.go b/services/images/service.go index b5263e9ebf9d..3b09201b4016 100644 --- a/services/images/service.go +++ b/services/images/service.go @@ -18,14 +18,13 @@ package images import ( "context" - "errors" imagesapi "github.com/containerd/containerd/v2/api/services/images/v1" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" ptypes "github.com/containerd/containerd/v2/protobuf/types" "github.com/containerd/containerd/v2/services" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" "google.golang.org/grpc" ) @@ -37,15 +36,7 @@ func init() { plugins.ServicePlugin, }, InitFn: func(ic *plugin.InitContext) (interface{}, error) { - sps, err := ic.GetByType(plugins.ServicePlugin) - if err != nil { - return nil, err - } - p, ok := sps[services.ImagesService] - if !ok { - return nil, errors.New("images service not found") - } - i, err := p.Instance() + i, err := ic.GetByID(plugins.ServicePlugin, services.ImagesService) if err != nil { return nil, err } diff --git a/services/introspection/local.go b/services/introspection/local.go index feff1457c963..e1405ad8de60 100644 --- a/services/introspection/local.go +++ b/services/introspection/local.go @@ -34,13 +34,13 @@ import ( "github.com/containerd/containerd/v2/api/types" "github.com/containerd/containerd/v2/errdefs" "github.com/containerd/containerd/v2/filters" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" "github.com/containerd/containerd/v2/protobuf" ptypes "github.com/containerd/containerd/v2/protobuf/types" "github.com/containerd/containerd/v2/services" "github.com/containerd/containerd/v2/services/warning" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" ) func init() { @@ -49,16 +49,7 @@ func init() { ID: services.IntrospectionService, Requires: []plugin.Type{plugins.WarningPlugin}, InitFn: func(ic *plugin.InitContext) (interface{}, error) { - sps, err := ic.GetByType(plugins.WarningPlugin) - if err != nil { - return nil, err - } - p, ok := sps[plugins.DeprecationsPlugin] - if !ok { - return nil, errors.New("warning service not found") - } - - i, err := p.Instance() + i, err := ic.GetByID(plugins.WarningPlugin, plugins.DeprecationsPlugin) if err != nil { return nil, err } diff --git a/services/introspection/service.go b/services/introspection/service.go index e9cb15619eb5..6c791913ac37 100644 --- a/services/introspection/service.go +++ b/services/introspection/service.go @@ -21,11 +21,11 @@ import ( "errors" api "github.com/containerd/containerd/v2/api/services/introspection/v1" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" ptypes "github.com/containerd/containerd/v2/protobuf/types" "github.com/containerd/containerd/v2/services" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" "google.golang.org/grpc" ) @@ -35,16 +35,7 @@ func init() { ID: "introspection", Requires: []plugin.Type{plugins.ServicePlugin}, InitFn: func(ic *plugin.InitContext) (interface{}, error) { - sps, err := ic.GetByType(plugins.ServicePlugin) - if err != nil { - return nil, err - } - p, ok := sps[services.IntrospectionService] - if !ok { - return nil, errors.New("introspection service not found") - } - - i, err := p.Instance() + i, err := ic.GetByID(plugins.ServicePlugin, services.IntrospectionService) if err != nil { return nil, err } diff --git a/services/leases/service.go b/services/leases/service.go index a9404af91267..1c40368858f8 100644 --- a/services/leases/service.go +++ b/services/leases/service.go @@ -22,11 +22,11 @@ import ( api "github.com/containerd/containerd/v2/api/services/leases/v1" "github.com/containerd/containerd/v2/errdefs" "github.com/containerd/containerd/v2/leases" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" "github.com/containerd/containerd/v2/protobuf" ptypes "github.com/containerd/containerd/v2/protobuf/types" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" "google.golang.org/grpc" ) diff --git a/services/namespaces/local.go b/services/namespaces/local.go index 28ce52169bbb..2a6dc8d77c03 100644 --- a/services/namespaces/local.go +++ b/services/namespaces/local.go @@ -26,11 +26,11 @@ import ( "github.com/containerd/containerd/v2/events" "github.com/containerd/containerd/v2/metadata" "github.com/containerd/containerd/v2/namespaces" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" ptypes "github.com/containerd/containerd/v2/protobuf/types" "github.com/containerd/containerd/v2/services" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" bolt "go.etcd.io/bbolt" "google.golang.org/grpc" "google.golang.org/grpc/codes" @@ -46,11 +46,11 @@ func init() { plugins.MetadataPlugin, }, InitFn: func(ic *plugin.InitContext) (interface{}, error) { - m, err := ic.Get(plugins.MetadataPlugin) + m, err := ic.GetSingle(plugins.MetadataPlugin) if err != nil { return nil, err } - ep, err := ic.Get(plugins.EventPlugin) + ep, err := ic.GetSingle(plugins.EventPlugin) if err != nil { return nil, err } diff --git a/services/namespaces/service.go b/services/namespaces/service.go index 3d0e14fc6096..123a18d837a8 100644 --- a/services/namespaces/service.go +++ b/services/namespaces/service.go @@ -18,14 +18,13 @@ package namespaces import ( "context" - "errors" api "github.com/containerd/containerd/v2/api/services/namespaces/v1" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" ptypes "github.com/containerd/containerd/v2/protobuf/types" "github.com/containerd/containerd/v2/services" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" "google.golang.org/grpc" ) @@ -37,15 +36,7 @@ func init() { plugins.ServicePlugin, }, InitFn: func(ic *plugin.InitContext) (interface{}, error) { - sps, err := ic.GetByType(plugins.ServicePlugin) - if err != nil { - return nil, err - } - p, ok := sps[services.NamespacesService] - if !ok { - return nil, errors.New("namespaces service not found") - } - i, err := p.Instance() + i, err := ic.GetByID(plugins.ServicePlugin, services.NamespacesService) if err != nil { return nil, err } diff --git a/services/opt/service.go b/services/opt/service.go index 2b2af445f563..f9b1292927ce 100644 --- a/services/opt/service.go +++ b/services/opt/service.go @@ -21,9 +21,9 @@ import ( "os" "path/filepath" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" ) // Config for the opt manager diff --git a/services/sandbox/controller_service.go b/services/sandbox/controller_service.go index 0bc67ff674e8..dd8cc352eb0e 100644 --- a/services/sandbox/controller_service.go +++ b/services/sandbox/controller_service.go @@ -18,7 +18,6 @@ package sandbox import ( "context" - "errors" "fmt" "time" @@ -29,13 +28,13 @@ import ( api "github.com/containerd/containerd/v2/api/services/sandbox/v1" "github.com/containerd/containerd/v2/errdefs" "github.com/containerd/containerd/v2/events" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "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" ) func init() { @@ -47,20 +46,12 @@ func init() { plugins.EventPlugin, }, InitFn: func(ic *plugin.InitContext) (interface{}, error) { - plugs, err := ic.GetByType(plugins.ServicePlugin) - if err != nil { - return nil, err - } - p, ok := plugs[services.SandboxControllersService] - if !ok { - return nil, errors.New("sandboxes service not found") - } - i, err := p.Instance() + i, err := ic.GetByID(plugins.ServicePlugin, services.SandboxControllersService) if err != nil { return nil, err } sc := i.(map[string]sandbox.Controller) - ep, err := ic.Get(plugins.EventPlugin) + ep, err := ic.GetSingle(plugins.EventPlugin) if err != nil { return nil, err } diff --git a/services/sandbox/sandboxers.go b/services/sandbox/sandboxers.go index cddbbf02df57..85db67018ecd 100644 --- a/services/sandbox/sandboxers.go +++ b/services/sandbox/sandboxers.go @@ -17,11 +17,11 @@ package sandbox import ( - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "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() { @@ -38,11 +38,7 @@ func init() { } sandboxers := make(map[string]sandbox.Controller) for name, srv := range sandboxesRaw { - inst, err := srv.Instance() - if err != nil { - return nil, err - } - sandboxers[name] = inst.(sandbox.Controller) + sandboxers[name] = srv.(sandbox.Controller) } return sandboxers, nil }, diff --git a/services/sandbox/store_service.go b/services/sandbox/store_service.go index 233526008e3e..eaafd012884b 100644 --- a/services/sandbox/store_service.go +++ b/services/sandbox/store_service.go @@ -24,11 +24,11 @@ import ( api "github.com/containerd/containerd/v2/api/services/sandbox/v1" "github.com/containerd/containerd/v2/api/types" "github.com/containerd/containerd/v2/errdefs" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" "github.com/containerd/containerd/v2/sandbox" "github.com/containerd/log" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" ) func init() { diff --git a/services/server/config/config.go b/services/server/config/config.go index fad902b0c073..8c25b52f0130 100644 --- a/services/server/config/config.go +++ b/services/server/config/config.go @@ -36,8 +36,8 @@ import ( "github.com/pelletier/go-toml/v2" "github.com/containerd/containerd/v2/errdefs" - "github.com/containerd/containerd/v2/plugin" "github.com/containerd/log" + "github.com/containerd/plugin" ) // CurrentConfigVersion is the max config version which is supported diff --git a/services/server/server.go b/services/server/server.go index 9b6e8fd7333e..bf775aa6336d 100644 --- a/services/server/server.go +++ b/services/server/server.go @@ -59,15 +59,15 @@ import ( "github.com/containerd/containerd/v2/pkg/dialer" "github.com/containerd/containerd/v2/pkg/timeout" "github.com/containerd/containerd/v2/platforms" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/dynamic" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" sbproxy "github.com/containerd/containerd/v2/sandbox/proxy" srvconfig "github.com/containerd/containerd/v2/services/server/config" "github.com/containerd/containerd/v2/services/warning" ssproxy "github.com/containerd/containerd/v2/snapshots/proxy" "github.com/containerd/containerd/v2/sys" + "github.com/containerd/plugin" + "github.com/containerd/plugin/dynamic" + "github.com/containerd/plugin/registry" ) // CreateTopLevelDirectories creates the top-level root and state directories. @@ -341,9 +341,9 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) { // recordConfigDeprecations attempts to record use of any deprecated config field. Failures are logged and ignored. func recordConfigDeprecations(ctx context.Context, config *srvconfig.Config, set *plugin.Set) { // record any detected deprecations without blocking server startup - plugin, err := set.GetByID(plugins.WarningPlugin, plugins.DeprecationsPlugin) - if err != nil { - log.G(ctx).WithError(err).Warn("failed to load warning service to record deprecations") + plugin := set.Get(plugins.WarningPlugin, plugins.DeprecationsPlugin) + if plugin == nil { + log.G(ctx).Warn("failed to find warning service to record deprecations") return } instance, err := plugin.Instance() diff --git a/services/server/server_test.go b/services/server/server_test.go index 2aa923415917..b05e796cf233 100644 --- a/services/server/server_test.go +++ b/services/server/server_test.go @@ -20,9 +20,9 @@ import ( "context" "testing" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" srvconfig "github.com/containerd/containerd/v2/services/server/config" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" "github.com/stretchr/testify/assert" ) diff --git a/services/snapshots/service.go b/services/snapshots/service.go index fe44428ba2fe..83b8fd59abdb 100644 --- a/services/snapshots/service.go +++ b/services/snapshots/service.go @@ -18,18 +18,17 @@ package snapshots import ( "context" - "errors" snapshotsapi "github.com/containerd/containerd/v2/api/services/snapshots/v1" "github.com/containerd/containerd/v2/errdefs" "github.com/containerd/containerd/v2/mount" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" ptypes "github.com/containerd/containerd/v2/protobuf/types" "github.com/containerd/containerd/v2/services" "github.com/containerd/containerd/v2/snapshots" "github.com/containerd/log" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" "google.golang.org/grpc" ) @@ -52,20 +51,11 @@ type service struct { } func newService(ic *plugin.InitContext) (interface{}, error) { - sps, err := ic.GetByType(plugins.ServicePlugin) + i, err := ic.GetByID(plugins.ServicePlugin, services.SnapshotsService) if err != nil { return nil, err } - p, ok := sps[services.SnapshotsService] - if !ok { - return nil, errors.New("snapshots service not found") - } - i, err := p.Instance() - if err != nil { - return nil, err - } - ss := i.(map[string]snapshots.Snapshotter) - return &service{ss: ss}, nil + return &service{ss: i.(map[string]snapshots.Snapshotter)}, nil } func (s *service) getSnapshotter(name string) (snapshots.Snapshotter, error) { diff --git a/services/snapshots/snapshotters.go b/services/snapshots/snapshotters.go index fad274fb2289..ecc67d4aced3 100644 --- a/services/snapshots/snapshotters.go +++ b/services/snapshots/snapshotters.go @@ -18,10 +18,10 @@ package snapshots import ( "github.com/containerd/containerd/v2/metadata" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" "github.com/containerd/containerd/v2/services" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" ) func init() { @@ -32,7 +32,7 @@ func init() { plugins.MetadataPlugin, }, InitFn: func(ic *plugin.InitContext) (interface{}, error) { - m, err := ic.Get(plugins.MetadataPlugin) + m, err := ic.GetSingle(plugins.MetadataPlugin) if err != nil { return nil, err } diff --git a/services/streaming/service.go b/services/streaming/service.go index d72aec34271b..2ad20a788965 100644 --- a/services/streaming/service.go +++ b/services/streaming/service.go @@ -23,12 +23,12 @@ import ( api "github.com/containerd/containerd/v2/api/services/streaming/v1" "github.com/containerd/containerd/v2/errdefs" "github.com/containerd/containerd/v2/pkg/streaming" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" "github.com/containerd/containerd/v2/protobuf" ptypes "github.com/containerd/containerd/v2/protobuf/types" "github.com/containerd/log" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" "github.com/containerd/typeurl/v2" "google.golang.org/grpc" ) diff --git a/services/tasks/local.go b/services/tasks/local.go index cf7d9cb609ae..138f6d22830d 100644 --- a/services/tasks/local.go +++ b/services/tasks/local.go @@ -41,8 +41,6 @@ import ( "github.com/containerd/containerd/v2/pkg/blockio" "github.com/containerd/containerd/v2/pkg/rdt" "github.com/containerd/containerd/v2/pkg/timeout" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" "github.com/containerd/containerd/v2/protobuf" "github.com/containerd/containerd/v2/protobuf/proto" @@ -51,6 +49,8 @@ import ( "github.com/containerd/containerd/v2/runtime/v2/runc/options" "github.com/containerd/containerd/v2/services" "github.com/containerd/log" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" "github.com/containerd/typeurl/v2" "github.com/opencontainers/go-digest" ocispec "github.com/opencontainers/image-spec/specs-go/v1" @@ -96,17 +96,17 @@ func initFunc(ic *plugin.InitContext) (interface{}, error) { return nil, err } - m, err := ic.Get(plugins.MetadataPlugin) + m, err := ic.GetSingle(plugins.MetadataPlugin) if err != nil { return nil, err } - ep, err := ic.Get(plugins.EventPlugin) + ep, err := ic.GetSingle(plugins.EventPlugin) if err != nil { return nil, err } - monitor, err := ic.Get(plugins.TaskMonitorPlugin) + monitor, err := ic.GetSingle(plugins.TaskMonitorPlugin) if err != nil { if !errors.Is(err, plugin.ErrPluginNotFound) { return nil, err diff --git a/services/tasks/local_darwin.go b/services/tasks/local_darwin.go index 6061a9aca337..e3eeccc0a99d 100644 --- a/services/tasks/local_darwin.go +++ b/services/tasks/local_darwin.go @@ -19,8 +19,8 @@ package tasks import ( - "github.com/containerd/containerd/v2/plugin" "github.com/containerd/containerd/v2/plugins" + "github.com/containerd/plugin" ) var tasksServiceRequires = []plugin.Type{ diff --git a/services/tasks/local_freebsd.go b/services/tasks/local_freebsd.go index bfd40ee69948..d80be5c8a41c 100644 --- a/services/tasks/local_freebsd.go +++ b/services/tasks/local_freebsd.go @@ -17,8 +17,8 @@ package tasks import ( - "github.com/containerd/containerd/v2/plugin" "github.com/containerd/containerd/v2/plugins" + "github.com/containerd/plugin" ) var tasksServiceRequires = []plugin.Type{ diff --git a/services/tasks/local_unix.go b/services/tasks/local_unix.go index 720a4eace083..911cded00c5d 100644 --- a/services/tasks/local_unix.go +++ b/services/tasks/local_unix.go @@ -19,8 +19,8 @@ package tasks import ( - "github.com/containerd/containerd/v2/plugin" "github.com/containerd/containerd/v2/plugins" + "github.com/containerd/plugin" ) var tasksServiceRequires = []plugin.Type{ diff --git a/services/tasks/local_windows.go b/services/tasks/local_windows.go index bfd40ee69948..d80be5c8a41c 100644 --- a/services/tasks/local_windows.go +++ b/services/tasks/local_windows.go @@ -17,8 +17,8 @@ package tasks import ( - "github.com/containerd/containerd/v2/plugin" "github.com/containerd/containerd/v2/plugins" + "github.com/containerd/plugin" ) var tasksServiceRequires = []plugin.Type{ diff --git a/services/tasks/service.go b/services/tasks/service.go index d0a0149925d0..a601d06626cf 100644 --- a/services/tasks/service.go +++ b/services/tasks/service.go @@ -18,14 +18,13 @@ package tasks import ( "context" - "errors" api "github.com/containerd/containerd/v2/api/services/tasks/v1" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" ptypes "github.com/containerd/containerd/v2/protobuf/types" "github.com/containerd/containerd/v2/services" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" "google.golang.org/grpc" ) @@ -41,15 +40,7 @@ func init() { plugins.ServicePlugin, }, InitFn: func(ic *plugin.InitContext) (interface{}, error) { - sps, err := ic.GetByType(plugins.ServicePlugin) - if err != nil { - return nil, err - } - p, ok := sps[services.TasksService] - if !ok { - return nil, errors.New("tasks service not found") - } - i, err := p.Instance() + i, err := ic.GetByID(plugins.ServicePlugin, services.TasksService) if err != nil { return nil, err } diff --git a/services/transfer/service.go b/services/transfer/service.go index 28ff0388a104..a3e04e0f9246 100644 --- a/services/transfer/service.go +++ b/services/transfer/service.go @@ -25,11 +25,11 @@ import ( "github.com/containerd/containerd/v2/pkg/streaming" "github.com/containerd/containerd/v2/pkg/transfer" tplugins "github.com/containerd/containerd/v2/pkg/transfer/plugins" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" ptypes "github.com/containerd/containerd/v2/protobuf/types" "github.com/containerd/log" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" "github.com/containerd/typeurl/v2" "google.golang.org/grpc" "google.golang.org/grpc/codes" @@ -64,11 +64,7 @@ func newService(ic *plugin.InitContext) (interface{}, error) { // TODO: how to determine order? t := make([]transfer.Transferrer, 0, len(sps)) for _, p := range sps { - i, err := p.Instance() - if err != nil { - return nil, err - } - t = append(t, i.(transfer.Transferrer)) + t = append(t, p.(transfer.Transferrer)) } sp, err := ic.GetByID(plugins.StreamingPlugin, "manager") if err != nil { diff --git a/services/version/service.go b/services/version/service.go index 38453653c367..ad76faeddb10 100644 --- a/services/version/service.go +++ b/services/version/service.go @@ -20,11 +20,11 @@ import ( "context" api "github.com/containerd/containerd/v2/api/services/version/v1" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" ptypes "github.com/containerd/containerd/v2/protobuf/types" ctrdversion "github.com/containerd/containerd/v2/version" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" "google.golang.org/grpc" ) diff --git a/services/warning/service.go b/services/warning/service.go index eeb9398f2ba1..112c1c1d5b57 100644 --- a/services/warning/service.go +++ b/services/warning/service.go @@ -24,9 +24,9 @@ import ( "github.com/containerd/log" deprecation "github.com/containerd/containerd/v2/pkg/deprecation" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" ) type Service interface { diff --git a/snapshots/blockfile/blockfile.go b/snapshots/blockfile/blockfile.go index 4673217dab7f..fadf727b5fe9 100644 --- a/snapshots/blockfile/blockfile.go +++ b/snapshots/blockfile/blockfile.go @@ -25,11 +25,11 @@ import ( "runtime" "github.com/containerd/containerd/v2/mount" - "github.com/containerd/containerd/v2/plugin" "github.com/containerd/containerd/v2/snapshots" "github.com/containerd/containerd/v2/snapshots/storage" "github.com/containerd/continuity/fs" "github.com/containerd/log" + "github.com/containerd/plugin" ) // viewHookHelper is only used in test for recover the filesystem. diff --git a/snapshots/blockfile/plugin/plugin.go b/snapshots/blockfile/plugin/plugin.go index 42b7ad2e5c42..4d8194da4ba9 100644 --- a/snapshots/blockfile/plugin/plugin.go +++ b/snapshots/blockfile/plugin/plugin.go @@ -20,10 +20,10 @@ import ( "errors" "github.com/containerd/containerd/v2/platforms" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" "github.com/containerd/containerd/v2/snapshots/blockfile" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" ) // Config represents configuration for the native plugin. diff --git a/snapshots/btrfs/btrfs.go b/snapshots/btrfs/btrfs.go index f0ac4ac5342f..4478cfc3d297 100644 --- a/snapshots/btrfs/btrfs.go +++ b/snapshots/btrfs/btrfs.go @@ -29,10 +29,10 @@ import ( "github.com/containerd/continuity/fs" "github.com/containerd/containerd/v2/mount" - "github.com/containerd/containerd/v2/plugin" "github.com/containerd/containerd/v2/snapshots" "github.com/containerd/containerd/v2/snapshots/storage" "github.com/containerd/log" + "github.com/containerd/plugin" ) type snapshotter struct { diff --git a/snapshots/btrfs/btrfs_test.go b/snapshots/btrfs/btrfs_test.go index 55f8941f5871..efe3c52a92ba 100644 --- a/snapshots/btrfs/btrfs_test.go +++ b/snapshots/btrfs/btrfs_test.go @@ -31,10 +31,10 @@ import ( "github.com/containerd/containerd/v2/mount" "github.com/containerd/containerd/v2/pkg/testutil" - "github.com/containerd/containerd/v2/plugin" "github.com/containerd/containerd/v2/snapshots" "github.com/containerd/containerd/v2/snapshots/testsuite" "github.com/containerd/continuity/testutil/loopback" + "github.com/containerd/plugin" exec "golang.org/x/sys/execabs" "golang.org/x/sys/unix" ) diff --git a/snapshots/btrfs/plugin/plugin.go b/snapshots/btrfs/plugin/plugin.go index ef9bd4b2cdc0..7d0ee8cd9fd3 100644 --- a/snapshots/btrfs/plugin/plugin.go +++ b/snapshots/btrfs/plugin/plugin.go @@ -24,10 +24,10 @@ import ( ocispec "github.com/opencontainers/image-spec/specs-go/v1" "github.com/containerd/containerd/v2/platforms" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" "github.com/containerd/containerd/v2/snapshots/btrfs" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" ) // Config represents configuration for the btrfs plugin. diff --git a/snapshots/devmapper/plugin/plugin.go b/snapshots/devmapper/plugin/plugin.go index e1c0d8a0ad8f..b63782a63bcb 100644 --- a/snapshots/devmapper/plugin/plugin.go +++ b/snapshots/devmapper/plugin/plugin.go @@ -23,10 +23,10 @@ import ( "fmt" "github.com/containerd/containerd/v2/platforms" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" "github.com/containerd/containerd/v2/snapshots/devmapper" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" ) func init() { diff --git a/snapshots/lcow/lcow.go b/snapshots/lcow/lcow.go index c238145d8006..a3466bddbf64 100644 --- a/snapshots/lcow/lcow.go +++ b/snapshots/lcow/lcow.go @@ -36,13 +36,13 @@ import ( "github.com/Microsoft/hcsshim/pkg/go-runhcs" "github.com/containerd/containerd/v2/errdefs" "github.com/containerd/containerd/v2/mount" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" "github.com/containerd/containerd/v2/snapshots" "github.com/containerd/containerd/v2/snapshots/storage" "github.com/containerd/continuity/fs" "github.com/containerd/log" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" ocispec "github.com/opencontainers/image-spec/specs-go/v1" ) diff --git a/snapshots/native/plugin/plugin.go b/snapshots/native/plugin/plugin.go index 447d391b4f23..a2bb26f1dce0 100644 --- a/snapshots/native/plugin/plugin.go +++ b/snapshots/native/plugin/plugin.go @@ -20,10 +20,10 @@ import ( "errors" "github.com/containerd/containerd/v2/platforms" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" "github.com/containerd/containerd/v2/snapshots/native" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" ) // Config represents configuration for the native plugin. diff --git a/snapshots/overlay/plugin/plugin.go b/snapshots/overlay/plugin/plugin.go index 3e61965b4364..07c1fc845784 100644 --- a/snapshots/overlay/plugin/plugin.go +++ b/snapshots/overlay/plugin/plugin.go @@ -22,11 +22,11 @@ import ( "errors" "github.com/containerd/containerd/v2/platforms" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" "github.com/containerd/containerd/v2/snapshots/overlay" "github.com/containerd/containerd/v2/snapshots/overlay/overlayutils" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" ) const ( diff --git a/snapshots/windows/windows.go b/snapshots/windows/windows.go index 586fd2f84e8c..35a7aacda6cd 100644 --- a/snapshots/windows/windows.go +++ b/snapshots/windows/windows.go @@ -37,13 +37,13 @@ import ( "github.com/containerd/containerd/v2/errdefs" "github.com/containerd/containerd/v2/mount" "github.com/containerd/containerd/v2/platforms" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" "github.com/containerd/containerd/v2/snapshots" "github.com/containerd/containerd/v2/snapshots/storage" "github.com/containerd/continuity/fs" "github.com/containerd/log" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" ocispec "github.com/opencontainers/image-spec/specs-go/v1" ) diff --git a/tracing/plugin/otlp.go b/tracing/plugin/otlp.go index 33211bc02c1a..37e25b63af11 100644 --- a/tracing/plugin/otlp.go +++ b/tracing/plugin/otlp.go @@ -24,11 +24,10 @@ import ( "time" "github.com/containerd/containerd/v2/errdefs" - "github.com/containerd/containerd/v2/plugin" - "github.com/containerd/containerd/v2/plugin/registry" "github.com/containerd/containerd/v2/plugins" "github.com/containerd/containerd/v2/tracing" - "github.com/containerd/log" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" "github.com/sirupsen/logrus" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/exporters/otlp/otlptrace" @@ -73,18 +72,8 @@ func init() { return nil, fmt.Errorf("failed to get tracing processors: %w", err) } procs := make([]trace.SpanProcessor, 0, len(plugins)) - for id, pctx := range plugins { - p, err := pctx.Instance() - if err != nil { - if plugin.IsSkipPlugin(err) { - log.G(ic.Context).WithError(err).Infof("skipping tracing processor initialization (no tracing plugin)") - } else { - log.G(ic.Context).WithError(err).Errorf("failed to initialize a tracing processor %q", id) - } - continue - } - proc := p.(trace.SpanProcessor) - procs = append(procs, proc) + for _, p := range plugins { + procs = append(procs, p.(trace.SpanProcessor)) } return newTracer(ic.Context, ic.Config.(*TraceConfig), procs) }, diff --git a/vendor/github.com/containerd/plugin/.golangci.yml b/vendor/github.com/containerd/plugin/.golangci.yml new file mode 100644 index 000000000000..a695775df49d --- /dev/null +++ b/vendor/github.com/containerd/plugin/.golangci.yml @@ -0,0 +1,30 @@ +linters: + enable: + - exportloopref # Checks for pointers to enclosing loop variables + - gofmt + - goimports + - gosec + - ineffassign + - misspell + - nolintlint + - revive + - staticcheck + - tenv # Detects using os.Setenv instead of t.Setenv since Go 1.17 + - unconvert + - unused + - vet + - dupword # Checks for duplicate words in the source code + disable: + - errcheck + +run: + timeout: 5m + skip-dirs: + - api + - cluster + - design + - docs + - docs/man + - releases + - reports + - test # e2e scripts diff --git a/vendor/github.com/containerd/plugin/LICENSE b/vendor/github.com/containerd/plugin/LICENSE new file mode 100644 index 000000000000..584149b6ee28 --- /dev/null +++ b/vendor/github.com/containerd/plugin/LICENSE @@ -0,0 +1,191 @@ + + Apache License + Version 2.0, January 2004 + https://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + 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 + + https://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. diff --git a/vendor/github.com/containerd/plugin/README.md b/vendor/github.com/containerd/plugin/README.md new file mode 100644 index 000000000000..eb1684f68a57 --- /dev/null +++ b/vendor/github.com/containerd/plugin/README.md @@ -0,0 +1,19 @@ +# plugin + +A Go package providing a common plugin interface across containerd repositories. + +This package is intended to be imported by the main containerd repository as well as plugin implementations. +By sharing a common implementations, plugins can register themselves without needing to import the main containerd repository. +This plugin is intended to provide an interface and common functionality, but is not intended to define plugin types used by containerd. +Plugins should copy plugin type strings to avoid creating unintended depdenencies. + +## Project details + +**plugin** is a containerd sub-project, licensed under the [Apache 2.0 license](./LICENSE). +As a containerd sub-project, you will find the: + * [Project governance](https://github.com/containerd/project/blob/main/GOVERNANCE.md), + * [Maintainers](https://github.com/containerd/project/blob/main/MAINTAINERS), + * and [Contributing guidelines](https://github.com/containerd/project/blob/main/CONTRIBUTING.md) + +information in our [`containerd/project`](https://github.com/containerd/project) repository. + diff --git a/vendor/github.com/containerd/plugin/context.go b/vendor/github.com/containerd/plugin/context.go new file mode 100644 index 000000000000..3b985ab75eb8 --- /dev/null +++ b/vendor/github.com/containerd/plugin/context.go @@ -0,0 +1,199 @@ +/* + 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 plugin + +import ( + "context" + "fmt" + + imagespec "github.com/opencontainers/image-spec/specs-go/v1" +) + +// InitContext is used for plugin initialization +type InitContext struct { + Context context.Context + Properties map[string]string + Config interface{} + RegisterReadiness func() func() + + // Meta is metadata plugins can fill in at init + Meta *Meta + + plugins *Set +} + +// NewContext returns a new plugin InitContext +func NewContext(ctx context.Context, plugins *Set, properties map[string]string) *InitContext { + if properties == nil { + properties = map[string]string{} + } + return &InitContext{ + Context: ctx, + Properties: properties, + Meta: &Meta{ + Exports: map[string]string{}, + }, + plugins: plugins, + } +} + +// Meta contains information gathered from the registration and initialization +// process. +type Meta struct { + Platforms []imagespec.Platform // platforms supported by plugin + Exports map[string]string // values exported by plugin + Capabilities []string // feature switches for plugin +} + +// Plugin represents an initialized plugin, used with an init context. +type Plugin struct { + Registration Registration // registration, as initialized + Config interface{} // config, as initialized + Meta Meta + + instance interface{} + err error // will be set if there was an error initializing the plugin +} + +// Err returns the errors during initialization. +// returns nil if no error was encountered +func (p *Plugin) Err() error { + return p.err +} + +// Instance returns the instance and any initialization error of the plugin +func (p *Plugin) Instance() (interface{}, error) { + return p.instance, p.err +} + +// Set defines a plugin collection, used with InitContext. +// +// This maintains ordering and unique indexing over the set. +// +// After iteratively instantiating plugins, this set should represent, the +// ordered, initialization set of plugins for a containerd instance. +type Set struct { + ordered []*Plugin // order of initialization + byTypeAndID map[Type]map[string]*Plugin +} + +// NewPluginSet returns an initialized plugin set +func NewPluginSet() *Set { + return &Set{ + byTypeAndID: make(map[Type]map[string]*Plugin), + } +} + +// Add a plugin to the set +func (ps *Set) Add(p *Plugin) error { + if byID, typeok := ps.byTypeAndID[p.Registration.Type]; !typeok { + ps.byTypeAndID[p.Registration.Type] = map[string]*Plugin{ + p.Registration.ID: p, + } + } else if _, idok := byID[p.Registration.ID]; !idok { + byID[p.Registration.ID] = p + } else { + return fmt.Errorf("plugin add failed for %s: %w", p.Registration.URI(), ErrPluginInitialized) + } + + ps.ordered = append(ps.ordered, p) + return nil +} + +// Get returns the plugin with the given type and id +func (ps *Set) Get(t Type, id string) *Plugin { + p, ok := ps.byTypeAndID[t] + if !ok { + return nil + } + return p[id] +} + +// GetAll returns all initialized plugins +func (ps *Set) GetAll() []*Plugin { + return ps.ordered +} + +// GetSingle returns a plugin instance of the given type when only a single instance +// of that type is expected. Throws an ErrPluginNotFound if no plugin is found and +// ErrPluginMultipleInstances when multiple instances are found. +// Since plugins are not ordered, if multiple instances is suported then +// GetByType should be used. If only one is expected, then to switch plugins, +// disable or remove the unused plugins of the same type. +func (i *InitContext) GetSingle(t Type) (interface{}, error) { + var ( + found bool + instance interface{} + ) + for _, v := range i.plugins.byTypeAndID[t] { + i, err := v.Instance() + if err != nil { + if IsSkipPlugin(err) { + continue + } + return i, err + } + if found { + return nil, fmt.Errorf("multiple plugins registered for %s: %w", t, ErrPluginMultipleInstances) + } + instance = i + found = true + } + if !found { + return nil, fmt.Errorf("no plugins registered for %s: %w", t, ErrPluginNotFound) + } + return instance, nil +} + +// Plugins returns plugin set +func (i *InitContext) Plugins() *Set { + return i.plugins +} + +// GetAll plugins in the set +func (i *InitContext) GetAll() []*Plugin { + return i.plugins.GetAll() +} + +// GetByID returns the plugin of the given type and ID +func (i *InitContext) GetByID(t Type, id string) (interface{}, error) { + p := i.plugins.Get(t, id) + if p == nil { + return nil, fmt.Errorf("no plugins registered for %s.%s: %w", t, id, ErrPluginNotFound) + } + return p.Instance() +} + +// GetByType returns all plugins with the specific type. +func (i *InitContext) GetByType(t Type) (map[string]interface{}, error) { + pi := map[string]interface{}{} + for id, p := range i.plugins.byTypeAndID[t] { + i, err := p.Instance() + if err != nil { + if IsSkipPlugin(err) { + continue + } + return nil, err + } + pi[id] = i + } + if len(pi) == 0 { + return nil, fmt.Errorf("no plugins registered for %s: %w", t, ErrPluginNotFound) + } + + return pi, nil +} diff --git a/vendor/github.com/containerd/plugin/dynamic/dynamic.go b/vendor/github.com/containerd/plugin/dynamic/dynamic.go new file mode 100644 index 000000000000..653b757400ba --- /dev/null +++ b/vendor/github.com/containerd/plugin/dynamic/dynamic.go @@ -0,0 +1,37 @@ +/* + 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 dynamic + +import "fmt" + +// Load loads all plugins at the provided path into containerd. +// +// Load is currently only implemented on non-static, non-gccgo builds for amd64 +// and arm64, and plugins must be built with the exact same version of Go as +// containerd itself. +func Load(path string) (loaded int, err error) { + defer func() { + if v := recover(); v != nil { + rerr, ok := v.(error) + if !ok { + rerr = fmt.Errorf("%s", v) + } + err = rerr + } + }() + return loadPlugins(path) +} diff --git a/vendor/github.com/containerd/plugin/dynamic/dynamic_supported.go b/vendor/github.com/containerd/plugin/dynamic/dynamic_supported.go new file mode 100644 index 000000000000..5c77f0a53bf3 --- /dev/null +++ b/vendor/github.com/containerd/plugin/dynamic/dynamic_supported.go @@ -0,0 +1,64 @@ +//go:build (amd64 || arm64) && !static_build && !gccgo + +/* + 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 dynamic + +import ( + "fmt" + "path/filepath" + "plugin" + "runtime" +) + +// loadPlugins loads all plugins for the OS and Arch +// that containerd is built for inside the provided path +func loadPlugins(path string) (int, error) { + abs, err := filepath.Abs(path) + if err != nil { + return 0, err + } + pattern := filepath.Join(abs, fmt.Sprintf( + "*-%s-%s.%s", + runtime.GOOS, + runtime.GOARCH, + getLibExt(), + )) + libs, err := filepath.Glob(pattern) + if err != nil { + return 0, err + } + loaded := 0 + for _, lib := range libs { + if _, err := plugin.Open(lib); err != nil { + return loaded, err + } + loaded++ + } + return loaded, nil +} + +// getLibExt returns a platform specific lib extension for +// the platform that containerd is running on +func getLibExt() string { + switch runtime.GOOS { + case "windows": + return "dll" + default: + return "so" + } +} diff --git a/vendor/github.com/containerd/plugin/dynamic/dynamic_unsupported.go b/vendor/github.com/containerd/plugin/dynamic/dynamic_unsupported.go new file mode 100644 index 000000000000..556569407c04 --- /dev/null +++ b/vendor/github.com/containerd/plugin/dynamic/dynamic_unsupported.go @@ -0,0 +1,28 @@ +//go:build (!amd64 && !arm64) || static_build || gccgo + +/* + 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 dynamic + +// loadPlugins is not supported; +// +// - with gccgo: gccgo has no plugin support golang/go#36403 +// - on static builds; https://github.com/containerd/containerd/commit/0d682e24a1ba8e93e5e54a73d64f7d256f87492f +// - on architectures other than amd64 and arm64 (other architectures need to be tested) +func loadPlugins(path string) (int, error) { + return 0, nil +} diff --git a/vendor/github.com/containerd/plugin/plugin.go b/vendor/github.com/containerd/plugin/plugin.go new file mode 100644 index 000000000000..f7899e184f31 --- /dev/null +++ b/vendor/github.com/containerd/plugin/plugin.go @@ -0,0 +1,178 @@ +/* + 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 plugin + +import ( + "context" + "errors" + "fmt" +) + +var ( + // ErrNoType is returned when no type is specified + ErrNoType = errors.New("plugin: no type") + // ErrNoPluginID is returned when no id is specified + ErrNoPluginID = errors.New("plugin: no id") + // ErrIDRegistered is returned when a duplicate id is already registered + ErrIDRegistered = errors.New("plugin: id already registered") + // ErrSkipPlugin is used when a plugin is not initialized and should not be loaded, + // this allows the plugin loader differentiate between a plugin which is configured + // not to load and one that fails to load. + ErrSkipPlugin = errors.New("skip plugin") + // ErrPluginInitialized is used when a plugin is already initialized + ErrPluginInitialized = errors.New("plugin: already initialized") + // ErrPluginNotFound is used when a plugin is looked up but not found + ErrPluginNotFound = errors.New("plugin: not found") + // ErrPluginMultipleInstances is used when a plugin is expected a single instance but has multiple + ErrPluginMultipleInstances = errors.New("plugin: multiple instances") + + // ErrInvalidRequires will be thrown if the requirements for a plugin are + // defined in an invalid manner. + ErrInvalidRequires = errors.New("invalid requires") +) + +// IsSkipPlugin returns true if the error is skipping the plugin +func IsSkipPlugin(err error) bool { + return errors.Is(err, ErrSkipPlugin) +} + +// Type is the type of the plugin +type Type string + +func (t Type) String() string { return string(t) } + +// Registration contains information for registering a plugin +type Registration struct { + // Type of the plugin + Type Type + // ID of the plugin + ID string + // Config specific to the plugin + Config interface{} + // Requires is a list of plugins that the registered plugin requires to be available + Requires []Type + + // InitFn is called when initializing a plugin. The registration and + // context are passed in. The init function may modify the registration to + // add exports, capabilities and platform support declarations. + InitFn func(*InitContext) (interface{}, error) + + // ConfigMigration allows a plugin to migrate configurations from an older + // version to handle plugin renames or moving of features from one plugin + // to another in a later version. + // The configuration map is keyed off the plugin name and the value + // is the configuration for that objects, with the structure defined + // for the plugin. No validation is done on the value before performing + // the migration. + ConfigMigration func(context.Context, int, map[string]interface{}) error +} + +// Init the registered plugin +func (r Registration) Init(ic *InitContext) *Plugin { + p, err := r.InitFn(ic) + return &Plugin{ + Registration: r, + Config: ic.Config, + Meta: *ic.Meta, + instance: p, + err: err, + } +} + +// URI returns the full plugin URI +func (r *Registration) URI() string { + return r.Type.String() + "." + r.ID +} + +// DisableFilter filters out disabled plugins +type DisableFilter func(r *Registration) bool + +// Registry is list of registrations which can be registered to and +// produce a filtered and ordered output. +// The Registry itself is immutable and the list will be copied +// and appeneded to a new registry when new items are registered. +type Registry []*Registration + +// Graph computes the ordered list of registrations based on their dependencies, +// filtering out any plugins which match the provided filter. +func (registry Registry) Graph(filter DisableFilter) []Registration { + disabled := map[*Registration]bool{} + for _, r := range registry { + if filter(r) { + disabled[r] = true + } + } + + ordered := make([]Registration, 0, len(registry)-len(disabled)) + added := map[*Registration]bool{} + for _, r := range registry { + if disabled[r] { + continue + } + children(r, registry, added, disabled, &ordered) + if !added[r] { + ordered = append(ordered, *r) + added[r] = true + } + } + return ordered +} + +func children(reg *Registration, registry []*Registration, added, disabled map[*Registration]bool, ordered *[]Registration) { + for _, t := range reg.Requires { + for _, r := range registry { + if !disabled[r] && r.URI() != reg.URI() && (t == "*" || r.Type == t) { + children(r, registry, added, disabled, ordered) + if !added[r] { + *ordered = append(*ordered, *r) + added[r] = true + } + } + } + } +} + +// Register adds the registration to a Registry and returns the +// updated Registry, panicking if registration could not succeed. +func (registry Registry) Register(r *Registration) Registry { + if r.Type == "" { + panic(ErrNoType) + } + if r.ID == "" { + panic(ErrNoPluginID) + } + if err := checkUnique(registry, r); err != nil { + panic(err) + } + + for _, requires := range r.Requires { + if requires == "*" && len(r.Requires) != 1 { + panic(ErrInvalidRequires) + } + } + + return append(registry, r) +} + +func checkUnique(registry Registry, r *Registration) error { + for _, registered := range registry { + if r.URI() == registered.URI() { + return fmt.Errorf("%s: %w", r.URI(), ErrIDRegistered) + } + } + return nil +} diff --git a/vendor/github.com/containerd/plugin/registry/register.go b/vendor/github.com/containerd/plugin/registry/register.go new file mode 100644 index 000000000000..57bb201bfc35 --- /dev/null +++ b/vendor/github.com/containerd/plugin/registry/register.go @@ -0,0 +1,50 @@ +/* + 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 registry + +import ( + "sync" + + "github.com/containerd/plugin" +) + +var register = struct { + sync.RWMutex + r plugin.Registry +}{} + +// Register allows plugins to register +func Register(r *plugin.Registration) { + register.Lock() + defer register.Unlock() + register.r = register.r.Register(r) +} + +// Reset removes all global registrations +func Reset() { + register.Lock() + defer register.Unlock() + register.r = nil +} + +// Graph returns an ordered list of registered plugins for initialization. +// Plugins in disableList specified by id will be disabled. +func Graph(filter plugin.DisableFilter) []plugin.Registration { + register.RLock() + defer register.RUnlock() + return register.r.Graph(filter) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 62469ac33bc3..1ca20bd8d596 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -142,6 +142,11 @@ github.com/containerd/nri/pkg/net/multiplex github.com/containerd/nri/pkg/runtime-tools/generate github.com/containerd/nri/pkg/stub github.com/containerd/nri/types/v1 +# github.com/containerd/plugin v0.0.0-20231101173250-7ec69893e1e7 +## explicit; go 1.20 +github.com/containerd/plugin +github.com/containerd/plugin/dynamic +github.com/containerd/plugin/registry # github.com/containerd/ttrpc v1.2.2 ## explicit; go 1.13 github.com/containerd/ttrpc