From 00e5ae211844cd06b9723d8896b243976e1a3021 Mon Sep 17 00:00:00 2001 From: Iceber Gu Date: Tue, 27 Jun 2023 18:13:16 +0800 Subject: [PATCH] shim: change ttrpcService and ttrpcServerOptioner to exported interfaces Signed-off-by: Iceber Gu --- .../cmd/containerd-shim-runc-fp-v1/plugin_linux.go | 5 ++++- runtime/v2/example/example.go | 4 ++++ runtime/v2/runc/pause/sandbox.go | 8 ++++++-- runtime/v2/runc/task/service.go | 2 +- runtime/v2/shim/shim.go | 12 ++++++------ 5 files changed, 21 insertions(+), 10 deletions(-) diff --git a/integration/failpoint/cmd/containerd-shim-runc-fp-v1/plugin_linux.go b/integration/failpoint/cmd/containerd-shim-runc-fp-v1/plugin_linux.go index 1e70c3c2a..33775b2f6 100644 --- a/integration/failpoint/cmd/containerd-shim-runc-fp-v1/plugin_linux.go +++ b/integration/failpoint/cmd/containerd-shim-runc-fp-v1/plugin_linux.go @@ -72,9 +72,12 @@ func init() { }, nil }, }) - } +var ( + _ = shim.TTRPCServerOptioner(&taskServiceWithFp{}) +) + type taskServiceWithFp struct { fps map[string]*failpoint.Failpoint local taskapi.TaskService diff --git a/runtime/v2/example/example.go b/runtime/v2/example/example.go index 7715ccbc9..36618fefa 100644 --- a/runtime/v2/example/example.go +++ b/runtime/v2/example/example.go @@ -77,6 +77,10 @@ func newTaskService(ctx context.Context, publisher shim.Publisher, sd shutdown.S return &exampleTaskService{}, nil } +var ( + _ = shim.TTRPCService(&exampleTaskService{}) +) + type exampleTaskService struct { } diff --git a/runtime/v2/runc/pause/sandbox.go b/runtime/v2/runc/pause/sandbox.go index 47cef70d5..aa0a31833 100644 --- a/runtime/v2/runc/pause/sandbox.go +++ b/runtime/v2/runc/pause/sandbox.go @@ -25,6 +25,7 @@ import ( "github.com/containerd/containerd/api/types" "github.com/containerd/containerd/log" "github.com/containerd/containerd/pkg/shutdown" + "github.com/containerd/containerd/runtime/v2/shim" "github.com/containerd/ttrpc" api "github.com/containerd/containerd/api/runtime/sandbox/v1" @@ -51,13 +52,16 @@ func init() { }) } +var ( + _ = shim.TTRPCService(&pauseService{}) + _ = api.TTRPCSandboxService(&pauseService{}) +) + // pauseService is an extension for task v2 runtime to support Pod "pause" containers via sandbox API. type pauseService struct { shutdown shutdown.Service } -var _ api.TTRPCSandboxService = (*pauseService)(nil) - func (p *pauseService) RegisterTTRPC(server *ttrpc.Server) error { api.RegisterTTRPCSandboxService(server, p) return nil diff --git a/runtime/v2/runc/task/service.go b/runtime/v2/runc/task/service.go index b771b218d..936321840 100644 --- a/runtime/v2/runc/task/service.go +++ b/runtime/v2/runc/task/service.go @@ -53,7 +53,7 @@ import ( ) var ( - _ = (taskAPI.TaskService)(&service{}) + _ = shim.TTRPCService(&service{}) empty = &ptypes.Empty{} ) diff --git a/runtime/v2/shim/shim.go b/runtime/v2/shim/shim.go index 34b9b30b4..99ecfe859 100644 --- a/runtime/v2/shim/shim.go +++ b/runtime/v2/shim/shim.go @@ -100,12 +100,12 @@ type Config struct { NoSetupLogger bool } -type ttrpcService interface { +type TTRPCService interface { RegisterTTRPC(*ttrpc.Server) error } -type ttrpcServerOptioner interface { - ttrpcService +type TTRPCServerOptioner interface { + TTRPCService UnaryInterceptor() ttrpc.UnaryServerInterceptor } @@ -302,7 +302,7 @@ func run(ctx context.Context, manager Manager, name string, config Config) error var ( initialized = plugin.NewPluginSet() - ttrpcServices = []ttrpcService{} + ttrpcServices = []TTRPCService{} ttrpcUnaryInterceptors = []ttrpc.UnaryServerInterceptor{} ) @@ -349,13 +349,13 @@ func run(ctx context.Context, manager Manager, name string, config Config) error return fmt.Errorf("failed to load plugin %s: %w", id, err) } - if src, ok := instance.(ttrpcService); ok { + if src, ok := instance.(TTRPCService); ok { logrus.WithField("id", id).Debug("registering ttrpc service") ttrpcServices = append(ttrpcServices, src) } - if src, ok := instance.(ttrpcServerOptioner); ok { + if src, ok := instance.(TTRPCServerOptioner); ok { ttrpcUnaryInterceptors = append(ttrpcUnaryInterceptors, src.UnaryInterceptor()) } }