From 4e5693938f7642e4635ba3696d908747085791e2 Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Wed, 19 Apr 2023 17:48:04 -0700 Subject: [PATCH] Add platform config to proxy plugins Signed-off-by: Derek McGowan --- services/server/config/config.go | 5 +++-- services/server/server.go | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/services/server/config/config.go b/services/server/config/config.go index bd9174b8d..ed96f090a 100644 --- a/services/server/config/config.go +++ b/services/server/config/config.go @@ -167,8 +167,9 @@ type CgroupConfig struct { // ProxyPlugin provides a proxy plugin configuration type ProxyPlugin struct { - Type string `toml:"type"` - Address string `toml:"address"` + Type string `toml:"type"` + Address string `toml:"address"` + Platform string `toml:"platform"` } // Decode unmarshals a plugin specific configuration by plugin id diff --git a/services/server/server.go b/services/server/server.go index e35c4a53a..442ecd5f6 100644 --- a/services/server/server.go +++ b/services/server/server.go @@ -45,6 +45,7 @@ import ( "github.com/containerd/containerd/log" "github.com/containerd/containerd/pkg/dialer" "github.com/containerd/containerd/pkg/timeout" + "github.com/containerd/containerd/platforms" "github.com/containerd/containerd/plugin" srvconfig "github.com/containerd/containerd/services/server/config" ssproxy "github.com/containerd/containerd/snapshots/proxy" @@ -53,6 +54,7 @@ import ( "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" @@ -396,6 +398,8 @@ func LoadPlugins(ctx context.Context, config *srvconfig.Config) ([]*plugin.Regis f func(*grpc.ClientConn) interface{} address = pp.Address + p v1.Platform + err error ) switch pp.Type { @@ -419,12 +423,21 @@ func LoadPlugins(ctx context.Context, config *srvconfig.Config) ([]*plugin.Regis default: log.G(ctx).WithField("type", pp.Type).Warn("unknown proxy plugin type") } + if pp.Platform != "" { + p, err = platforms.Parse(pp.Platform) + if err != nil { + log.G(ctx).WithError(err).WithField("plugin", name).Warn("skipping proxy platform with bad platform") + } + } else { + p = platforms.DefaultSpec() + } plugin.Register(&plugin.Registration{ Type: t, ID: name, InitFn: func(ic *plugin.InitContext) (interface{}, error) { ic.Meta.Exports["address"] = address + ic.Meta.Platforms = append(ic.Meta.Platforms, p) conn, err := clients.getClient(address) if err != nil { return nil, err