diff --git a/integration/client/container_linux_test.go b/integration/client/container_linux_test.go index 586260102..c7a74353d 100644 --- a/integration/client/container_linux_test.go +++ b/integration/client/container_linux_test.go @@ -430,7 +430,7 @@ func getLogDirPath(runtimeVersion, id string) string { case "v1": return filepath.Join(defaultRoot, plugin.RuntimeLinuxV1, testNamespace, id) case "v2": - return filepath.Join(defaultState, "io.containerd.runtime-shim.v2.shim", testNamespace, id) + return filepath.Join(defaultState, "io.containerd.runtime.v2.task", testNamespace, id) default: panic(fmt.Errorf("Unsupported runtime version %s", runtimeVersion)) } diff --git a/plugin/plugin.go b/plugin/plugin.go index 6c94e960c..f24a3c77b 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -57,8 +57,6 @@ const ( RuntimePlugin Type = "io.containerd.runtime.v1" // RuntimePluginV2 implements a runtime v2 RuntimePluginV2 Type = "io.containerd.runtime.v2" - // RuntimeShimPlugin implements the shim manager for runtime v2. - RuntimeShimPlugin Type = "io.containerd.runtime-shim.v2" // ServicePlugin implements a internal service ServicePlugin Type = "io.containerd.service.v1" // GRPCPlugin implements a grpc service diff --git a/runtime/v2/manager.go b/runtime/v2/manager.go index 338197ab3..73703b802 100644 --- a/runtime/v2/manager.go +++ b/runtime/v2/manager.go @@ -50,8 +50,8 @@ type Config struct { func init() { plugin.Register(&plugin.Registration{ - Type: plugin.RuntimeShimPlugin, - ID: "shim", + Type: plugin.RuntimePluginV2, + ID: "task", Requires: []plugin.Type{ plugin.EventPlugin, plugin.MetadataPlugin, @@ -79,7 +79,7 @@ func init() { cs := metadata.NewContainerStore(m.(*metadata.DB)) events := ep.(*exchange.Exchange) - return NewShimManager(ic.Context, &ManagerConfig{ + shimManager, err := NewShimManager(ic.Context, &ManagerConfig{ Root: ic.Root, State: ic.State, Address: ic.Address, @@ -88,72 +88,15 @@ func init() { Store: cs, SchedCore: config.SchedCore, }) - }, - }) - - plugin.Register(&plugin.Registration{ - Type: plugin.RuntimePluginV2, - ID: "task", - Requires: []plugin.Type{ - plugin.RuntimeShimPlugin, - }, - InitFn: func(ic *plugin.InitContext) (interface{}, error) { - shimManagerInterface, err := ic.Get(plugin.RuntimeShimPlugin) if err != nil { return nil, err } - shimManager := shimManagerInterface.(*ShimManager) - - // From now on task manager works via shim manager, which has different home directory. - // Check if there are any leftovers from previous containerd versions and migrate home directory, - // so we can properly restore existing tasks as well. - if err := migrateTasks(ic, shimManager); err != nil { - log.G(ic.Context).WithError(err).Error("unable to migrate tasks") - } - return NewTaskManager(shimManager), nil }, }) } -func migrateTasks(ic *plugin.InitContext, shimManager *ShimManager) error { - if !shimManager.shims.IsEmpty() { - return nil - } - - // Rename below will fail is target directory exists. - // `Root` and `State` dirs expected to be empty at this point (we check that there are no shims loaded above). - // If for some they are not empty, these remove calls will fail (`os.Remove` requires a dir to be empty to succeed). - if err := os.Remove(shimManager.root); err != nil && !os.IsNotExist(err) { - return fmt.Errorf("failed to remove `root` dir: %w", err) - } - - if err := os.Remove(shimManager.state); err != nil && !os.IsNotExist(err) { - return fmt.Errorf("failed to remove `state` dir: %w", err) - } - - if err := os.Rename(ic.Root, shimManager.root); err != nil { - if os.IsNotExist(err) { - return nil - } - return fmt.Errorf("failed to migrate task `root` directory: %w", err) - } - - if err := os.Rename(ic.State, shimManager.state); err != nil { - if os.IsNotExist(err) { - return nil - } - return fmt.Errorf("failed to migrate task `state` directory: %w", err) - } - - if err := shimManager.loadExistingTasks(ic.Context); err != nil { - return fmt.Errorf("failed to load tasks after migration: %w", err) - } - - return nil -} - type ManagerConfig struct { Root string State string @@ -209,7 +152,7 @@ type ShimManager struct { // ID of the shim manager func (m *ShimManager) ID() string { - return fmt.Sprintf("%s.%s", plugin.RuntimeShimPlugin, "shim") + return fmt.Sprintf("%s.%s", plugin.RuntimePluginV2, "shim") } // Start launches a new shim instance diff --git a/services/tasks/local.go b/services/tasks/local.go index 98ff571b1..9a2b33c24 100644 --- a/services/tasks/local.go +++ b/services/tasks/local.go @@ -43,7 +43,6 @@ import ( "github.com/containerd/containerd/plugin" "github.com/containerd/containerd/runtime" "github.com/containerd/containerd/runtime/linux/runctypes" - v2 "github.com/containerd/containerd/runtime/v2" "github.com/containerd/containerd/runtime/v2/runc/options" "github.com/containerd/containerd/services" "github.com/containerd/typeurl" @@ -111,7 +110,7 @@ func initFunc(ic *plugin.InitContext) (interface{}, error) { store: db.ContentStore(), publisher: ep.(events.Publisher), monitor: monitor.(runtime.TaskMonitor), - v2Runtime: v2r.(*v2.TaskManager), + v2Runtime: v2r.(runtime.PlatformRuntime), } for _, r := range runtimes { tasks, err := r.Tasks(ic.Context, true) @@ -139,7 +138,7 @@ type local struct { publisher events.Publisher monitor runtime.TaskMonitor - v2Runtime *v2.TaskManager + v2Runtime runtime.PlatformRuntime } func (l *local) Create(ctx context.Context, r *api.CreateTaskRequest, _ ...grpc.CallOption) (*api.CreateTaskResponse, error) { diff --git a/services/tasks/local_freebsd.go b/services/tasks/local_freebsd.go index aa081529a..c0b57edfa 100644 --- a/services/tasks/local_freebsd.go +++ b/services/tasks/local_freebsd.go @@ -24,7 +24,6 @@ import ( var tasksServiceRequires = []plugin.Type{ plugin.EventPlugin, plugin.RuntimePluginV2, - plugin.RuntimeShimPlugin, plugin.MetadataPlugin, plugin.TaskMonitorPlugin, } diff --git a/services/tasks/local_unix.go b/services/tasks/local_unix.go index badd3bc7a..50a29f612 100644 --- a/services/tasks/local_unix.go +++ b/services/tasks/local_unix.go @@ -30,7 +30,6 @@ var tasksServiceRequires = []plugin.Type{ plugin.EventPlugin, plugin.RuntimePlugin, plugin.RuntimePluginV2, - plugin.RuntimeShimPlugin, plugin.MetadataPlugin, plugin.TaskMonitorPlugin, } diff --git a/services/tasks/local_windows.go b/services/tasks/local_windows.go index c494f4981..90b1ed9dd 100644 --- a/services/tasks/local_windows.go +++ b/services/tasks/local_windows.go @@ -24,7 +24,6 @@ import ( var tasksServiceRequires = []plugin.Type{ plugin.EventPlugin, plugin.RuntimePluginV2, - plugin.RuntimeShimPlugin, plugin.MetadataPlugin, plugin.TaskMonitorPlugin, }