forked from containerd/containerd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request containerd#9258 from samuelkarp/introspection-depr…
…ecation-warning Expose usage of deprecated features
- Loading branch information
Showing
18 changed files
with
663 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.