Skip to content

Commit eaebe23

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]> (cherry picked from commit 468bee9) (cherry-pick was not clean) Signed-off-by: Akihiro Suda <[email protected]>
1 parent 8e86a0b commit eaebe23

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

cmd/ctr/commands/client.go

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

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

2224
"github.com/containerd/containerd"
2325
"github.com/containerd/containerd/log"
2426
"github.com/containerd/containerd/namespaces"
2527
"github.com/containerd/containerd/pkg/epoch"
28+
ptypes "github.com/containerd/containerd/protobuf/types"
2629
"github.com/urfave/cli"
2730
)
2831

@@ -62,5 +65,22 @@ func NewClient(context *cli.Context, opts ...containerd.ClientOpt) (*containerd.
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)