Merge pull request #9807 from AkihiroSuda/ctr-print-deprecations
ctr: print deprecation warnings on every invocation
This commit is contained in:
commit
32169d591d
@ -18,10 +18,13 @@ package commands
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
gocontext "context"
|
gocontext "context"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
containerd "github.com/containerd/containerd/v2/client"
|
containerd "github.com/containerd/containerd/v2/client"
|
||||||
"github.com/containerd/containerd/v2/pkg/epoch"
|
"github.com/containerd/containerd/v2/pkg/epoch"
|
||||||
"github.com/containerd/containerd/v2/pkg/namespaces"
|
"github.com/containerd/containerd/v2/pkg/namespaces"
|
||||||
|
ptypes "github.com/containerd/containerd/v2/protobuf/types"
|
||||||
"github.com/containerd/log"
|
"github.com/containerd/log"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
@ -62,5 +65,22 @@ func NewClient(context *cli.Context, opts ...containerd.Opt) (*containerd.Client
|
|||||||
return nil, nil, nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
ctx, cancel := AppContext(context)
|
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
|
return client, ctx, cancel, nil
|
||||||
}
|
}
|
||||||
|
@ -47,6 +47,9 @@ var listCommand = cli.Command{
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
Action: func(context *cli.Context) error {
|
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)
|
client, ctx, cancel, err := commands.NewClient(context)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user