@@ -50,8 +50,8 @@ type Config struct {
5050
5151func init () {
5252 plugin .Register (& plugin.Registration {
53- Type : plugin .RuntimeShimPlugin ,
54- ID : "shim " ,
53+ Type : plugin .RuntimePluginV2 ,
54+ ID : "task " ,
5555 Requires : []plugin.Type {
5656 plugin .EventPlugin ,
5757 plugin .MetadataPlugin ,
@@ -79,7 +79,7 @@ func init() {
7979 cs := metadata .NewContainerStore (m .(* metadata.DB ))
8080 events := ep .(* exchange.Exchange )
8181
82- return NewShimManager (ic .Context , & ManagerConfig {
82+ shimManager , err := NewShimManager (ic .Context , & ManagerConfig {
8383 Root : ic .Root ,
8484 State : ic .State ,
8585 Address : ic .Address ,
@@ -88,72 +88,15 @@ func init() {
8888 Store : cs ,
8989 SchedCore : config .SchedCore ,
9090 })
91- },
92- })
93-
94- plugin .Register (& plugin.Registration {
95- Type : plugin .RuntimePluginV2 ,
96- ID : "task" ,
97- Requires : []plugin.Type {
98- plugin .RuntimeShimPlugin ,
99- },
100- InitFn : func (ic * plugin.InitContext ) (interface {}, error ) {
101- shimManagerInterface , err := ic .Get (plugin .RuntimeShimPlugin )
10291 if err != nil {
10392 return nil , err
10493 }
10594
106- shimManager := shimManagerInterface .(* ShimManager )
107-
108- // From now on task manager works via shim manager, which has different home directory.
109- // Check if there are any leftovers from previous containerd versions and migrate home directory,
110- // so we can properly restore existing tasks as well.
111- if err := migrateTasks (ic , shimManager ); err != nil {
112- log .G (ic .Context ).WithError (err ).Error ("unable to migrate tasks" )
113- }
114-
11595 return NewTaskManager (shimManager ), nil
11696 },
11797 })
11898}
11999
120- func migrateTasks (ic * plugin.InitContext , shimManager * ShimManager ) error {
121- if ! shimManager .shims .IsEmpty () {
122- return nil
123- }
124-
125- // Rename below will fail is target directory exists.
126- // `Root` and `State` dirs expected to be empty at this point (we check that there are no shims loaded above).
127- // If for some they are not empty, these remove calls will fail (`os.Remove` requires a dir to be empty to succeed).
128- if err := os .Remove (shimManager .root ); err != nil && ! os .IsNotExist (err ) {
129- return fmt .Errorf ("failed to remove `root` dir: %w" , err )
130- }
131-
132- if err := os .Remove (shimManager .state ); err != nil && ! os .IsNotExist (err ) {
133- return fmt .Errorf ("failed to remove `state` dir: %w" , err )
134- }
135-
136- if err := os .Rename (ic .Root , shimManager .root ); err != nil {
137- if os .IsNotExist (err ) {
138- return nil
139- }
140- return fmt .Errorf ("failed to migrate task `root` directory: %w" , err )
141- }
142-
143- if err := os .Rename (ic .State , shimManager .state ); err != nil {
144- if os .IsNotExist (err ) {
145- return nil
146- }
147- return fmt .Errorf ("failed to migrate task `state` directory: %w" , err )
148- }
149-
150- if err := shimManager .loadExistingTasks (ic .Context ); err != nil {
151- return fmt .Errorf ("failed to load tasks after migration: %w" , err )
152- }
153-
154- return nil
155- }
156-
157100type ManagerConfig struct {
158101 Root string
159102 State string
@@ -209,7 +152,7 @@ type ShimManager struct {
209152
210153// ID of the shim manager
211154func (m * ShimManager ) ID () string {
212- return fmt .Sprintf ("%s.%s" , plugin .RuntimeShimPlugin , "shim" )
155+ return fmt .Sprintf ("%s.%s" , plugin .RuntimePluginV2 , "shim" )
213156}
214157
215158// Start launches a new shim instance
0 commit comments