Skip to content

Commit 74a0667

Browse files
committed
plugin: 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 fa5f3c9 commit 74a0667

4 files changed

Lines changed: 31 additions & 21 deletions

File tree

plugin/plugin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ var register = struct {
146146
}{}
147147

148148
// Load loads all plugins at the provided path into containerd
149-
func Load(path string) (err error) {
149+
func Load(path string) (count int, err error) {
150150
defer func() {
151151
if v := recover(); v != nil {
152152
rerr, ok := v.(error)

plugin/plugin_go18.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/plugin_other.go

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

1919
package plugin
2020

21-
func loadPlugins(path string) error {
21+
func loadPlugins(path string) (int, error) {
2222
// plugins not supported until 1.8
23-
return nil
23+
return 0, nil
2424
}

services/server/server.go

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ import (
3434
"sync/atomic"
3535
"time"
3636

37+
"github.com/containerd/ttrpc"
38+
"github.com/docker/go-metrics"
39+
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
40+
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
41+
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
42+
"google.golang.org/grpc"
43+
"google.golang.org/grpc/backoff"
44+
"google.golang.org/grpc/credentials"
45+
"google.golang.org/grpc/credentials/insecure"
46+
3747
csapi "github.com/containerd/containerd/api/services/content/v1"
3848
diffapi "github.com/containerd/containerd/api/services/diff/v1"
3949
ssapi "github.com/containerd/containerd/api/services/snapshots/v1"
@@ -44,22 +54,14 @@ import (
4454
diffproxy "github.com/containerd/containerd/diff/proxy"
4555
"github.com/containerd/containerd/events/exchange"
4656
"github.com/containerd/containerd/log"
57+
"github.com/containerd/containerd/pkg/deprecation"
4758
"github.com/containerd/containerd/pkg/dialer"
4859
"github.com/containerd/containerd/pkg/timeout"
4960
"github.com/containerd/containerd/plugin"
5061
srvconfig "github.com/containerd/containerd/services/server/config"
5162
"github.com/containerd/containerd/services/warning"
5263
ssproxy "github.com/containerd/containerd/snapshots/proxy"
5364
"github.com/containerd/containerd/sys"
54-
"github.com/containerd/ttrpc"
55-
"github.com/docker/go-metrics"
56-
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
57-
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
58-
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
59-
"google.golang.org/grpc"
60-
"google.golang.org/grpc/backoff"
61-
"google.golang.org/grpc/credentials"
62-
"google.golang.org/grpc/credentials/insecure"
6365
)
6466

6567
// CreateTopLevelDirectories creates the top-level root and state directories.
@@ -320,7 +322,9 @@ func recordConfigDeprecations(ctx context.Context, config *srvconfig.Config, set
320322
return
321323
}
322324

323-
_ = warn // TODO(samuelkarp): placeholder for future use
325+
if config.PluginDir != "" {
326+
warn.Emit(ctx, deprecation.GoPluginLibrary)
327+
}
324328
}
325329

326330
// Server is the containerd main daemon
@@ -427,8 +431,11 @@ func LoadPlugins(ctx context.Context, config *srvconfig.Config) ([]*plugin.Regis
427431
if path == "" {
428432
path = filepath.Join(config.Root, "plugins")
429433
}
430-
if err := plugin.Load(path); err != nil {
434+
if count, err := plugin.Load(path); err != nil {
431435
return nil, err
436+
} else if count > 0 || config.PluginDir != "" {
437+
config.PluginDir = path
438+
log.G(ctx).Warningf("loaded %d dynamic plugins. `go_plugin` is deprecated, please use `external plugins` instead", count)
432439
}
433440
// load additional plugins that don't automatically register themselves
434441
plugin.Register(&plugin.Registration{

0 commit comments

Comments
 (0)