Skip to content

Commit

Permalink
ctr: print deprecation warnings on every invocation
Browse files Browse the repository at this point in the history
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 <akihiro.suda.cz@hco.ntt.co.jp>
(cherry picked from commit 468bee9)
(cherry-pick was not clean)
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
  • Loading branch information
AkihiroSuda committed Feb 14, 2024
1 parent 8e86a0b commit eaebe23
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
20 changes: 20 additions & 0 deletions cmd/ctr/commands/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ package commands

import (
gocontext "context"
"os"
"strconv"

"github.com/containerd/containerd"
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/pkg/epoch"
ptypes "github.com/containerd/containerd/protobuf/types"
"github.com/urfave/cli"
)

Expand Down Expand Up @@ -62,5 +65,22 @@ func NewClient(context *cli.Context, opts ...containerd.ClientOpt) (*containerd.
return nil, nil, nil, err
}
ctx, cancel := AppContext(context)
var suppressDeprecationWarnings bool
if s := os.Getenv("CONTAINERD_SUPPRESS_DEPRECATION_WARNINGS"); s != "" {
suppressDeprecationWarnings, err = strconv.ParseBool(s)
if err != nil {
log.L.WithError(err).Warn("Failed to parse CONTAINERD_SUPPRESS_DEPRECATION_WARNINGS=" + s)
}
}
if !suppressDeprecationWarnings {
resp, err := client.IntrospectionService().Server(ctx, &ptypes.Empty{})
if err != nil {
log.L.WithError(err).Warn("Failed to check deprecations")
} else {
for _, d := range resp.Deprecations {
log.L.Warn("DEPRECATION: " + d.Message)
}
}
}
return client, ctx, cancel, nil
}
3 changes: 3 additions & 0 deletions cmd/ctr/commands/deprecations/deprecations.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ var listCommand = cli.Command{
},
},
Action: func(context *cli.Context) error {
// Suppress automatic warnings, since we print the warnings by ourselves.
os.Setenv("CONTAINERD_SUPPRESS_DEPRECATION_WARNINGS", "1")

client, ctx, cancel, err := commands.NewClient(context)
if err != nil {
return err
Expand Down

0 comments on commit eaebe23

Please sign in to comment.