server: add ability to record config deprecations
Signed-off-by: Samuel Karp <samuelkarp@google.com>
This commit is contained in:
parent
bc861b66f9
commit
260e71abc4
@ -127,6 +127,19 @@ func (ps *Set) Get(t Type) (interface{}, error) {
|
||||
return nil, fmt.Errorf("no plugins registered for %s: %w", t, ErrPluginNotFound)
|
||||
}
|
||||
|
||||
// GetByID returns the plugin of the given type and ID
|
||||
func (ps *Set) GetByID(t Type, id string) (*Plugin, error) {
|
||||
typSet, ok := ps.byTypeAndID[t]
|
||||
if !ok || len(typSet) == 0 {
|
||||
return nil, fmt.Errorf("no plugins registered for %s: %w", t, ErrPluginNotFound)
|
||||
}
|
||||
p, ok := typSet[id]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("no plugins registered for %s %q: %w", t, id, ErrPluginNotFound)
|
||||
}
|
||||
return p, nil
|
||||
}
|
||||
|
||||
// GetAll returns all initialized plugins
|
||||
func (ps *Set) GetAll() []*Plugin {
|
||||
return ps.ordered
|
||||
|
@ -34,6 +34,18 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/containerd/log"
|
||||
"github.com/containerd/ttrpc"
|
||||
"github.com/docker/go-metrics"
|
||||
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
|
||||
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
||||
v1 "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/backoff"
|
||||
"google.golang.org/grpc/credentials"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
|
||||
csapi "github.com/containerd/containerd/api/services/content/v1"
|
||||
diffapi "github.com/containerd/containerd/api/services/diff/v1"
|
||||
sbapi "github.com/containerd/containerd/api/services/sandbox/v1"
|
||||
@ -52,19 +64,9 @@ import (
|
||||
"github.com/containerd/containerd/plugins"
|
||||
sbproxy "github.com/containerd/containerd/sandbox/proxy"
|
||||
srvconfig "github.com/containerd/containerd/services/server/config"
|
||||
"github.com/containerd/containerd/services/warning"
|
||||
ssproxy "github.com/containerd/containerd/snapshots/proxy"
|
||||
"github.com/containerd/containerd/sys"
|
||||
"github.com/containerd/log"
|
||||
"github.com/containerd/ttrpc"
|
||||
"github.com/docker/go-metrics"
|
||||
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
|
||||
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
||||
v1 "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/backoff"
|
||||
"google.golang.org/grpc/credentials"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
)
|
||||
|
||||
// CreateTopLevelDirectories creates the top-level root and state directories.
|
||||
@ -330,9 +332,33 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
recordConfigDeprecations(ctx, config, initialized)
|
||||
return s, nil
|
||||
}
|
||||
|
||||
// recordConfigDeprecations attempts to record use of any deprecated config field. Failures are logged and ignored.
|
||||
func recordConfigDeprecations(ctx context.Context, config *srvconfig.Config, set *plugin.Set) {
|
||||
// record any detected deprecations without blocking server startup
|
||||
plugin, err := set.GetByID(plugins.WarningPlugin, plugins.DeprecationsPlugin)
|
||||
if err != nil {
|
||||
log.G(ctx).WithError(err).Warn("failed to load warning service to record deprecations")
|
||||
return
|
||||
}
|
||||
instance, err := plugin.Instance()
|
||||
if err != nil {
|
||||
log.G(ctx).WithError(err).Warn("failed to load warning service to record deprecations")
|
||||
return
|
||||
}
|
||||
warn, ok := instance.(warning.Service)
|
||||
if !ok {
|
||||
log.G(ctx).WithError(err).Warn("failed to load warning service to record deprecations, unexpected plugin type")
|
||||
return
|
||||
}
|
||||
|
||||
_ = warn // TODO(samuelkarp): placeholder for future use
|
||||
}
|
||||
|
||||
// Server is the containerd main daemon
|
||||
type Server struct {
|
||||
grpcServer *grpc.Server
|
||||
@ -433,7 +459,7 @@ func (s *Server) Wait() {
|
||||
// of all plugins.
|
||||
func LoadPlugins(ctx context.Context, config *srvconfig.Config) ([]plugin.Registration, error) {
|
||||
// load all plugins into containerd
|
||||
path := config.PluginDir //nolint: staticcheck
|
||||
path := config.PluginDir // nolint: staticcheck
|
||||
if path == "" {
|
||||
path = filepath.Join(config.Root, "plugins")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user