Skip to content

Commit 260e71a

Browse files
committed
server: add ability to record config deprecations
Signed-off-by: Samuel Karp <[email protected]>
1 parent bc861b6 commit 260e71a

2 files changed

Lines changed: 51 additions & 12 deletions

File tree

plugin/context.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,19 @@ func (ps *Set) Get(t Type) (interface{}, error) {
127127
return nil, fmt.Errorf("no plugins registered for %s: %w", t, ErrPluginNotFound)
128128
}
129129

130+
// GetByID returns the plugin of the given type and ID
131+
func (ps *Set) GetByID(t Type, id string) (*Plugin, error) {
132+
typSet, ok := ps.byTypeAndID[t]
133+
if !ok || len(typSet) == 0 {
134+
return nil, fmt.Errorf("no plugins registered for %s: %w", t, ErrPluginNotFound)
135+
}
136+
p, ok := typSet[id]
137+
if !ok {
138+
return nil, fmt.Errorf("no plugins registered for %s %q: %w", t, id, ErrPluginNotFound)
139+
}
140+
return p, nil
141+
}
142+
130143
// GetAll returns all initialized plugins
131144
func (ps *Set) GetAll() []*Plugin {
132145
return ps.ordered

services/server/server.go

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

37+
"github.com/containerd/log"
38+
"github.com/containerd/ttrpc"
39+
"github.com/docker/go-metrics"
40+
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
41+
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
42+
v1 "github.com/opencontainers/image-spec/specs-go/v1"
43+
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
44+
"google.golang.org/grpc"
45+
"google.golang.org/grpc/backoff"
46+
"google.golang.org/grpc/credentials"
47+
"google.golang.org/grpc/credentials/insecure"
48+
3749
csapi "github.com/containerd/containerd/api/services/content/v1"
3850
diffapi "github.com/containerd/containerd/api/services/diff/v1"
3951
sbapi "github.com/containerd/containerd/api/services/sandbox/v1"
@@ -52,19 +64,9 @@ import (
5264
"github.com/containerd/containerd/plugins"
5365
sbproxy "github.com/containerd/containerd/sandbox/proxy"
5466
srvconfig "github.com/containerd/containerd/services/server/config"
67+
"github.com/containerd/containerd/services/warning"
5568
ssproxy "github.com/containerd/containerd/snapshots/proxy"
5669
"github.com/containerd/containerd/sys"
57-
"github.com/containerd/log"
58-
"github.com/containerd/ttrpc"
59-
"github.com/docker/go-metrics"
60-
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
61-
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
62-
v1 "github.com/opencontainers/image-spec/specs-go/v1"
63-
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
64-
"google.golang.org/grpc"
65-
"google.golang.org/grpc/backoff"
66-
"google.golang.org/grpc/credentials"
67-
"google.golang.org/grpc/credentials/insecure"
6870
)
6971

7072
// CreateTopLevelDirectories creates the top-level root and state directories.
@@ -330,9 +332,33 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
330332
return nil, err
331333
}
332334
}
335+
336+
recordConfigDeprecations(ctx, config, initialized)
333337
return s, nil
334338
}
335339

340+
// recordConfigDeprecations attempts to record use of any deprecated config field. Failures are logged and ignored.
341+
func recordConfigDeprecations(ctx context.Context, config *srvconfig.Config, set *plugin.Set) {
342+
// record any detected deprecations without blocking server startup
343+
plugin, err := set.GetByID(plugins.WarningPlugin, plugins.DeprecationsPlugin)
344+
if err != nil {
345+
log.G(ctx).WithError(err).Warn("failed to load warning service to record deprecations")
346+
return
347+
}
348+
instance, err := plugin.Instance()
349+
if err != nil {
350+
log.G(ctx).WithError(err).Warn("failed to load warning service to record deprecations")
351+
return
352+
}
353+
warn, ok := instance.(warning.Service)
354+
if !ok {
355+
log.G(ctx).WithError(err).Warn("failed to load warning service to record deprecations, unexpected plugin type")
356+
return
357+
}
358+
359+
_ = warn // TODO(samuelkarp): placeholder for future use
360+
}
361+
336362
// Server is the containerd main daemon
337363
type Server struct {
338364
grpcServer *grpc.Server
@@ -433,7 +459,7 @@ func (s *Server) Wait() {
433459
// of all plugins.
434460
func LoadPlugins(ctx context.Context, config *srvconfig.Config) ([]plugin.Registration, error) {
435461
// load all plugins into containerd
436-
path := config.PluginDir //nolint: staticcheck
462+
path := config.PluginDir // nolint: staticcheck
437463
if path == "" {
438464
path = filepath.Join(config.Root, "plugins")
439465
}

0 commit comments

Comments
 (0)