Skip to content

Commit

Permalink
restart: containerd.io/restart.logpath warning
Browse files Browse the repository at this point in the history
Signed-off-by: Samuel Karp <samuelkarp@google.com>
  • Loading branch information
samuelkarp committed Dec 21, 2023
1 parent 679b52e commit 03fed55
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
3 changes: 3 additions & 0 deletions pkg/deprecation/deprecation.go
Expand Up @@ -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
Expand Down Expand Up @@ -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. " +
Expand Down
10 changes: 9 additions & 1 deletion runtime/restart/monitor/change.go
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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",
Expand Down
21 changes: 18 additions & 3 deletions runtime/restart/monitor/monitor.go
Expand Up @@ -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 {
Expand Down Expand Up @@ -56,6 +59,7 @@ func init() {
Requires: []plugin.Type{
plugin.EventPlugin,
plugin.ServicePlugin,
plugin.WarningPlugin,
},
ID: "restart",
Config: &Config{
Expand All @@ -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
Expand All @@ -84,6 +94,7 @@ type change interface {

type monitor struct {
client *containerd.Client
warn warning.Service
}

func (m *monitor) run(interval time.Duration) {
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 03fed55

Please sign in to comment.