Skip to content

Commit fa5f3c9

Browse files
committed
server: add ability to record config deprecations
Signed-off-by: Samuel Karp <[email protected]> (cherry picked from commit 260e71a) Signed-off-by: Samuel Karp <[email protected]>
1 parent f7880e7 commit fa5f3c9

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

plugin/context.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ import (
2121
"fmt"
2222
"path/filepath"
2323

24+
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
25+
2426
"github.com/containerd/containerd/errdefs"
2527
"github.com/containerd/containerd/events/exchange"
26-
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
2728
)
2829

2930
// InitContext is used for plugin initialization
@@ -133,6 +134,19 @@ func (ps *Set) Get(t Type) (interface{}, error) {
133134
return nil, fmt.Errorf("no plugins registered for %s: %w", t, errdefs.ErrNotFound)
134135
}
135136

137+
// GetByID returns the plugin of the given type and ID
138+
func (ps *Set) GetByID(t Type, id string) (*Plugin, error) {
139+
typSet, ok := ps.byTypeAndID[t]
140+
if !ok || len(typSet) == 0 {
141+
return nil, fmt.Errorf("no plugins registered for %s: %w", t, errdefs.ErrNotFound)
142+
}
143+
p, ok := typSet[id]
144+
if !ok {
145+
return nil, fmt.Errorf("no plugins registered for %s %q: %w", t, id, errdefs.ErrNotFound)
146+
}
147+
return p, nil
148+
}
149+
136150
// GetAll returns all initialized plugins
137151
func (ps *Set) GetAll() []*Plugin {
138152
return ps.ordered

services/server/server.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import (
4848
"github.com/containerd/containerd/pkg/timeout"
4949
"github.com/containerd/containerd/plugin"
5050
srvconfig "github.com/containerd/containerd/services/server/config"
51+
"github.com/containerd/containerd/services/warning"
5152
ssproxy "github.com/containerd/containerd/snapshots/proxy"
5253
"github.com/containerd/containerd/sys"
5354
"github.com/containerd/ttrpc"
@@ -295,9 +296,33 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
295296
return nil, err
296297
}
297298
}
299+
300+
recordConfigDeprecations(ctx, config, initialized)
298301
return s, nil
299302
}
300303

304+
// recordConfigDeprecations attempts to record use of any deprecated config field. Failures are logged and ignored.
305+
func recordConfigDeprecations(ctx context.Context, config *srvconfig.Config, set *plugin.Set) {
306+
// record any detected deprecations without blocking server startup
307+
plugin, err := set.GetByID(plugin.WarningPlugin, plugin.DeprecationsPlugin)
308+
if err != nil {
309+
log.G(ctx).WithError(err).Warn("failed to load warning service to record deprecations")
310+
return
311+
}
312+
instance, err := plugin.Instance()
313+
if err != nil {
314+
log.G(ctx).WithError(err).Warn("failed to load warning service to record deprecations")
315+
return
316+
}
317+
warn, ok := instance.(warning.Service)
318+
if !ok {
319+
log.G(ctx).WithError(err).Warn("failed to load warning service to record deprecations, unexpected plugin type")
320+
return
321+
}
322+
323+
_ = warn // TODO(samuelkarp): placeholder for future use
324+
}
325+
301326
// Server is the containerd main daemon
302327
type Server struct {
303328
grpcServer *grpc.Server

0 commit comments

Comments
 (0)