From 71f8b4357ee2f7c615bffabc8f7ca3bc2fa72692 Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Thu, 12 Oct 2023 15:37:26 -0700 Subject: [PATCH] Move dynamic plugins to a subpackage Signed-off-by: Derek McGowan --- plugin/dynamic/dynamic.go | 37 +++++++++++++++++++ .../dynamic_supported.go} | 2 +- .../dynamic_unsupported.go} | 2 +- plugin/plugin.go | 18 --------- services/server/server.go | 3 +- 5 files changed, 41 insertions(+), 21 deletions(-) create mode 100644 plugin/dynamic/dynamic.go rename plugin/{plugin_supported.go => dynamic/dynamic_supported.go} (98%) rename plugin/{plugin_unsupported.go => dynamic/dynamic_unsupported.go} (98%) diff --git a/plugin/dynamic/dynamic.go b/plugin/dynamic/dynamic.go new file mode 100644 index 000000000..30b4423a1 --- /dev/null +++ b/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) (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/plugin/plugin_supported.go b/plugin/dynamic/dynamic_supported.go similarity index 98% rename from plugin/plugin_supported.go rename to plugin/dynamic/dynamic_supported.go index 0eaf47064..eff7e597f 100644 --- a/plugin/plugin_supported.go +++ b/plugin/dynamic/dynamic_supported.go @@ -16,7 +16,7 @@ limitations under the License. */ -package plugin +package dynamic import ( "fmt" diff --git a/plugin/plugin_unsupported.go b/plugin/dynamic/dynamic_unsupported.go similarity index 98% rename from plugin/plugin_unsupported.go rename to plugin/dynamic/dynamic_unsupported.go index b250be357..ccef3d37f 100644 --- a/plugin/plugin_unsupported.go +++ b/plugin/dynamic/dynamic_unsupported.go @@ -16,7 +16,7 @@ limitations under the License. */ -package plugin +package dynamic // loadPlugins is not supported; // diff --git a/plugin/plugin.go b/plugin/plugin.go index 0a2d2dec6..d68c5013a 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -96,24 +96,6 @@ func (r *Registration) URI() string { return r.Type.String() + "." + r.ID } -// 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) (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) -} - // DisableFilter filters out disabled plugins type DisableFilter func(r *Registration) bool diff --git a/services/server/server.go b/services/server/server.go index faa0a1a45..4f5a6976d 100644 --- a/services/server/server.go +++ b/services/server/server.go @@ -46,6 +46,7 @@ import ( "github.com/containerd/containerd/pkg/timeout" "github.com/containerd/containerd/platforms" "github.com/containerd/containerd/plugin" + "github.com/containerd/containerd/plugin/dynamic" "github.com/containerd/containerd/plugin/registry" "github.com/containerd/containerd/plugins" srvconfig "github.com/containerd/containerd/services/server/config" @@ -434,7 +435,7 @@ func LoadPlugins(ctx context.Context, config *srvconfig.Config) ([]plugin.Regist if path == "" { path = filepath.Join(config.Root, "plugins") } - if err := plugin.Load(path); err != nil { + if err := dynamic.Load(path); err != nil { return nil, err } // load additional plugins that don't automatically register themselves