Skip to content

Commit

Permalink
tasks: emit warning for v1 runtime
Browse files Browse the repository at this point in the history
Signed-off-by: Samuel Karp <[email protected]>
(cherry picked from commit 329e1d4)
Signed-off-by: Samuel Karp <[email protected]>
  • Loading branch information
samuelkarp committed Dec 5, 2023
1 parent 183dbe4 commit 7825689
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 9 deletions.
3 changes: 3 additions & 0 deletions pkg/deprecation/deprecation.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const (
CRIAPIV1Alpha2 Warning = Prefix + "cri-api-v1alpha2"
// AUFSSnapshotter is a warning for the use of the aufs snapshotter
AUFSSnapshotter Warning = Prefix + "aufs-snapshotter"
// RuntimeV1 is a warning for the io.containerd.runtime.v1.linux runtime
RuntimeV1 Warning = Prefix + "runtime-v1"
)

var messages = map[Warning]string{
Expand All @@ -49,6 +51,7 @@ var messages = map[Warning]string{
"Use `config_path` instead.",
CRIAPIV1Alpha2: "CRI API v1alpha2 is deprecated since containerd v1.7 and removed in containerd v2.0. Use CRI API v1 instead.",
AUFSSnapshotter: "The aufs snapshotter is deprecated since containerd v1.5 and removed in containerd v2.0. Use the overlay snapshotter instead.",
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.",
}

// Valid checks whether a given Warning is valid
Expand Down
34 changes: 25 additions & 9 deletions services/tasks/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ import (
"strings"
"time"

"github.com/containerd/typeurl"
ptypes "github.com/gogo/protobuf/types"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

api "github.com/containerd/containerd/api/services/tasks/v1"
"github.com/containerd/containerd/api/types"
"github.com/containerd/containerd/api/types/task"
Expand All @@ -39,18 +46,14 @@ import (
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/metadata"
"github.com/containerd/containerd/mount"
"github.com/containerd/containerd/pkg/deprecation"
"github.com/containerd/containerd/pkg/timeout"
"github.com/containerd/containerd/plugin"
"github.com/containerd/containerd/runtime"
"github.com/containerd/containerd/runtime/linux/runctypes"
"github.com/containerd/containerd/runtime/v2/runc/options"
"github.com/containerd/containerd/services"
"github.com/containerd/typeurl"
ptypes "github.com/gogo/protobuf/types"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"github.com/containerd/containerd/services/warning"
)

var (
Expand Down Expand Up @@ -110,6 +113,11 @@ func initFunc(ic *plugin.InitContext) (interface{}, error) {
monitor = runtime.NewNoopMonitor()
}

w, err := ic.Get(plugin.WarningPlugin)
if err != nil {
return nil, err
}

db := m.(*metadata.DB)
l := &local{
runtimes: runtimes,
Expand All @@ -118,6 +126,7 @@ func initFunc(ic *plugin.InitContext) (interface{}, error) {
publisher: ep.(events.Publisher),
monitor: monitor.(runtime.TaskMonitor),
v2Runtime: v2r.(runtime.PlatformRuntime),
warnings: w.(warning.Service),
}
for _, r := range runtimes {
tasks, err := r.Tasks(ic.Context, true)
Expand Down Expand Up @@ -151,6 +160,7 @@ type local struct {

monitor runtime.TaskMonitor
v2Runtime runtime.PlatformRuntime
warnings warning.Service
}

func (l *local) Create(ctx context.Context, r *api.CreateTaskRequest, _ ...grpc.CallOption) (*api.CreateTaskResponse, error) {
Expand Down Expand Up @@ -209,11 +219,10 @@ func (l *local) Create(ctx context.Context, r *api.CreateTaskRequest, _ ...grpc.
Options: m.Options,
})
}
if strings.HasPrefix(container.Runtime.Name, "io.containerd.runtime.v1.") {
log.G(ctx).Warn("runtime v1 is deprecated since containerd v1.4, consider using runtime v2")
} else if container.Runtime.Name == plugin.RuntimeRuncV1 {
if container.Runtime.Name == plugin.RuntimeRuncV1 {
log.G(ctx).Warnf("%q is deprecated since containerd v1.4, consider using %q", plugin.RuntimeRuncV1, plugin.RuntimeRuncV2)
}
l.emitRuntimeWarning(ctx, container.Runtime.Name)
rtime, err := l.getRuntime(container.Runtime.Name)
if err != nil {
return nil, err
Expand Down Expand Up @@ -243,6 +252,13 @@ func (l *local) Create(ctx context.Context, r *api.CreateTaskRequest, _ ...grpc.
}, nil
}

func (l *local) emitRuntimeWarning(ctx context.Context, runtime string) {
switch runtime {
case plugin.RuntimeLinuxV1:
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)
l.warnings.Emit(ctx, deprecation.RuntimeV1)
}
}
func (l *local) Start(ctx context.Context, r *api.StartRequest, _ ...grpc.CallOption) (*api.StartResponse, error) {
t, err := l.getTask(ctx, r.ContainerID)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions services/tasks/local_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var tasksServiceRequires = []plugin.Type{
plugin.RuntimePluginV2,
plugin.MetadataPlugin,
plugin.TaskMonitorPlugin,
plugin.WarningPlugin,
}

// loadV1Runtimes on darwin returns an empty map. There are no v1 runtimes
Expand Down
1 change: 1 addition & 0 deletions services/tasks/local_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var tasksServiceRequires = []plugin.Type{
plugin.RuntimePluginV2,
plugin.MetadataPlugin,
plugin.TaskMonitorPlugin,
plugin.WarningPlugin,
}

// loadV1Runtimes on FreeBSD returns an empty map. There are no v1 runtimes
Expand Down
1 change: 1 addition & 0 deletions services/tasks/local_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var tasksServiceRequires = []plugin.Type{
plugin.RuntimePluginV2,
plugin.MetadataPlugin,
plugin.TaskMonitorPlugin,
plugin.WarningPlugin,
}

func loadV1Runtimes(ic *plugin.InitContext) (map[string]runtime.PlatformRuntime, error) {
Expand Down
1 change: 1 addition & 0 deletions services/tasks/local_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var tasksServiceRequires = []plugin.Type{
plugin.RuntimePluginV2,
plugin.MetadataPlugin,
plugin.TaskMonitorPlugin,
plugin.WarningPlugin,
}

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

0 comments on commit 7825689

Please sign in to comment.