Skip to content

Commit 079383d

Browse files
committed
dynamic: record deprecation for dynamic plugins
Signed-off-by: Samuel Karp <[email protected]>
1 parent 260e71a commit 079383d

File tree

5 files changed

+22
-24
lines changed

5 files changed

+22
-24
lines changed

plugin/dynamic/dynamic.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import "fmt"
2323
// Load is currently only implemented on non-static, non-gccgo builds for amd64
2424
// and arm64, and plugins must be built with the exact same version of Go as
2525
// containerd itself.
26-
func Load(path string) (err error) {
26+
func Load(path string) (loaded int, err error) {
2727
defer func() {
2828
if v := recover(); v != nil {
2929
rerr, ok := v.(error)

plugin/dynamic/dynamic_supported.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ import (
2525
"runtime"
2626
)
2727

28-
// loadPlugins loads all plugins for the OS and Arch
29-
// that containerd is built for inside the provided path
30-
func loadPlugins(path string) error {
28+
// loadPlugins loads all plugins for the OS and Arch that containerd is built
29+
// for inside the provided path and returns the count of successfully-loaded
30+
// plugins
31+
func loadPlugins(path string) (int, error) {
3132
abs, err := filepath.Abs(path)
3233
if err != nil {
33-
return err
34+
return 0, err
3435
}
3536
pattern := filepath.Join(abs, fmt.Sprintf(
3637
"*-%s-%s.%s",
@@ -40,14 +41,16 @@ func loadPlugins(path string) error {
4041
))
4142
libs, err := filepath.Glob(pattern)
4243
if err != nil {
43-
return err
44+
return 0, err
4445
}
46+
loaded := 0
4547
for _, lib := range libs {
4648
if _, err := plugin.Open(lib); err != nil {
47-
return err
49+
return loaded, err
4850
}
51+
loaded++
4952
}
50-
return nil
53+
return loaded, nil
5154
}
5255

5356
// getLibExt returns a platform specific lib extension for

plugin/dynamic/dynamic_unsupported.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ package dynamic
2323
// - with gccgo: gccgo has no plugin support golang/go#36403
2424
// - on static builds; https://github.com/containerd/containerd/commit/0d682e24a1ba8e93e5e54a73d64f7d256f87492f
2525
// - on architectures other than amd64 and arm64 (other architectures need to be tested)
26-
func loadPlugins(path string) error {
27-
return nil
26+
func loadPlugins(path string) (int, error) {
27+
return 0, nil
2828
}

services/server/server.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import (
5555
"github.com/containerd/containerd/defaults"
5656
"github.com/containerd/containerd/diff"
5757
diffproxy "github.com/containerd/containerd/diff/proxy"
58+
"github.com/containerd/containerd/pkg/deprecation"
5859
"github.com/containerd/containerd/pkg/dialer"
5960
"github.com/containerd/containerd/pkg/timeout"
6061
"github.com/containerd/containerd/platforms"
@@ -356,7 +357,9 @@ func recordConfigDeprecations(ctx context.Context, config *srvconfig.Config, set
356357
return
357358
}
358359

359-
_ = warn // TODO(samuelkarp): placeholder for future use
360+
if config.PluginDir != "" { //nolint:staticcheck
361+
warn.Emit(ctx, deprecation.GoPluginLibrary)
362+
}
360363
}
361364

362365
// Server is the containerd main daemon
@@ -459,13 +462,15 @@ func (s *Server) Wait() {
459462
// of all plugins.
460463
func LoadPlugins(ctx context.Context, config *srvconfig.Config) ([]plugin.Registration, error) {
461464
// load all plugins into containerd
462-
path := config.PluginDir // nolint: staticcheck
465+
path := config.PluginDir //nolint:staticcheck
463466
if path == "" {
464467
path = filepath.Join(config.Root, "plugins")
465468
}
466-
log.G(ctx).Warning("`go_plugin` is deprecated, please use `external plugins` instead")
467-
if err := dynamic.Load(path); err != nil {
469+
if count, err := dynamic.Load(path); err != nil {
468470
return nil, err
471+
} else if count > 0 || config.PluginDir != "" { //nolint:staticcheck
472+
config.PluginDir = path //nolint:staticcheck
473+
log.G(ctx).Warningf("loaded %d dynamic plugins. `go_plugin` is deprecated, please use `external plugins` instead", count)
469474
}
470475
// load additional plugins that don't automatically register themselves
471476
registry.Register(&plugin.Registration{

services/warning/service.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,6 @@ type Warning struct {
5252

5353
var _ Service = (*service)(nil)
5454

55-
func init() {
56-
registry.Register(&plugin.Registration{
57-
Type: plugins.InternalPlugin,
58-
ID: "warning",
59-
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
60-
return &service{warnings: make(map[deprecation.Warning]time.Time)}, nil
61-
},
62-
})
63-
}
64-
6555
type service struct {
6656
warnings map[deprecation.Warning]time.Time
6757
m sync.RWMutex

0 commit comments

Comments
 (0)