Skip to content

Commit

Permalink
Merge pull request containerd#9258 from samuelkarp/introspection-depr…
Browse files Browse the repository at this point in the history
…ecation-warning

Expose usage of deprecated features
  • Loading branch information
samuelkarp authored Oct 26, 2023
2 parents 82d7a69 + 3fff8b4 commit 332fbd9
Show file tree
Hide file tree
Showing 18 changed files with 663 additions and 131 deletions.
34 changes: 34 additions & 0 deletions api/next.pb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4344,6 +4344,7 @@ file {
dependency: "github.com/containerd/containerd/api/types/platform.proto"
dependency: "google/rpc/status.proto"
dependency: "google/protobuf/empty.proto"
dependency: "google/protobuf/timestamp.proto"
message_type {
name: "Plugin"
field {
Expand Down Expand Up @@ -4463,6 +4464,39 @@ file {
type: TYPE_UINT64
json_name: "pidns"
}
field {
name: "deprecations"
number: 4
label: LABEL_REPEATED
type: TYPE_MESSAGE
type_name: ".containerd.services.introspection.v1.DeprecationWarning"
json_name: "deprecations"
}
}
message_type {
name: "DeprecationWarning"
field {
name: "id"
number: 1
label: LABEL_OPTIONAL
type: TYPE_STRING
json_name: "id"
}
field {
name: "message"
number: 2
label: LABEL_OPTIONAL
type: TYPE_STRING
json_name: "message"
}
field {
name: "last_occurrence"
number: 3
label: LABEL_OPTIONAL
type: TYPE_MESSAGE
type_name: ".google.protobuf.Timestamp"
json_name: "lastOccurrence"
}
}
service {
name: "Introspection"
Expand Down
262 changes: 183 additions & 79 deletions api/services/introspection/v1/introspection.pb.go

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions api/services/introspection/v1/introspection.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package containerd.services.introspection.v1;
import "github.com/containerd/containerd/api/types/platform.proto";
import "google/rpc/status.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/timestamp.proto";

option go_package = "github.com/containerd/containerd/api/services/introspection/v1;introspection";

Expand Down Expand Up @@ -102,4 +103,11 @@ message ServerResponse {
string uuid = 1;
uint64 pid = 2;
uint64 pidns = 3; // PID namespace, such as 4026531836
repeated DeprecationWarning deprecations = 4;
}

message DeprecationWarning {
string id = 1;
string message = 2;
google.protobuf.Timestamp last_occurrence = 3;
}
1 change: 1 addition & 0 deletions cmd/containerd/builtins/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@ import (
_ "github.com/containerd/containerd/services/tasks"
_ "github.com/containerd/containerd/services/transfer"
_ "github.com/containerd/containerd/services/version"
_ "github.com/containerd/containerd/services/warning"
)
9 changes: 6 additions & 3 deletions cmd/ctr/app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@ import (
"fmt"
"io"

"github.com/containerd/log"
"github.com/urfave/cli"
"google.golang.org/grpc/grpclog"

"github.com/containerd/containerd/cmd/ctr/commands/containers"
"github.com/containerd/containerd/cmd/ctr/commands/content"
"github.com/containerd/containerd/cmd/ctr/commands/deprecations"
"github.com/containerd/containerd/cmd/ctr/commands/events"
"github.com/containerd/containerd/cmd/ctr/commands/images"
"github.com/containerd/containerd/cmd/ctr/commands/info"
Expand All @@ -39,9 +44,6 @@ import (
"github.com/containerd/containerd/defaults"
"github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/version"
"github.com/containerd/log"
"github.com/urfave/cli"
"google.golang.org/grpc/grpclog"
)

var extraCmds = []cli.Command{}
Expand Down Expand Up @@ -118,6 +120,7 @@ containerd CLI
ociCmd.Command,
sandboxes.Command,
info.Command,
deprecations.Command,
}, extraCmds...)
app.Before = func(context *cli.Context) error {
if context.GlobalBool("debug") {
Expand Down
113 changes: 113 additions & 0 deletions cmd/ctr/commands/deprecations/deprecations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
Copyright The containerd Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package deprecations

import (
"fmt"
"os"
"text/tabwriter"
"time"

"github.com/urfave/cli"

api "github.com/containerd/containerd/api/services/introspection/v1"
"github.com/containerd/containerd/cmd/ctr/commands"
"github.com/containerd/containerd/protobuf"
ptypes "github.com/containerd/containerd/protobuf/types"
)

// Command is the parent for all commands under "deprecations"
var Command = cli.Command{
Name: "deprecations",
Subcommands: []cli.Command{
listCommand,
},
}
var listCommand = cli.Command{
Name: "list",
Usage: "Print warnings for deprecations",
Flags: []cli.Flag{
cli.StringFlag{
Name: "format",
Usage: "output format to use (Examples: 'default', 'json')",
},
},
Action: func(context *cli.Context) error {
client, ctx, cancel, err := commands.NewClient(context)
if err != nil {
return err
}
defer cancel()

resp, err := client.IntrospectionService().Server(ctx, &ptypes.Empty{})
if err != nil {
return err
}
wrn := warnings(resp)
if len(wrn) > 0 {
switch context.String("format") {
case "json":
commands.PrintAsJSON(warnings(resp))
return nil
default:
w := tabwriter.NewWriter(os.Stdout, 4, 8, 4, ' ', 0)
fmt.Fprintln(w, "ID\tLAST OCCURRENCE\tMESSAGE\t")
for _, dw := range wrn {
if _, err := fmt.Fprintf(w, "%s\t%s\t%s\n",
dw.ID,
dw.LastOccurrence.Format(time.RFC3339Nano),
dw.Message,
); err != nil {
return err
}
}
return w.Flush()
}

}
return nil
},
}

type deprecationWarning struct {
ID string `json:"id"`
Message string `json:"message"`
LastOccurrence time.Time `json:"lastOccurrence"`
}

func warnings(in *api.ServerResponse) []deprecationWarning {
var warnings []deprecationWarning
for _, dw := range in.Deprecations {
wrn := deprecationWarningFromPB(dw)
if wrn == nil {
continue
}
warnings = append(warnings, *wrn)
}
return warnings
}
func deprecationWarningFromPB(in *api.DeprecationWarning) *deprecationWarning {
if in == nil {
return nil
}
lo := protobuf.FromTimestamp(in.LastOccurrence)
return &deprecationWarning{
ID: in.ID,
Message: in.Message,
LastOccurrence: lo,
}
}
21 changes: 21 additions & 0 deletions images/labels.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Copyright The containerd Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package images

const (
ConvertedDockerSchema1LabelKey = "io.containerd.image/converted-docker-schema1"
)
46 changes: 46 additions & 0 deletions pkg/deprecation/deprecation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
Copyright The containerd Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package deprecation

type Warning string

const (
// Prefix is a standard prefix for all Warnings, used for filtering plugin Exports
Prefix = "io.containerd.deprecation/"
// PullSchema1Image is a warning for the use of schema 1 images
PullSchema1Image Warning = Prefix + "pull-schema-1-image"
// GoPluginLibrary is a warning for the use of dynamic library Go plugins
GoPluginLibrary Warning = Prefix + "go-plugin-library"
)

var messages = map[Warning]string{
PullSchema1Image: "Schema 1 images are deprecated since containerd v1.7 and removed in containerd v2.0. " +
`Since containerd v1.7.8, schema 1 images are identified by the "io.containerd.image/converted-docker-schema1" label.`,
GoPluginLibrary: "Dynamically-linked Go plugins as containerd runtimes are deprecated since containerd v2.0 and removed in containerd v2.1.",
}

// Valid checks whether a given Warning is valid
func Valid(id Warning) bool {
_, ok := messages[id]
return ok
}

// Message returns the human-readable message for a given Warning
func Message(id Warning) (string, bool) {
msg, ok := messages[id]
return msg, ok
}
13 changes: 13 additions & 0 deletions plugin/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,19 @@ func (ps *Set) Get(t Type) (interface{}, error) {
return nil, fmt.Errorf("no plugins registered for %s: %w", t, ErrPluginNotFound)
}

// GetByID returns the plugin of the given type and ID
func (ps *Set) GetByID(t Type, id string) (*Plugin, error) {
typSet, ok := ps.byTypeAndID[t]
if !ok || len(typSet) == 0 {
return nil, fmt.Errorf("no plugins registered for %s: %w", t, ErrPluginNotFound)
}
p, ok := typSet[id]
if !ok {
return nil, fmt.Errorf("no plugins registered for %s %q: %w", t, id, ErrPluginNotFound)
}
return p, nil
}

// GetAll returns all initialized plugins
func (ps *Set) GetAll() []*Plugin {
return ps.ordered
Expand Down
2 changes: 1 addition & 1 deletion plugin/dynamic/dynamic.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import "fmt"
// Load is currently only implemented on non-static, non-gccgo builds for amd64
// and arm64, and plugins must be built with the exact same version of Go as
// containerd itself.
func Load(path string) (err error) {
func Load(path string) (loaded int, err error) {
defer func() {
if v := recover(); v != nil {
rerr, ok := v.(error)
Expand Down
17 changes: 10 additions & 7 deletions plugin/dynamic/dynamic_supported.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ import (
"runtime"
)

// loadPlugins loads all plugins for the OS and Arch
// that containerd is built for inside the provided path
func loadPlugins(path string) error {
// loadPlugins loads all plugins for the OS and Arch that containerd is built
// for inside the provided path and returns the count of successfully-loaded
// plugins
func loadPlugins(path string) (int, error) {
abs, err := filepath.Abs(path)
if err != nil {
return err
return 0, err
}
pattern := filepath.Join(abs, fmt.Sprintf(
"*-%s-%s.%s",
Expand All @@ -40,14 +41,16 @@ func loadPlugins(path string) error {
))
libs, err := filepath.Glob(pattern)
if err != nil {
return err
return 0, err
}
loaded := 0
for _, lib := range libs {
if _, err := plugin.Open(lib); err != nil {
return err
return loaded, err
}
loaded++
}
return nil
return loaded, nil
}

// getLibExt returns a platform specific lib extension for
Expand Down
4 changes: 2 additions & 2 deletions plugin/dynamic/dynamic_unsupported.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ package dynamic
// - with gccgo: gccgo has no plugin support golang/go#36403
// - on static builds; https://github.com/containerd/containerd/commit/0d682e24a1ba8e93e5e54a73d64f7d256f87492f
// - on architectures other than amd64 and arm64 (other architectures need to be tested)
func loadPlugins(path string) error {
return nil
func loadPlugins(path string) (int, error) {
return 0, nil
}
4 changes: 4 additions & 0 deletions plugins/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,15 @@ const (
SandboxControllerPlugin plugin.Type = "io.containerd.sandbox.controller.v1"
// ImageVerifierPlugin implements an image verifier service
ImageVerifierPlugin plugin.Type = "io.containerd.image-verifier.v1"
// WarningPlugin implements a warning service
WarningPlugin plugin.Type = "io.containerd.warning.v1"
)

const (
// RuntimeRuncV2 is the runc runtime that supports multiple containers per shim
RuntimeRuncV2 = "io.containerd.runc.v2"

DeprecationsPlugin = "deprecations"
)

const (
Expand Down
Loading

0 comments on commit 332fbd9

Please sign in to comment.