Skip to content

Commit d24d263

Browse files
committed
restart: containerd.io/restart.logpath warning
Signed-off-by: Samuel Karp <[email protected]> (cherry picked from commit 03fed55) Signed-off-by: Samuel Karp <[email protected]>
1 parent 5c13c78 commit d24d263

3 files changed

Lines changed: 30 additions & 3 deletions

File tree

pkg/deprecation/deprecation.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ const (
4545
CRIAPIV1Alpha2 Warning = Prefix + "cri-api-v1alpha2"
4646
// AUFSSnapshotter is a warning for the use of the aufs snapshotter
4747
AUFSSnapshotter Warning = Prefix + "aufs-snapshotter"
48+
// RestartLogpath is a warning for the containerd.io/restart.logpath label
49+
RestartLogpath Warning = Prefix + "restart-logpath"
4850
// RuntimeV1 is a warning for the io.containerd.runtime.v1.linux runtime
4951
RuntimeV1 Warning = Prefix + "runtime-v1"
5052
// RuntimeRuncV1 is a warning for the io.containerd.runc.v1 runtime
@@ -75,6 +77,7 @@ var messages = map[Warning]string{
7577
"Use `config_path` instead.",
7678
CRIAPIV1Alpha2: "CRI API v1alpha2 is deprecated since containerd v1.7 and removed in containerd v2.0. Use CRI API v1 instead.",
7779
AUFSSnapshotter: "The aufs snapshotter is deprecated since containerd v1.5 and removed in containerd v2.0. Use the overlay snapshotter instead.",
80+
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.",
7881
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.",
7982
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.",
8083
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. " +

runtime/restart/monitor/change.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ import (
2222
"net/url"
2323
"syscall"
2424

25+
"github.com/sirupsen/logrus"
26+
2527
"github.com/containerd/containerd"
2628
"github.com/containerd/containerd/cio"
27-
"github.com/sirupsen/logrus"
29+
"github.com/containerd/containerd/runtime/restart"
2830
)
2931

3032
type stopChange struct {
@@ -41,6 +43,8 @@ type startChange struct {
4143

4244
// Deprecated(in release 1.5): but recognized now, prefer to use logURI
4345
logPath string
46+
// logPathCallback is a func invoked if logPath is defined, used for emitting deprecation warnings
47+
logPathCallback func()
4448
}
4549

4650
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
5559
} else if s.logPath != "" {
5660
log = cio.LogFile(s.logPath)
5761
}
62+
if s.logPath != "" && s.logPathCallback != nil {
63+
logrus.WithField("container", s.container.ID()).WithField(restart.LogPathLabel, s.logPath).
64+
Warnf("%q label is deprecated in containerd v1.5 and will be removed in containerd v2.0. Use %q instead.", restart.LogPathLabel, restart.LogURILabel)
65+
s.logPathCallback()
66+
}
5867

5968
if s.logURI != "" && s.logPath != "" {
6069
logrus.Warnf("LogPathLabel=%v has been deprecated, using LogURILabel=%v",

runtime/restart/monitor/monitor.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import (
2222
"sync"
2323
"time"
2424

25+
"github.com/sirupsen/logrus"
26+
2527
"github.com/containerd/containerd"
2628
containers "github.com/containerd/containerd/api/services/containers/v1"
2729
diff "github.com/containerd/containerd/api/services/diff/v1"
@@ -31,11 +33,12 @@ import (
3133
"github.com/containerd/containerd/content"
3234
"github.com/containerd/containerd/leases"
3335
"github.com/containerd/containerd/namespaces"
36+
"github.com/containerd/containerd/pkg/deprecation"
3437
"github.com/containerd/containerd/plugin"
3538
"github.com/containerd/containerd/runtime/restart"
3639
"github.com/containerd/containerd/services"
40+
"github.com/containerd/containerd/services/warning"
3741
"github.com/containerd/containerd/snapshots"
38-
"github.com/sirupsen/logrus"
3942
)
4043

4144
type duration struct {
@@ -64,6 +67,7 @@ func init() {
6467
Requires: []plugin.Type{
6568
plugin.EventPlugin,
6669
plugin.ServicePlugin,
70+
plugin.WarningPlugin,
6771
},
6872
ID: "restart",
6973
Config: &Config{
@@ -80,8 +84,14 @@ func init() {
8084
if err != nil {
8185
return nil, err
8286
}
87+
ws, err := ic.Get(plugin.WarningPlugin)
88+
if err != nil {
89+
return nil, err
90+
}
91+
warn := ws.(warning.Service)
8392
m := &monitor{
8493
client: client,
94+
warn: warn,
8595
}
8696
go m.run(ic.Config.(*Config).Interval.Duration)
8797
return m, nil
@@ -152,6 +162,7 @@ type change interface {
152162

153163
type monitor struct {
154164
client *containerd.Client
165+
warn warning.Service
155166
}
156167

157168
func (m *monitor) run(interval time.Duration) {
@@ -221,7 +232,11 @@ func (m *monitor) monitor(ctx context.Context) ([]change, error) {
221232
changes = append(changes, &startChange{
222233
container: c,
223234
logPath: labels[restart.LogPathLabel],
224-
logURI: labels[restart.LogURILabel],
235+
logPathCallback: func() {
236+
237+
m.warn.Emit(ctx, deprecation.RestartLogpath)
238+
},
239+
logURI: labels[restart.LogURILabel],
225240
})
226241
case containerd.Stopped:
227242
changes = append(changes, &stopChange{

0 commit comments

Comments
 (0)