Revert shim plugin migration
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
This commit is contained in:
parent
2190192b54
commit
6bccd67e84
@ -430,7 +430,7 @@ func getLogDirPath(runtimeVersion, id string) string {
|
|||||||
case "v1":
|
case "v1":
|
||||||
return filepath.Join(defaultRoot, plugin.RuntimeLinuxV1, testNamespace, id)
|
return filepath.Join(defaultRoot, plugin.RuntimeLinuxV1, testNamespace, id)
|
||||||
case "v2":
|
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:
|
default:
|
||||||
panic(fmt.Errorf("Unsupported runtime version %s", runtimeVersion))
|
panic(fmt.Errorf("Unsupported runtime version %s", runtimeVersion))
|
||||||
}
|
}
|
||||||
|
@ -57,8 +57,6 @@ const (
|
|||||||
RuntimePlugin Type = "io.containerd.runtime.v1"
|
RuntimePlugin Type = "io.containerd.runtime.v1"
|
||||||
// RuntimePluginV2 implements a runtime v2
|
// RuntimePluginV2 implements a runtime v2
|
||||||
RuntimePluginV2 Type = "io.containerd.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 implements a internal service
|
||||||
ServicePlugin Type = "io.containerd.service.v1"
|
ServicePlugin Type = "io.containerd.service.v1"
|
||||||
// GRPCPlugin implements a grpc service
|
// GRPCPlugin implements a grpc service
|
||||||
|
@ -50,8 +50,8 @@ type Config struct {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
plugin.Register(&plugin.Registration{
|
plugin.Register(&plugin.Registration{
|
||||||
Type: plugin.RuntimeShimPlugin,
|
Type: plugin.RuntimePluginV2,
|
||||||
ID: "shim",
|
ID: "task",
|
||||||
Requires: []plugin.Type{
|
Requires: []plugin.Type{
|
||||||
plugin.EventPlugin,
|
plugin.EventPlugin,
|
||||||
plugin.MetadataPlugin,
|
plugin.MetadataPlugin,
|
||||||
@ -79,7 +79,7 @@ func init() {
|
|||||||
cs := metadata.NewContainerStore(m.(*metadata.DB))
|
cs := metadata.NewContainerStore(m.(*metadata.DB))
|
||||||
events := ep.(*exchange.Exchange)
|
events := ep.(*exchange.Exchange)
|
||||||
|
|
||||||
return NewShimManager(ic.Context, &ManagerConfig{
|
shimManager, err := NewShimManager(ic.Context, &ManagerConfig{
|
||||||
Root: ic.Root,
|
Root: ic.Root,
|
||||||
State: ic.State,
|
State: ic.State,
|
||||||
Address: ic.Address,
|
Address: ic.Address,
|
||||||
@ -88,72 +88,15 @@ func init() {
|
|||||||
Store: cs,
|
Store: cs,
|
||||||
SchedCore: config.SchedCore,
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
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
|
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 {
|
type ManagerConfig struct {
|
||||||
Root string
|
Root string
|
||||||
State string
|
State string
|
||||||
@ -209,7 +152,7 @@ type ShimManager struct {
|
|||||||
|
|
||||||
// ID of the shim manager
|
// ID of the shim manager
|
||||||
func (m *ShimManager) ID() string {
|
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
|
// Start launches a new shim instance
|
||||||
|
@ -43,7 +43,6 @@ import (
|
|||||||
"github.com/containerd/containerd/plugin"
|
"github.com/containerd/containerd/plugin"
|
||||||
"github.com/containerd/containerd/runtime"
|
"github.com/containerd/containerd/runtime"
|
||||||
"github.com/containerd/containerd/runtime/linux/runctypes"
|
"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/runtime/v2/runc/options"
|
||||||
"github.com/containerd/containerd/services"
|
"github.com/containerd/containerd/services"
|
||||||
"github.com/containerd/typeurl"
|
"github.com/containerd/typeurl"
|
||||||
@ -111,7 +110,7 @@ func initFunc(ic *plugin.InitContext) (interface{}, error) {
|
|||||||
store: db.ContentStore(),
|
store: db.ContentStore(),
|
||||||
publisher: ep.(events.Publisher),
|
publisher: ep.(events.Publisher),
|
||||||
monitor: monitor.(runtime.TaskMonitor),
|
monitor: monitor.(runtime.TaskMonitor),
|
||||||
v2Runtime: v2r.(*v2.TaskManager),
|
v2Runtime: v2r.(runtime.PlatformRuntime),
|
||||||
}
|
}
|
||||||
for _, r := range runtimes {
|
for _, r := range runtimes {
|
||||||
tasks, err := r.Tasks(ic.Context, true)
|
tasks, err := r.Tasks(ic.Context, true)
|
||||||
@ -139,7 +138,7 @@ type local struct {
|
|||||||
publisher events.Publisher
|
publisher events.Publisher
|
||||||
|
|
||||||
monitor runtime.TaskMonitor
|
monitor runtime.TaskMonitor
|
||||||
v2Runtime *v2.TaskManager
|
v2Runtime runtime.PlatformRuntime
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *local) Create(ctx context.Context, r *api.CreateTaskRequest, _ ...grpc.CallOption) (*api.CreateTaskResponse, error) {
|
func (l *local) Create(ctx context.Context, r *api.CreateTaskRequest, _ ...grpc.CallOption) (*api.CreateTaskResponse, error) {
|
||||||
|
@ -24,7 +24,6 @@ import (
|
|||||||
var tasksServiceRequires = []plugin.Type{
|
var tasksServiceRequires = []plugin.Type{
|
||||||
plugin.EventPlugin,
|
plugin.EventPlugin,
|
||||||
plugin.RuntimePluginV2,
|
plugin.RuntimePluginV2,
|
||||||
plugin.RuntimeShimPlugin,
|
|
||||||
plugin.MetadataPlugin,
|
plugin.MetadataPlugin,
|
||||||
plugin.TaskMonitorPlugin,
|
plugin.TaskMonitorPlugin,
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,6 @@ var tasksServiceRequires = []plugin.Type{
|
|||||||
plugin.EventPlugin,
|
plugin.EventPlugin,
|
||||||
plugin.RuntimePlugin,
|
plugin.RuntimePlugin,
|
||||||
plugin.RuntimePluginV2,
|
plugin.RuntimePluginV2,
|
||||||
plugin.RuntimeShimPlugin,
|
|
||||||
plugin.MetadataPlugin,
|
plugin.MetadataPlugin,
|
||||||
plugin.TaskMonitorPlugin,
|
plugin.TaskMonitorPlugin,
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,6 @@ import (
|
|||||||
var tasksServiceRequires = []plugin.Type{
|
var tasksServiceRequires = []plugin.Type{
|
||||||
plugin.EventPlugin,
|
plugin.EventPlugin,
|
||||||
plugin.RuntimePluginV2,
|
plugin.RuntimePluginV2,
|
||||||
plugin.RuntimeShimPlugin,
|
|
||||||
plugin.MetadataPlugin,
|
plugin.MetadataPlugin,
|
||||||
plugin.TaskMonitorPlugin,
|
plugin.TaskMonitorPlugin,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user