Skip to content

Commit 468bee9

Browse files
committed
ctr: print deprecation warnings on every invocation
Print deprecation warnings on any ctr command, as users won't notice the deprecations until we actually remove the deprecated features. The warnings can be suppressed by setting `CONTAINERD_SUPPRESS_DEPRECATION_WARNINGS=1`. Signed-off-by: Akihiro Suda <[email protected]>
1 parent 2c7520d commit 468bee9

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

cmd/ctr/commands/client.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ package commands
1818

1919
import (
2020
gocontext "context"
21+
"os"
22+
"strconv"
2123

2224
containerd "github.com/containerd/containerd/v2/client"
2325
"github.com/containerd/containerd/v2/pkg/epoch"
2426
"github.com/containerd/containerd/v2/pkg/namespaces"
27+
ptypes "github.com/containerd/containerd/v2/protobuf/types"
2528
"github.com/containerd/log"
2629
"github.com/urfave/cli"
2730
)
@@ -62,5 +65,22 @@ func NewClient(context *cli.Context, opts ...containerd.Opt) (*containerd.Client
6265
return nil, nil, nil, err
6366
}
6467
ctx, cancel := AppContext(context)
68+
var suppressDeprecationWarnings bool
69+
if s := os.Getenv("CONTAINERD_SUPPRESS_DEPRECATION_WARNINGS"); s != "" {
70+
suppressDeprecationWarnings, err = strconv.ParseBool(s)
71+
if err != nil {
72+
log.L.WithError(err).Warn("Failed to parse CONTAINERD_SUPPRESS_DEPRECATION_WARNINGS=" + s)
73+
}
74+
}
75+
if !suppressDeprecationWarnings {
76+
resp, err := client.IntrospectionService().Server(ctx, &ptypes.Empty{})
77+
if err != nil {
78+
log.L.WithError(err).Warn("Failed to check deprecations")
79+
} else {
80+
for _, d := range resp.Deprecations {
81+
log.L.Warn("DEPRECATION: " + d.Message)
82+
}
83+
}
84+
}
6585
return client, ctx, cancel, nil
6686
}

cmd/ctr/commands/deprecations/deprecations.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ var listCommand = cli.Command{
4747
},
4848
},
4949
Action: func(context *cli.Context) error {
50+
// Suppress automatic warnings, since we print the warnings by ourselves.
51+
os.Setenv("CONTAINERD_SUPPRESS_DEPRECATION_WARNINGS", "1")
52+
5053
client, ctx, cancel, err := commands.NewClient(context)
5154
if err != nil {
5255
return err

0 commit comments

Comments
 (0)