From 079383dbec05fb07e506b31ff68c1589b6fba0ba Mon Sep 17 00:00:00 2001 From: Samuel Karp Date: Tue, 17 Oct 2023 23:36:43 -0700 Subject: [PATCH] dynamic: record deprecation for dynamic plugins Signed-off-by: Samuel Karp --- plugin/dynamic/dynamic.go | 2 +- plugin/dynamic/dynamic_supported.go | 17 ++++++++++------- plugin/dynamic/dynamic_unsupported.go | 4 ++-- services/server/server.go | 13 +++++++++---- services/warning/service.go | 10 ---------- 5 files changed, 22 insertions(+), 24 deletions(-) diff --git a/plugin/dynamic/dynamic.go b/plugin/dynamic/dynamic.go index 30b4423a1..653b75740 100644 --- a/plugin/dynamic/dynamic.go +++ b/plugin/dynamic/dynamic.go @@ -23,7 +23,7 @@ import "fmt" // 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) { +func Load(path string) (loaded int, err error) { defer func() { if v := recover(); v != nil { rerr, ok := v.(error) diff --git a/plugin/dynamic/dynamic_supported.go b/plugin/dynamic/dynamic_supported.go index eff7e597f..0308ac9b5 100644 --- a/plugin/dynamic/dynamic_supported.go +++ b/plugin/dynamic/dynamic_supported.go @@ -25,12 +25,13 @@ import ( "runtime" ) -// loadPlugins loads all plugins for the OS and Arch -// that containerd is built for inside the provided path -func loadPlugins(path string) error { +// loadPlugins loads all plugins for the OS and Arch that containerd is built +// for inside the provided path and returns the count of successfully-loaded +// plugins +func loadPlugins(path string) (int, error) { abs, err := filepath.Abs(path) if err != nil { - return err + return 0, err } pattern := filepath.Join(abs, fmt.Sprintf( "*-%s-%s.%s", @@ -40,14 +41,16 @@ func loadPlugins(path string) error { )) libs, err := filepath.Glob(pattern) if err != nil { - return err + return 0, err } + loaded := 0 for _, lib := range libs { if _, err := plugin.Open(lib); err != nil { - return err + return loaded, err } + loaded++ } - return nil + return loaded, nil } // getLibExt returns a platform specific lib extension for diff --git a/plugin/dynamic/dynamic_unsupported.go b/plugin/dynamic/dynamic_unsupported.go index ccef3d37f..556569407 100644 --- a/plugin/dynamic/dynamic_unsupported.go +++ b/plugin/dynamic/dynamic_unsupported.go @@ -23,6 +23,6 @@ package dynamic // - 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) error { - return nil +func loadPlugins(path string) (int, error) { + return 0, nil } diff --git a/services/server/server.go b/services/server/server.go index 3b7f65526..75919a622 100644 --- a/services/server/server.go +++ b/services/server/server.go @@ -55,6 +55,7 @@ import ( "github.com/containerd/containerd/defaults" "github.com/containerd/containerd/diff" diffproxy "github.com/containerd/containerd/diff/proxy" + "github.com/containerd/containerd/pkg/deprecation" "github.com/containerd/containerd/pkg/dialer" "github.com/containerd/containerd/pkg/timeout" "github.com/containerd/containerd/platforms" @@ -356,7 +357,9 @@ func recordConfigDeprecations(ctx context.Context, config *srvconfig.Config, set return } - _ = warn // TODO(samuelkarp): placeholder for future use + if config.PluginDir != "" { //nolint:staticcheck + warn.Emit(ctx, deprecation.GoPluginLibrary) + } } // Server is the containerd main daemon @@ -459,13 +462,15 @@ func (s *Server) Wait() { // of all plugins. func LoadPlugins(ctx context.Context, config *srvconfig.Config) ([]plugin.Registration, error) { // load all plugins into containerd - path := config.PluginDir // nolint: staticcheck + path := config.PluginDir //nolint:staticcheck if path == "" { path = filepath.Join(config.Root, "plugins") } - log.G(ctx).Warning("`go_plugin` is deprecated, please use `external plugins` instead") - if err := dynamic.Load(path); err != nil { + if count, err := dynamic.Load(path); err != nil { return nil, err + } else if count > 0 || config.PluginDir != "" { //nolint:staticcheck + config.PluginDir = path //nolint:staticcheck + log.G(ctx).Warningf("loaded %d dynamic plugins. `go_plugin` is deprecated, please use `external plugins` instead", count) } // load additional plugins that don't automatically register themselves registry.Register(&plugin.Registration{ diff --git a/services/warning/service.go b/services/warning/service.go index dc35bc423..f5bb19498 100644 --- a/services/warning/service.go +++ b/services/warning/service.go @@ -52,16 +52,6 @@ type Warning struct { var _ Service = (*service)(nil) -func init() { - registry.Register(&plugin.Registration{ - Type: plugins.InternalPlugin, - ID: "warning", - InitFn: func(ic *plugin.InitContext) (interface{}, error) { - return &service{warnings: make(map[deprecation.Warning]time.Time)}, nil - }, - }) -} - type service struct { warnings map[deprecation.Warning]time.Time m sync.RWMutex