Skip to content

Commit 03fed55

Browse files
committed
restart: containerd.io/restart.logpath warning
Signed-off-by: Samuel Karp <[email protected]>
1 parent 679b52e commit 03fed55

3 files changed

Lines changed: 30 additions & 4 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: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ import (
2323
"strconv"
2424
"syscall"
2525

26+
"github.com/sirupsen/logrus"
27+
2628
"github.com/containerd/containerd"
2729
"github.com/containerd/containerd/cio"
2830
"github.com/containerd/containerd/runtime/restart"
29-
"github.com/sirupsen/logrus"
3031
)
3132

3233
type stopChange struct {
@@ -44,6 +45,8 @@ type startChange struct {
4445

4546
// Deprecated(in release 1.5): but recognized now, prefer to use logURI
4647
logPath string
48+
// logPathCallback is a func invoked if logPath is defined, used for emitting deprecation warnings
49+
logPathCallback func()
4750
}
4851

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

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

runtime/restart/monitor/monitor.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@ import (
2323
"sync"
2424
"time"
2525

26+
"github.com/sirupsen/logrus"
27+
2628
"github.com/containerd/containerd"
2729
"github.com/containerd/containerd/namespaces"
30+
"github.com/containerd/containerd/pkg/deprecation"
2831
"github.com/containerd/containerd/plugin"
2932
"github.com/containerd/containerd/runtime/restart"
30-
"github.com/sirupsen/logrus"
33+
"github.com/containerd/containerd/services/warning"
3134
)
3235

3336
type duration struct {
@@ -56,6 +59,7 @@ func init() {
5659
Requires: []plugin.Type{
5760
plugin.EventPlugin,
5861
plugin.ServicePlugin,
62+
plugin.WarningPlugin,
5963
},
6064
ID: "restart",
6165
Config: &Config{
@@ -69,8 +73,14 @@ func init() {
6973
if err != nil {
7074
return nil, err
7175
}
76+
ws, err := ic.Get(plugin.WarningPlugin)
77+
if err != nil {
78+
return nil, err
79+
}
80+
warn := ws.(warning.Service)
7281
m := &monitor{
7382
client: client,
83+
warn: warn,
7484
}
7585
go m.run(ic.Config.(*Config).Interval.Duration)
7686
return m, nil
@@ -84,6 +94,7 @@ type change interface {
8494

8595
type monitor struct {
8696
client *containerd.Client
97+
warn warning.Service
8798
}
8899

89100
func (m *monitor) run(interval time.Duration) {
@@ -178,8 +189,12 @@ func (m *monitor) monitor(ctx context.Context) ([]change, error) {
178189
changes = append(changes, &startChange{
179190
container: c,
180191
logPath: labels[restart.LogPathLabel],
181-
logURI: labels[restart.LogURILabel],
182-
count: restartCount + 1,
192+
logPathCallback: func() {
193+
194+
m.warn.Emit(ctx, deprecation.RestartLogpath)
195+
},
196+
logURI: labels[restart.LogURILabel],
197+
count: restartCount + 1,
183198
})
184199
case containerd.Stopped:
185200
changes = append(changes, &stopChange{

0 commit comments

Comments
 (0)