shim: change ttrpcService and ttrpcServerOptioner to exported interfaces
Signed-off-by: Iceber Gu <wei.cai-nat@daocloud.io>
This commit is contained in:
		@@ -72,9 +72,12 @@ func init() {
 | 
				
			|||||||
			}, nil
 | 
								}, nil
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var (
 | 
				
			||||||
 | 
						_ = shim.TTRPCServerOptioner(&taskServiceWithFp{})
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type taskServiceWithFp struct {
 | 
					type taskServiceWithFp struct {
 | 
				
			||||||
	fps   map[string]*failpoint.Failpoint
 | 
						fps   map[string]*failpoint.Failpoint
 | 
				
			||||||
	local taskapi.TaskService
 | 
						local taskapi.TaskService
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -77,6 +77,10 @@ func newTaskService(ctx context.Context, publisher shim.Publisher, sd shutdown.S
 | 
				
			|||||||
	return &exampleTaskService{}, nil
 | 
						return &exampleTaskService{}, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var (
 | 
				
			||||||
 | 
						_ = shim.TTRPCService(&exampleTaskService{})
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type exampleTaskService struct {
 | 
					type exampleTaskService struct {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -25,6 +25,7 @@ import (
 | 
				
			|||||||
	"github.com/containerd/containerd/api/types"
 | 
						"github.com/containerd/containerd/api/types"
 | 
				
			||||||
	"github.com/containerd/containerd/log"
 | 
						"github.com/containerd/containerd/log"
 | 
				
			||||||
	"github.com/containerd/containerd/pkg/shutdown"
 | 
						"github.com/containerd/containerd/pkg/shutdown"
 | 
				
			||||||
 | 
						"github.com/containerd/containerd/runtime/v2/shim"
 | 
				
			||||||
	"github.com/containerd/ttrpc"
 | 
						"github.com/containerd/ttrpc"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	api "github.com/containerd/containerd/api/runtime/sandbox/v1"
 | 
						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.
 | 
					// pauseService is an extension for task v2 runtime to support Pod "pause" containers via sandbox API.
 | 
				
			||||||
type pauseService struct {
 | 
					type pauseService struct {
 | 
				
			||||||
	shutdown shutdown.Service
 | 
						shutdown shutdown.Service
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var _ api.TTRPCSandboxService = (*pauseService)(nil)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
func (p *pauseService) RegisterTTRPC(server *ttrpc.Server) error {
 | 
					func (p *pauseService) RegisterTTRPC(server *ttrpc.Server) error {
 | 
				
			||||||
	api.RegisterTTRPCSandboxService(server, p)
 | 
						api.RegisterTTRPCSandboxService(server, p)
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -53,7 +53,7 @@ import (
 | 
				
			|||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
var (
 | 
					var (
 | 
				
			||||||
	_     = (taskAPI.TaskService)(&service{})
 | 
						_     = shim.TTRPCService(&service{})
 | 
				
			||||||
	empty = &ptypes.Empty{}
 | 
						empty = &ptypes.Empty{}
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -100,12 +100,12 @@ type Config struct {
 | 
				
			|||||||
	NoSetupLogger bool
 | 
						NoSetupLogger bool
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type ttrpcService interface {
 | 
					type TTRPCService interface {
 | 
				
			||||||
	RegisterTTRPC(*ttrpc.Server) error
 | 
						RegisterTTRPC(*ttrpc.Server) error
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type ttrpcServerOptioner interface {
 | 
					type TTRPCServerOptioner interface {
 | 
				
			||||||
	ttrpcService
 | 
						TTRPCService
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	UnaryInterceptor() ttrpc.UnaryServerInterceptor
 | 
						UnaryInterceptor() ttrpc.UnaryServerInterceptor
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -302,7 +302,7 @@ func run(ctx context.Context, manager Manager, name string, config Config) error
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	var (
 | 
						var (
 | 
				
			||||||
		initialized   = plugin.NewPluginSet()
 | 
							initialized   = plugin.NewPluginSet()
 | 
				
			||||||
		ttrpcServices = []ttrpcService{}
 | 
							ttrpcServices = []TTRPCService{}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		ttrpcUnaryInterceptors = []ttrpc.UnaryServerInterceptor{}
 | 
							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)
 | 
								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")
 | 
								logrus.WithField("id", id).Debug("registering ttrpc service")
 | 
				
			||||||
			ttrpcServices = append(ttrpcServices, src)
 | 
								ttrpcServices = append(ttrpcServices, src)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if src, ok := instance.(ttrpcServerOptioner); ok {
 | 
							if src, ok := instance.(TTRPCServerOptioner); ok {
 | 
				
			||||||
			ttrpcUnaryInterceptors = append(ttrpcUnaryInterceptors, src.UnaryInterceptor())
 | 
								ttrpcUnaryInterceptors = append(ttrpcUnaryInterceptors, src.UnaryInterceptor())
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user