Skip to content

Commit 329e1d4

Browse files
committed
tasks: emit warning for v1 runtime
Signed-off-by: Samuel Karp <[email protected]>
1 parent 9c65471 commit 329e1d4

6 files changed

Lines changed: 26 additions & 3 deletions

File tree

pkg/deprecation/deprecation.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ const (
3535
CRIAPIV1Alpha2 Warning = Prefix + "cri-api-v1alpha2"
3636
// AUFSSnapshotter is a warning for the use of the aufs snapshotter
3737
AUFSSnapshotter Warning = Prefix + "aufs-snapshotter"
38+
// RuntimeV1 is a warning for the io.containerd.runtime.v1.linux runtime
39+
RuntimeV1 Warning = Prefix + "runtime-v1"
3840
)
3941

4042
var messages = map[Warning]string{
@@ -49,6 +51,7 @@ var messages = map[Warning]string{
4951
"Use `config_path` instead.",
5052
CRIAPIV1Alpha2: "CRI API v1alpha2 is deprecated since containerd v1.7 and removed in containerd v2.0. Use CRI API v1 instead.",
5153
AUFSSnapshotter: "The aufs snapshotter is deprecated since containerd v1.5 and removed in containerd v2.0. Use the overlay snapshotter instead.",
54+
RuntimeV1: "The `io.containerd.runtime.v1.linux` runtime is deprecated since containerd v1.4 and removed in containerd v2.0. Use the `io.containerd.runc.v2` runtime instead.",
5255
}
5356

5457
// Valid checks whether a given Warning is valid

services/tasks/local.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import (
4040
"github.com/containerd/containerd/metadata"
4141
"github.com/containerd/containerd/mount"
4242
"github.com/containerd/containerd/pkg/blockio"
43+
"github.com/containerd/containerd/pkg/deprecation"
4344
"github.com/containerd/containerd/pkg/rdt"
4445
"github.com/containerd/containerd/pkg/timeout"
4546
"github.com/containerd/containerd/plugin"
@@ -50,6 +51,8 @@ import (
5051
"github.com/containerd/containerd/runtime/linux/runctypes"
5152
"github.com/containerd/containerd/runtime/v2/runc/options"
5253
"github.com/containerd/containerd/services"
54+
"github.com/containerd/containerd/services/warning"
55+
5356
"github.com/containerd/typeurl/v2"
5457
"github.com/opencontainers/go-digest"
5558
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
@@ -117,6 +120,11 @@ func initFunc(ic *plugin.InitContext) (interface{}, error) {
117120
monitor = runtime.NewNoopMonitor()
118121
}
119122

123+
w, err := ic.Get(plugin.WarningPlugin)
124+
if err != nil {
125+
return nil, err
126+
}
127+
120128
db := m.(*metadata.DB)
121129
l := &local{
122130
runtimes: runtimes,
@@ -125,6 +133,7 @@ func initFunc(ic *plugin.InitContext) (interface{}, error) {
125133
publisher: ep.(events.Publisher),
126134
monitor: monitor.(runtime.TaskMonitor),
127135
v2Runtime: v2r.(runtime.PlatformRuntime),
136+
warnings: w.(warning.Service),
128137
}
129138
for _, r := range runtimes {
130139
tasks, err := r.Tasks(ic.Context, true)
@@ -161,6 +170,7 @@ type local struct {
161170

162171
monitor runtime.TaskMonitor
163172
v2Runtime runtime.PlatformRuntime
173+
warnings warning.Service
164174
}
165175

166176
func (l *local) Create(ctx context.Context, r *api.CreateTaskRequest, _ ...grpc.CallOption) (*api.CreateTaskResponse, error) {
@@ -221,11 +231,10 @@ func (l *local) Create(ctx context.Context, r *api.CreateTaskRequest, _ ...grpc.
221231
Options: m.Options,
222232
})
223233
}
224-
if strings.HasPrefix(container.Runtime.Name, "io.containerd.runtime.v1.") {
225-
log.G(ctx).Warn("runtime v1 is deprecated since containerd v1.4, consider using runtime v2")
226-
} else if container.Runtime.Name == plugin.RuntimeRuncV1 {
234+
if container.Runtime.Name == plugin.RuntimeRuncV1 {
227235
log.G(ctx).Warnf("%q is deprecated since containerd v1.4, consider using %q", plugin.RuntimeRuncV1, plugin.RuntimeRuncV2)
228236
}
237+
l.emitRuntimeWarning(ctx, container.Runtime.Name)
229238
rtime, err := l.getRuntime(container.Runtime.Name)
230239
if err != nil {
231240
return nil, err
@@ -255,6 +264,13 @@ func (l *local) Create(ctx context.Context, r *api.CreateTaskRequest, _ ...grpc.
255264
}, nil
256265
}
257266

267+
func (l *local) emitRuntimeWarning(ctx context.Context, runtime string) {
268+
switch runtime {
269+
case plugin.RuntimeLinuxV1:
270+
log.G(ctx).Warnf("%q is deprecated since containerd v1.4 and will be removed in containerd v2.0, use %q instead", plugin.RuntimeLinuxV1, plugin.RuntimeRuncV2)
271+
l.warnings.Emit(ctx, deprecation.RuntimeV1)
272+
}
273+
}
258274
func (l *local) Start(ctx context.Context, r *api.StartRequest, _ ...grpc.CallOption) (*api.StartResponse, error) {
259275
t, err := l.getTask(ctx, r.ContainerID)
260276
if err != nil {

services/tasks/local_darwin.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var tasksServiceRequires = []plugin.Type{
2727
plugin.RuntimePluginV2,
2828
plugin.MetadataPlugin,
2929
plugin.TaskMonitorPlugin,
30+
plugin.WarningPlugin,
3031
}
3132

3233
// loadV1Runtimes on darwin returns an empty map. There are no v1 runtimes

services/tasks/local_freebsd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var tasksServiceRequires = []plugin.Type{
2626
plugin.RuntimePluginV2,
2727
plugin.MetadataPlugin,
2828
plugin.TaskMonitorPlugin,
29+
plugin.WarningPlugin,
2930
}
3031

3132
// loadV1Runtimes on FreeBSD returns an empty map. There are no v1 runtimes

services/tasks/local_unix.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ var tasksServiceRequires = []plugin.Type{
3232
plugin.RuntimePluginV2,
3333
plugin.MetadataPlugin,
3434
plugin.TaskMonitorPlugin,
35+
plugin.WarningPlugin,
3536
}
3637

3738
func loadV1Runtimes(ic *plugin.InitContext) (map[string]runtime.PlatformRuntime, error) {

services/tasks/local_windows.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ var tasksServiceRequires = []plugin.Type{
2626
plugin.RuntimePluginV2,
2727
plugin.MetadataPlugin,
2828
plugin.TaskMonitorPlugin,
29+
plugin.WarningPlugin,
2930
}
3031

3132
// loadV1Runtimes on Windows V2 returns an empty map. There are no v1 runtimes

0 commit comments

Comments
 (0)