Skip to content

Commit 9936370

Browse files
committed
Refactors the TasksService requires per platform
Removes the start dependency on V1 runtimes in the TasksService for: // +build windows_v2. For unix and windows (v1) this code remains to load all v1 runtimes as expected. Signed-off-by: Justin Terry (VM) <[email protected]>
1 parent b8f4c7a commit 9936370

3 files changed

Lines changed: 96 additions & 23 deletions

File tree

services/tasks/local.go

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -60,20 +60,15 @@ var (
6060

6161
func init() {
6262
plugin.Register(&plugin.Registration{
63-
Type: plugin.ServicePlugin,
64-
ID: services.TasksService,
65-
Requires: []plugin.Type{
66-
plugin.RuntimePlugin,
67-
plugin.RuntimePluginV2,
68-
plugin.MetadataPlugin,
69-
plugin.TaskMonitorPlugin,
70-
},
71-
InitFn: initFunc,
63+
Type: plugin.ServicePlugin,
64+
ID: services.TasksService,
65+
Requires: tasksServiceRequires,
66+
InitFn: initFunc,
7267
})
7368
}
7469

7570
func initFunc(ic *plugin.InitContext) (interface{}, error) {
76-
rt, err := ic.GetByType(plugin.RuntimePlugin)
71+
runtimes, err := loadV1Runtimes(ic)
7772
if err != nil {
7873
return nil, err
7974
}
@@ -87,20 +82,7 @@ func initFunc(ic *plugin.InitContext) (interface{}, error) {
8782
if err != nil {
8883
return nil, err
8984
}
90-
runtimes := make(map[string]runtime.PlatformRuntime)
91-
for _, rr := range rt {
92-
ri, err := rr.Instance()
93-
if err != nil {
94-
log.G(ic.Context).WithError(err).Warn("could not load runtime instance due to initialization error")
95-
continue
96-
}
97-
r := ri.(runtime.PlatformRuntime)
98-
runtimes[r.ID()] = r
99-
}
10085

101-
if len(runtimes) == 0 {
102-
return nil, errors.New("no runtimes available to create task service")
103-
}
10486
monitor, err := ic.Get(plugin.TaskMonitorPlugin)
10587
if err != nil {
10688
if !errdefs.IsNotFound(err) {

services/tasks/local_unix.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// +build !windows_v2
2+
3+
/*
4+
Copyright The containerd Authors.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
package tasks
20+
21+
import (
22+
"github.com/containerd/containerd/log"
23+
"github.com/containerd/containerd/plugin"
24+
"github.com/containerd/containerd/runtime"
25+
"github.com/pkg/errors"
26+
)
27+
28+
var tasksServiceRequires = []plugin.Type{
29+
plugin.RuntimePlugin,
30+
plugin.RuntimePluginV2,
31+
plugin.MetadataPlugin,
32+
plugin.TaskMonitorPlugin,
33+
}
34+
35+
func loadV1Runtimes(ic *plugin.InitContext) (map[string]runtime.PlatformRuntime, error) {
36+
rt, err := ic.GetByType(plugin.RuntimePlugin)
37+
if err != nil {
38+
return nil, err
39+
}
40+
41+
runtimes := make(map[string]runtime.PlatformRuntime)
42+
for _, rr := range rt {
43+
ri, err := rr.Instance()
44+
if err != nil {
45+
log.G(ic.Context).WithError(err).Warn("could not load runtime instance due to initialization error")
46+
continue
47+
}
48+
r := ri.(runtime.PlatformRuntime)
49+
runtimes[r.ID()] = r
50+
}
51+
52+
if len(runtimes) == 0 {
53+
return nil, errors.New("no runtimes available to create task service")
54+
}
55+
return runtimes, nil
56+
}

services/tasks/local_windows_v2.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// +build windows,windows_v2
2+
3+
/*
4+
Copyright The containerd Authors.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
package tasks
20+
21+
import (
22+
"github.com/containerd/containerd/plugin"
23+
"github.com/containerd/containerd/runtime"
24+
)
25+
26+
var tasksServiceRequires = []plugin.Type{
27+
plugin.RuntimePluginV2,
28+
plugin.MetadataPlugin,
29+
plugin.TaskMonitorPlugin,
30+
}
31+
32+
// loadV1Runtimes on Windows V2 returns an empty map. There are no v1 runtimes
33+
func loadV1Runtimes(ic *plugin.InitContext) (map[string]runtime.PlatformRuntime, error) {
34+
return make(map[string]runtime.PlatformRuntime), nil
35+
}

0 commit comments

Comments
 (0)