Fix backward compatibility with old task shims
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
This commit is contained in:
parent
33786ee4d2
commit
a3d298193c
@ -433,7 +433,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.v2.shim", testNamespace, id)
|
||||
return filepath.Join(defaultState, "io.containerd.runtime.v2.task", testNamespace, id)
|
||||
default:
|
||||
panic(fmt.Errorf("Unsupported runtime version %s", runtimeVersion))
|
||||
}
|
||||
|
@ -57,8 +57,8 @@ const (
|
||||
RuntimePlugin Type = "io.containerd.runtime.v1"
|
||||
// RuntimePluginV2 implements a runtime v2
|
||||
RuntimePluginV2 Type = "io.containerd.runtime.v2"
|
||||
// RuntimePluginV2Service is a shim provided service implemented on top of runtime v2 plugins.
|
||||
RuntimePluginV2Service Type = "io.containerd.runtime.v2.service"
|
||||
// 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
|
||||
|
@ -48,7 +48,7 @@ type Config struct {
|
||||
|
||||
func init() {
|
||||
plugin.Register(&plugin.Registration{
|
||||
Type: plugin.RuntimePluginV2,
|
||||
Type: plugin.RuntimeShimPlugin,
|
||||
ID: "shim",
|
||||
Requires: []plugin.Type{
|
||||
plugin.EventPlugin,
|
||||
@ -65,12 +65,7 @@ func init() {
|
||||
}
|
||||
|
||||
ic.Meta.Platforms = supportedPlatforms
|
||||
if err := os.MkdirAll(ic.Root, 0711); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := os.MkdirAll(ic.State, 0711); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
m, err := ic.Get(plugin.MetadataPlugin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -95,18 +90,47 @@ func init() {
|
||||
})
|
||||
|
||||
plugin.Register(&plugin.Registration{
|
||||
Type: plugin.RuntimePluginV2Service,
|
||||
Type: plugin.RuntimePluginV2,
|
||||
ID: "task",
|
||||
Requires: []plugin.Type{
|
||||
plugin.RuntimePluginV2,
|
||||
plugin.RuntimeShimPlugin,
|
||||
},
|
||||
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
|
||||
shimInstance, err := ic.GetByID(plugin.RuntimePluginV2, "shim")
|
||||
m, err := ic.Get(plugin.MetadataPlugin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ep, err := ic.GetByID(plugin.EventPlugin, "exchange")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cs := metadata.NewContainerStore(m.(*metadata.DB))
|
||||
events := ep.(*exchange.Exchange)
|
||||
|
||||
shimManager, err := NewShimManager(ic.Context, &ManagerConfig{
|
||||
Root: ic.Root,
|
||||
State: ic.State,
|
||||
Address: ic.Address,
|
||||
TTRPCAddress: ic.TTRPCAddress,
|
||||
Events: events,
|
||||
Store: cs,
|
||||
SchedCore: false,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
shimManager := shimInstance.(*ShimManager)
|
||||
// Internally task manager relies on shim manager to launch task shims.
|
||||
// It's also possible to use shim manager independently and launch other types of shims.
|
||||
//
|
||||
// Ideally task manager should depend on shim instance we registered above, however it'll use
|
||||
// different home directory (`io.containerd.runtime.v2.task` vs `io.containerd.runtime.v2.shim`),
|
||||
// which will break backward compatibility when upgrading containerd to the new version.
|
||||
//
|
||||
// For now, we create another instance of shim manager with the "old" home directory, so shim tasks
|
||||
// are properly restored, but will work independently.
|
||||
//
|
||||
// See more context https://github.com/containerd/containerd/pull/5918#discussion_r705434412
|
||||
return NewTaskManager(shimManager), nil
|
||||
},
|
||||
})
|
||||
@ -420,7 +444,7 @@ func NewTaskManager(shims *ShimManager) *TaskManager {
|
||||
|
||||
// ID of the task manager
|
||||
func (m *TaskManager) ID() string {
|
||||
return fmt.Sprintf("%s.%s", plugin.RuntimePluginV2Service, "task")
|
||||
return fmt.Sprintf("%s.%s", plugin.RuntimeShimPlugin, "task")
|
||||
}
|
||||
|
||||
// Create launches new shim instance and creates new task
|
||||
|
@ -81,7 +81,7 @@ func initFunc(ic *plugin.InitContext) (interface{}, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
v2r, err := ic.GetByID(plugin.RuntimePluginV2Service, "task")
|
||||
v2r, err := ic.GetByID(plugin.RuntimePluginV2, "task")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ import (
|
||||
var tasksServiceRequires = []plugin.Type{
|
||||
plugin.EventPlugin,
|
||||
plugin.RuntimePluginV2,
|
||||
plugin.RuntimePluginV2Service,
|
||||
plugin.RuntimeShimPlugin,
|
||||
plugin.MetadataPlugin,
|
||||
plugin.TaskMonitorPlugin,
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ var tasksServiceRequires = []plugin.Type{
|
||||
plugin.EventPlugin,
|
||||
plugin.RuntimePlugin,
|
||||
plugin.RuntimePluginV2,
|
||||
plugin.RuntimePluginV2Service,
|
||||
plugin.RuntimeShimPlugin,
|
||||
plugin.MetadataPlugin,
|
||||
plugin.TaskMonitorPlugin,
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ import (
|
||||
var tasksServiceRequires = []plugin.Type{
|
||||
plugin.EventPlugin,
|
||||
plugin.RuntimePluginV2,
|
||||
plugin.RuntimePluginV2Service,
|
||||
plugin.RuntimeShimPlugin,
|
||||
plugin.MetadataPlugin,
|
||||
plugin.TaskMonitorPlugin,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user