Skip to content

Commit 24068b8

Browse files
committed
dynamic: record deprecation for dynamic plugins
Signed-off-by: Samuel Karp <[email protected]> (cherry picked from commit 079383d) Signed-off-by: Samuel Karp <[email protected]>
1 parent 218c7a1 commit 24068b8

4 files changed

Lines changed: 21 additions & 12 deletions

File tree

plugin/plugin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ var register = struct {
134134
}{}
135135

136136
// Load loads all plugins at the provided path into containerd
137-
func Load(path string) (err error) {
137+
func Load(path string) (count int, err error) {
138138
defer func() {
139139
if v := recover(); v != nil {
140140
rerr, ok := v.(error)

plugin/plugin_go18.go

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

29-
// loadPlugins loads all plugins for the OS and Arch
30-
// that containerd is built for inside the provided path
31-
func loadPlugins(path string) error {
29+
// loadPlugins loads all plugins for the OS and Arch that containerd is built
30+
// for inside the provided path and returns the count of successfully-loaded
31+
// plugins
32+
func loadPlugins(path string) (int, error) {
3233
abs, err := filepath.Abs(path)
3334
if err != nil {
34-
return err
35+
return 0, err
3536
}
3637
pattern := filepath.Join(abs, fmt.Sprintf(
3738
"*-%s-%s.%s",
@@ -41,14 +42,16 @@ func loadPlugins(path string) error {
4142
))
4243
libs, err := filepath.Glob(pattern)
4344
if err != nil {
44-
return err
45+
return 0, err
4546
}
47+
loaded := 0
4648
for _, lib := range libs {
4749
if _, err := plugin.Open(lib); err != nil {
48-
return err
50+
return loaded, err
4951
}
52+
loaded++
5053
}
51-
return nil
54+
return loaded, nil
5255
}
5356

5457
// getLibExt returns a platform specific lib extension for

plugin/plugin_other.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
package plugin
2121

22-
func loadPlugins(path string) error {
22+
func loadPlugins(path string) (int, error) {
2323
// plugins not supported until 1.8
24-
return nil
24+
return 0, nil
2525
}

services/server/server.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import (
5656
"github.com/containerd/containerd/events/exchange"
5757
"github.com/containerd/containerd/log"
5858
"github.com/containerd/containerd/metadata"
59+
"github.com/containerd/containerd/pkg/deprecation"
5960
"github.com/containerd/containerd/pkg/dialer"
6061
"github.com/containerd/containerd/pkg/timeout"
6162
"github.com/containerd/containerd/plugin"
@@ -332,7 +333,9 @@ func recordConfigDeprecations(ctx context.Context, config *srvconfig.Config, set
332333
return
333334
}
334335

335-
_ = warn // TODO(samuelkarp): placeholder for future use
336+
if config.PluginDir != "" {
337+
warn.Emit(ctx, deprecation.GoPluginLibrary)
338+
}
336339
}
337340

338341
// Server is the containerd main daemon
@@ -439,8 +442,11 @@ func LoadPlugins(ctx context.Context, config *srvconfig.Config) ([]*plugin.Regis
439442
if path == "" {
440443
path = filepath.Join(config.Root, "plugins")
441444
}
442-
if err := plugin.Load(path); err != nil {
445+
if count, err := plugin.Load(path); err != nil {
443446
return nil, err
447+
} else if count > 0 || config.PluginDir != "" {
448+
config.PluginDir = path
449+
log.G(ctx).Warningf("loaded %d dynamic plugins. `go_plugin` is deprecated, please use `external plugins` instead", count)
444450
}
445451
// load additional plugins that don't automatically register themselves
446452
plugin.Register(&plugin.Registration{

0 commit comments

Comments
 (0)