Skip to content

Commit 218c7a1

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 dfb9e1d commit 218c7a1

2 files changed

Lines changed: 51 additions & 11 deletions

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: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ import (
3535
"sync/atomic"
3636
"time"
3737

38+
"github.com/containerd/ttrpc"
39+
metrics "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+
bolt "go.etcd.io/bbolt"
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+
3849
csapi "github.com/containerd/containerd/api/services/content/v1"
3950
ssapi "github.com/containerd/containerd/api/services/snapshots/v1"
4051
"github.com/containerd/containerd/content"
@@ -49,19 +60,10 @@ import (
4960
"github.com/containerd/containerd/pkg/timeout"
5061
"github.com/containerd/containerd/plugin"
5162
srvconfig "github.com/containerd/containerd/services/server/config"
63+
"github.com/containerd/containerd/services/warning"
5264
"github.com/containerd/containerd/snapshots"
5365
ssproxy "github.com/containerd/containerd/snapshots/proxy"
5466
"github.com/containerd/containerd/sys"
55-
"github.com/containerd/ttrpc"
56-
metrics "github.com/docker/go-metrics"
57-
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
58-
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
59-
bolt "go.etcd.io/bbolt"
60-
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
61-
"google.golang.org/grpc"
62-
"google.golang.org/grpc/backoff"
63-
"google.golang.org/grpc/credentials"
64-
"google.golang.org/grpc/credentials/insecure"
6567
)
6668

6769
const (
@@ -306,9 +308,33 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
306308
return nil, err
307309
}
308310
}
311+
312+
recordConfigDeprecations(ctx, config, initialized)
309313
return s, nil
310314
}
311315

316+
// recordConfigDeprecations attempts to record use of any deprecated config field. Failures are logged and ignored.
317+
func recordConfigDeprecations(ctx context.Context, config *srvconfig.Config, set *plugin.Set) {
318+
// record any detected deprecations without blocking server startup
319+
plugin, err := set.GetByID(plugin.WarningPlugin, plugin.DeprecationsPlugin)
320+
if err != nil {
321+
log.G(ctx).WithError(err).Warn("failed to load warning service to record deprecations")
322+
return
323+
}
324+
instance, err := plugin.Instance()
325+
if err != nil {
326+
log.G(ctx).WithError(err).Warn("failed to load warning service to record deprecations")
327+
return
328+
}
329+
warn, ok := instance.(warning.Service)
330+
if !ok {
331+
log.G(ctx).WithError(err).Warn("failed to load warning service to record deprecations, unexpected plugin type")
332+
return
333+
}
334+
335+
_ = warn // TODO(samuelkarp): placeholder for future use
336+
}
337+
312338
// Server is the containerd main daemon
313339
type Server struct {
314340
grpcServer *grpc.Server

0 commit comments

Comments
 (0)