From 03fed557e38f3cfeca0652607100c40c86806288 Mon Sep 17 00:00:00 2001 From: Samuel Karp Date: Wed, 20 Dec 2023 21:43:43 -0800 Subject: [PATCH] restart: containerd.io/restart.logpath warning Signed-off-by: Samuel Karp --- pkg/deprecation/deprecation.go | 3 +++ runtime/restart/monitor/change.go | 10 +++++++++- runtime/restart/monitor/monitor.go | 21 ++++++++++++++++++--- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/pkg/deprecation/deprecation.go b/pkg/deprecation/deprecation.go index 9b57a3e8208f..3d87b01de837 100644 --- a/pkg/deprecation/deprecation.go +++ b/pkg/deprecation/deprecation.go @@ -45,6 +45,8 @@ const ( CRIAPIV1Alpha2 Warning = Prefix + "cri-api-v1alpha2" // AUFSSnapshotter is a warning for the use of the aufs snapshotter AUFSSnapshotter Warning = Prefix + "aufs-snapshotter" + // RestartLogpath is a warning for the containerd.io/restart.logpath label + RestartLogpath Warning = Prefix + "restart-logpath" // RuntimeV1 is a warning for the io.containerd.runtime.v1.linux runtime RuntimeV1 Warning = Prefix + "runtime-v1" // RuntimeRuncV1 is a warning for the io.containerd.runc.v1 runtime @@ -75,6 +77,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.", + RestartLogpath: "The `containerd.io/restart.logpath` label is deprecated since containerd v1.5 and removed in containerd v2.0. Use `containerd.io/restart.loguri` 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.", RuntimeRuncV1: "The `io.containerd.runc.v1` runtime is deprecated since containerd v1.4 and removed in containerd v2.0. Use the `io.containerd.runc.v2` runtime instead.", CRICRIUPath: "The `CriuPath` property of `[plugins.\"io.containerd.grpc.v1.cri\".containerd.runtimes.*.options]` is deprecated since containerd v1.7 and will be removed in containerd v2.0. " + diff --git a/runtime/restart/monitor/change.go b/runtime/restart/monitor/change.go index 7188e0a72bd2..fe08b406e09f 100644 --- a/runtime/restart/monitor/change.go +++ b/runtime/restart/monitor/change.go @@ -23,10 +23,11 @@ import ( "strconv" "syscall" + "github.com/sirupsen/logrus" + "github.com/containerd/containerd" "github.com/containerd/containerd/cio" "github.com/containerd/containerd/runtime/restart" - "github.com/sirupsen/logrus" ) type stopChange struct { @@ -44,6 +45,8 @@ type startChange struct { // Deprecated(in release 1.5): but recognized now, prefer to use logURI logPath string + // logPathCallback is a func invoked if logPath is defined, used for emitting deprecation warnings + logPathCallback func() } func (s *startChange) apply(ctx context.Context, client *containerd.Client) error { @@ -58,6 +61,11 @@ func (s *startChange) apply(ctx context.Context, client *containerd.Client) erro } else if s.logPath != "" { log = cio.LogFile(s.logPath) } + if s.logPath != "" && s.logPathCallback != nil { + logrus.WithField("container", s.container.ID()).WithField(restart.LogPathLabel, s.logPath). + Warnf("%q label is deprecated in containerd v1.5 and will be removed in containerd v2.0. Use %q instead.", restart.LogPathLabel, restart.LogURILabel) + s.logPathCallback() + } if s.logURI != "" && s.logPath != "" { logrus.Warnf("LogPathLabel=%v has been deprecated, using LogURILabel=%v", diff --git a/runtime/restart/monitor/monitor.go b/runtime/restart/monitor/monitor.go index 315720d34f26..94e757239cd1 100644 --- a/runtime/restart/monitor/monitor.go +++ b/runtime/restart/monitor/monitor.go @@ -23,11 +23,14 @@ import ( "sync" "time" + "github.com/sirupsen/logrus" + "github.com/containerd/containerd" "github.com/containerd/containerd/namespaces" + "github.com/containerd/containerd/pkg/deprecation" "github.com/containerd/containerd/plugin" "github.com/containerd/containerd/runtime/restart" - "github.com/sirupsen/logrus" + "github.com/containerd/containerd/services/warning" ) type duration struct { @@ -56,6 +59,7 @@ func init() { Requires: []plugin.Type{ plugin.EventPlugin, plugin.ServicePlugin, + plugin.WarningPlugin, }, ID: "restart", Config: &Config{ @@ -69,8 +73,14 @@ func init() { if err != nil { return nil, err } + ws, err := ic.Get(plugin.WarningPlugin) + if err != nil { + return nil, err + } + warn := ws.(warning.Service) m := &monitor{ client: client, + warn: warn, } go m.run(ic.Config.(*Config).Interval.Duration) return m, nil @@ -84,6 +94,7 @@ type change interface { type monitor struct { client *containerd.Client + warn warning.Service } func (m *monitor) run(interval time.Duration) { @@ -178,8 +189,12 @@ func (m *monitor) monitor(ctx context.Context) ([]change, error) { changes = append(changes, &startChange{ container: c, logPath: labels[restart.LogPathLabel], - logURI: labels[restart.LogURILabel], - count: restartCount + 1, + logPathCallback: func() { + + m.warn.Emit(ctx, deprecation.RestartLogpath) + }, + logURI: labels[restart.LogURILabel], + count: restartCount + 1, }) case containerd.Stopped: changes = append(changes, &stopChange{