Merge pull request #8747 from Iceber/shim_ttrpc_service

shim: change ttrpcService and ttrpcServerOptioner to exported interfaces
This commit is contained in:
Maksym Pavlenko 2023-07-18 17:12:22 -07:00 committed by GitHub
commit 8dcc06d14a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 10 deletions

View File

@ -69,9 +69,12 @@ func init() {
}, nil
},
})
}
var (
_ = shim.TTRPCServerOptioner(&taskServiceWithFp{})
)
type taskServiceWithFp struct {
fps map[string]*failpoint.Failpoint
local taskapi.TaskService

View File

@ -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 {
}

View File

@ -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

View File

@ -53,7 +53,7 @@ import (
)
var (
_ = (taskAPI.TaskService)(&service{})
_ = shim.TTRPCService(&service{})
empty = &ptypes.Empty{}
)

View File

@ -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())
}
}