From d24d263a42f51dca398070be1f8268fd53fe6cc9 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 (cherry picked from commit 03fed557e38f3cfeca0652607100c40c86806288) Signed-off-by: Samuel Karp --- pkg/deprecation/deprecation.go | 3 +++ runtime/restart/monitor/change.go | 11 ++++++++++- runtime/restart/monitor/monitor.go | 19 +++++++++++++++++-- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/pkg/deprecation/deprecation.go b/pkg/deprecation/deprecation.go index 8e24db8064e0d..19411a0d3e501 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 a74b3dcd1a336..ffe9f9c4efe9e 100644 --- a/runtime/restart/monitor/change.go +++ b/runtime/restart/monitor/change.go @@ -22,9 +22,11 @@ import ( "net/url" "syscall" + "github.com/sirupsen/logrus" + "github.com/containerd/containerd" "github.com/containerd/containerd/cio" - "github.com/sirupsen/logrus" + "github.com/containerd/containerd/runtime/restart" ) type stopChange struct { @@ -41,6 +43,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 { @@ -55,6 +59,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 a504ad9f4bf7a..05617d17a83b6 100644 --- a/runtime/restart/monitor/monitor.go +++ b/runtime/restart/monitor/monitor.go @@ -22,6 +22,8 @@ import ( "sync" "time" + "github.com/sirupsen/logrus" + "github.com/containerd/containerd" containers "github.com/containerd/containerd/api/services/containers/v1" diff "github.com/containerd/containerd/api/services/diff/v1" @@ -31,11 +33,12 @@ import ( "github.com/containerd/containerd/content" "github.com/containerd/containerd/leases" "github.com/containerd/containerd/namespaces" + "github.com/containerd/containerd/pkg/deprecation" "github.com/containerd/containerd/plugin" "github.com/containerd/containerd/runtime/restart" "github.com/containerd/containerd/services" + "github.com/containerd/containerd/services/warning" "github.com/containerd/containerd/snapshots" - "github.com/sirupsen/logrus" ) type duration struct { @@ -64,6 +67,7 @@ func init() { Requires: []plugin.Type{ plugin.EventPlugin, plugin.ServicePlugin, + plugin.WarningPlugin, }, ID: "restart", Config: &Config{ @@ -80,8 +84,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 @@ -152,6 +162,7 @@ type change interface { type monitor struct { client *containerd.Client + warn warning.Service } func (m *monitor) run(interval time.Duration) { @@ -221,7 +232,11 @@ func (m *monitor) monitor(ctx context.Context) ([]change, error) { changes = append(changes, &startChange{ container: c, logPath: labels[restart.LogPathLabel], - logURI: labels[restart.LogURILabel], + logPathCallback: func() { + + m.warn.Emit(ctx, deprecation.RestartLogpath) + }, + logURI: labels[restart.LogURILabel], }) case containerd.Stopped: changes = append(changes, &stopChange{