diff --git a/cmd/containerd-shim-runc-v2/main.go b/cmd/containerd-shim-runc-v2/main.go index b57ed16ef..7b80310f0 100644 --- a/cmd/containerd-shim-runc-v2/main.go +++ b/cmd/containerd-shim-runc-v2/main.go @@ -28,5 +28,5 @@ import ( ) func main() { - shim.RunManager(context.Background(), manager.NewShimManager("io.containerd.runc.v2")) + shim.Run(context.Background(), manager.NewShimManager("io.containerd.runc.v2")) } diff --git a/integration/failpoint/cmd/containerd-shim-runc-fp-v1/main_linux.go b/integration/failpoint/cmd/containerd-shim-runc-fp-v1/main_linux.go index 0c6af2526..c55ffb77b 100644 --- a/integration/failpoint/cmd/containerd-shim-runc-fp-v1/main_linux.go +++ b/integration/failpoint/cmd/containerd-shim-runc-fp-v1/main_linux.go @@ -25,5 +25,5 @@ import ( ) func main() { - shim.RunManager(context.Background(), manager.NewShimManager("io.containerd.runc-fp.v1")) + shim.Run(context.Background(), manager.NewShimManager("io.containerd.runc-fp.v1")) } diff --git a/runtime/v2/shim/shim.go b/runtime/v2/shim/shim.go index cf006d805..34b9b30b4 100644 --- a/runtime/v2/shim/shim.go +++ b/runtime/v2/shim/shim.go @@ -50,11 +50,9 @@ type Publisher interface { // StartOpts describes shim start configuration received from containerd type StartOpts struct { - ID string // TODO(2.0): Remove ID, passed directly to start for call symmetry - ContainerdBinary string // TODO(2.0): Remove ContainerdBinary, use the TTRPC_ADDRESS env to forward events - Address string - TTRPCAddress string - Debug bool + Address string + TTRPCAddress string + Debug bool } // BootstrapParams is a JSON payload returned in stdout from shim.Start call. @@ -73,18 +71,6 @@ type StopStatus struct { ExitedAt time.Time } -// Init func for the creation of a shim server -// TODO(2.0): Remove init function -type Init func(context.Context, string, Publisher, func()) (Shim, error) - -// Shim server interface -// TODO(2.0): Remove unified shim interface -type Shim interface { - shimapi.TaskService - Cleanup(ctx context.Context) (*shimapi.DeleteResponse, error) - StartShim(ctx context.Context, opts StartOpts) (string, error) -} - // Manager is the interface which manages the shim process type Manager interface { Name() string @@ -124,15 +110,6 @@ type ttrpcServerOptioner interface { UnaryInterceptor() ttrpc.UnaryServerInterceptor } -type taskService struct { - shimapi.TaskService -} - -func (t taskService) RegisterTTRPC(server *ttrpc.Server) error { - shimapi.RegisterTaskService(server, t.TaskService) - return nil -} - var ( debugFlag bool versionFlag bool @@ -200,54 +177,8 @@ func setLogger(ctx context.Context, id string) (context.Context, error) { return log.WithLogger(ctx, l), nil } -// Run initializes and runs a shim server -// TODO(2.0): Remove function -func Run(name string, initFunc Init, opts ...BinaryOpts) { - var config Config - for _, o := range opts { - o(&config) - } - - ctx := context.Background() - ctx = log.WithLogger(ctx, log.G(ctx).WithField("runtime", name)) - - if err := run(ctx, nil, initFunc, name, config); err != nil { - fmt.Fprintf(os.Stderr, "%s: %s", name, err) - os.Exit(1) - } -} - -// TODO(2.0): Remove this type -type shimToManager struct { - shim Shim - name string -} - -func (stm shimToManager) Name() string { - return stm.name -} - -func (stm shimToManager) Start(ctx context.Context, id string, opts StartOpts) (string, error) { - opts.ID = id - return stm.shim.StartShim(ctx, opts) -} - -func (stm shimToManager) Stop(ctx context.Context, id string) (StopStatus, error) { - // shim must already have id - dr, err := stm.shim.Cleanup(ctx) - if err != nil { - return StopStatus{}, err - } - return StopStatus{ - Pid: int(dr.Pid), - ExitStatus: int(dr.ExitStatus), - ExitedAt: protobuf.FromTimestamp(dr.ExitedAt), - }, nil -} - -// RunManager initializes and runs a shim server. -// TODO(2.0): Rename to Run -func RunManager(ctx context.Context, manager Manager, opts ...BinaryOpts) { +// Run initializes and runs a shim server. +func Run(ctx context.Context, manager Manager, opts ...BinaryOpts) { var config Config for _, o := range opts { o(&config) @@ -255,13 +186,13 @@ func RunManager(ctx context.Context, manager Manager, opts ...BinaryOpts) { ctx = log.WithLogger(ctx, log.G(ctx).WithField("runtime", manager.Name())) - if err := run(ctx, manager, nil, "", config); err != nil { + if err := run(ctx, manager, "", config); err != nil { fmt.Fprintf(os.Stderr, "%s: %s", manager.Name(), err) os.Exit(1) } } -func run(ctx context.Context, manager Manager, initFunc Init, name string, config Config) error { +func run(ctx context.Context, manager Manager, name string, config Config) error { parseFlags() if versionFlag { fmt.Printf("%s:\n", filepath.Base(os.Args[0])) @@ -301,27 +232,6 @@ func run(ctx context.Context, manager Manager, initFunc Init, name string, confi ctx, sd := shutdown.WithShutdown(ctx) defer sd.Shutdown() - if manager == nil { - service, err := initFunc(ctx, id, publisher, sd.Shutdown) - if err != nil { - return err - } - plugin.Register(&plugin.Registration{ - Type: plugin.TTRPCPlugin, - ID: "task", - Requires: []plugin.Type{ - plugin.EventPlugin, - }, - InitFn: func(ic *plugin.InitContext) (interface{}, error) { - return taskService{service}, nil - }, - }) - manager = shimToManager{ - shim: service, - name: name, - } - } - // Handle explicit actions switch action { case "delete":