Skip to content

Commit

Permalink
server: add ability to record config deprecations
Browse files Browse the repository at this point in the history
Signed-off-by: Samuel Karp <samuelkarp@google.com>
  • Loading branch information
samuelkarp committed Oct 25, 2023
1 parent bc861b6 commit 260e71a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 12 deletions.
13 changes: 13 additions & 0 deletions plugin/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
50 changes: 38 additions & 12 deletions services/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
}
Expand Down

0 comments on commit 260e71a

Please sign in to comment.