Remove gogo/protobuf and adjust types
This commit migrates containerd/protobuf from github.com/gogo/protobuf to google.golang.org/protobuf and adjust types. Proto-generated structs cannot be passed as values. Fixes #6564. Signed-off-by: Kazuyoshi Kato <katokazu@amazon.com>
This commit is contained in:
parent
fd37cc75be
commit
e3db7de8f5
@ -36,7 +36,7 @@ func (c *criService) ListContainerStats(
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to build metrics request: %w", err)
|
||||
}
|
||||
resp, err := c.client.TaskService().Metrics(ctx, &request)
|
||||
resp, err := c.client.TaskService().Metrics(ctx, request)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to fetch metrics for tasks: %w", err)
|
||||
}
|
||||
@ -79,8 +79,8 @@ func (c *criService) normalizeContainerStatsFilter(filter *runtime.ContainerStat
|
||||
// the information in the stats request and the containerStore
|
||||
func (c *criService) buildTaskMetricsRequest(
|
||||
r *runtime.ListContainerStatsRequest,
|
||||
) (tasks.MetricsRequest, []containerstore.Container, error) {
|
||||
var req tasks.MetricsRequest
|
||||
) (*tasks.MetricsRequest, []containerstore.Container, error) {
|
||||
req := &tasks.MetricsRequest{}
|
||||
if r.GetFilter() == nil {
|
||||
return req, c.containerStore.List(), nil
|
||||
}
|
||||
|
@ -17,28 +17,28 @@
|
||||
package protobuf
|
||||
|
||||
import (
|
||||
"github.com/containerd/containerd/protobuf/types"
|
||||
"github.com/containerd/typeurl"
|
||||
"google.golang.org/protobuf/types/known/anypb"
|
||||
)
|
||||
|
||||
// FromAny converts typeurl.Any to github.com/containerd/containerd/protobuf/types.Any.
|
||||
func FromAny(from typeurl.Any) *types.Any {
|
||||
func FromAny(from typeurl.Any) *anypb.Any {
|
||||
if from == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if pbany, ok := from.(*types.Any); ok {
|
||||
if pbany, ok := from.(*anypb.Any); ok {
|
||||
return pbany
|
||||
}
|
||||
|
||||
return &types.Any{
|
||||
return &anypb.Any{
|
||||
TypeUrl: from.GetTypeUrl(),
|
||||
Value: from.GetValue(),
|
||||
}
|
||||
}
|
||||
|
||||
// FromAny converts an arbitrary interface to github.com/containerd/containerd/protobuf/types.Any.
|
||||
func MarshalAnyToProto(from interface{}) (*types.Any, error) {
|
||||
func MarshalAnyToProto(from interface{}) (*anypb.Any, error) {
|
||||
any, err := typeurl.MarshalAny(from)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -18,13 +18,13 @@
|
||||
package proto
|
||||
|
||||
import (
|
||||
gogo "github.com/gogo/protobuf/proto"
|
||||
google "google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
func Marshal(input gogo.Message) ([]byte, error) {
|
||||
return gogo.Marshal(input)
|
||||
func Marshal(input google.Message) ([]byte, error) {
|
||||
return google.Marshal(input)
|
||||
}
|
||||
|
||||
func Unmarshal(input []byte, output gogo.Message) error {
|
||||
return gogo.Unmarshal(input, output)
|
||||
func Unmarshal(input []byte, output google.Message) error {
|
||||
return google.Unmarshal(input, output)
|
||||
}
|
||||
|
@ -19,30 +19,18 @@ package protobuf
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/gogo/protobuf/types"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
)
|
||||
|
||||
// Once we migrate off from gogo/protobuf, we can use the function below, which don't return any errors.
|
||||
// https://github.com/protocolbuffers/protobuf-go/blob/v1.28.0/types/known/timestamppb/timestamp.pb.go#L200-L208
|
||||
|
||||
// ToTimestamp creates protobuf's Timestamp from time.Time.
|
||||
func ToTimestamp(from time.Time) *types.Timestamp {
|
||||
pt, err := types.TimestampProto(from)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return pt
|
||||
func ToTimestamp(from time.Time) *timestamppb.Timestamp {
|
||||
return timestamppb.New(from)
|
||||
}
|
||||
|
||||
// FromTimestamp creates time.Time from protobuf's Timestamp.
|
||||
func FromTimestamp(from *types.Timestamp) time.Time {
|
||||
if from == nil {
|
||||
// Return time.Time's zero value as like timestamppb.
|
||||
return time.Time{}.UTC()
|
||||
}
|
||||
tt, err := types.TimestampFromProto(from)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return tt
|
||||
func FromTimestamp(from *timestamppb.Timestamp) time.Time {
|
||||
return from.AsTime()
|
||||
}
|
||||
|
@ -18,9 +18,11 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
gogo "github.com/gogo/protobuf/types"
|
||||
"google.golang.org/genproto/protobuf/field_mask"
|
||||
"google.golang.org/protobuf/types/known/anypb"
|
||||
"google.golang.org/protobuf/types/known/emptypb"
|
||||
)
|
||||
|
||||
type Empty = gogo.Empty
|
||||
type Any = gogo.Any
|
||||
type FieldMask = gogo.FieldMask
|
||||
type Empty = emptypb.Empty
|
||||
type Any = anypb.Any
|
||||
type FieldMask = field_mask.FieldMask
|
||||
|
@ -449,13 +449,13 @@ func (s *Service) Checkpoint(ctx context.Context, r *shimapi.CheckpointTaskReque
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var options runctypes.CheckpointOptions
|
||||
var options *runctypes.CheckpointOptions
|
||||
if r.Options != nil {
|
||||
v, err := typeurl.UnmarshalAny(r.Options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
options = *v.(*runctypes.CheckpointOptions)
|
||||
options = v.(*runctypes.CheckpointOptions)
|
||||
}
|
||||
if err := p.(*process.Init).Checkpoint(ctx, &process.CheckpointConfig{
|
||||
Path: r.Path,
|
||||
@ -644,13 +644,13 @@ func getTopic(ctx context.Context, e interface{}) string {
|
||||
}
|
||||
|
||||
func newInit(ctx context.Context, path, workDir, runtimeRoot, namespace string, systemdCgroup bool, platform stdio.Platform, r *process.CreateConfig, rootfs string) (*process.Init, error) {
|
||||
var options runctypes.CreateOptions
|
||||
options := &runctypes.CreateOptions{}
|
||||
if r.Options != nil {
|
||||
v, err := typeurl.UnmarshalAny(r.Options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
options = *v.(*runctypes.CreateOptions)
|
||||
options = v.(*runctypes.CreateOptions)
|
||||
}
|
||||
|
||||
runtime := process.NewRunc(runtimeRoot, path, namespace, r.Runtime, systemdCgroup)
|
||||
|
@ -48,14 +48,14 @@ func NewContainer(ctx context.Context, platform stdio.Platform, r *task.CreateTa
|
||||
return nil, fmt.Errorf("create namespace: %w", err)
|
||||
}
|
||||
|
||||
var opts options.Options
|
||||
opts := &options.Options{}
|
||||
if r.Options.GetValue() != nil {
|
||||
v, err := typeurl.UnmarshalAny(r.Options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if v != nil {
|
||||
opts = *v.(*options.Options)
|
||||
opts = v.(*options.Options)
|
||||
}
|
||||
}
|
||||
|
||||
@ -123,7 +123,7 @@ func NewContainer(ctx context.Context, platform stdio.Platform, r *task.CreateTa
|
||||
ns,
|
||||
platform,
|
||||
config,
|
||||
&opts,
|
||||
opts,
|
||||
rootfs,
|
||||
)
|
||||
if err != nil {
|
||||
@ -188,7 +188,7 @@ func ReadOptions(path string) (*options.Options, error) {
|
||||
}
|
||||
|
||||
// WriteOptions writes the options information into the path
|
||||
func WriteOptions(path string, opts options.Options) error {
|
||||
func WriteOptions(path string, opts *options.Options) error {
|
||||
data, err := json.Marshal(opts)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -467,13 +467,13 @@ func (c *Container) Checkpoint(ctx context.Context, r *task.CheckpointTaskReques
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var opts options.CheckpointOptions
|
||||
var opts *options.CheckpointOptions
|
||||
if r.Options != nil {
|
||||
v, err := typeurl.UnmarshalAny(r.Options)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
opts = *v.(*options.CheckpointOptions)
|
||||
opts = v.(*options.CheckpointOptions)
|
||||
}
|
||||
return p.(*process.Init).Checkpoint(ctx, &process.CheckpointConfig{
|
||||
Path: r.Path,
|
||||
|
@ -29,8 +29,9 @@ import (
|
||||
"github.com/containerd/containerd/plugin"
|
||||
ptypes "github.com/containerd/containerd/protobuf/types"
|
||||
"github.com/containerd/containerd/services"
|
||||
"github.com/gogo/googleapis/google/rpc"
|
||||
"github.com/google/uuid"
|
||||
"google.golang.org/genproto/googleapis/rpc/code"
|
||||
rpc "google.golang.org/genproto/googleapis/rpc/status"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
@ -55,7 +56,7 @@ type Local struct {
|
||||
mu sync.Mutex
|
||||
root string
|
||||
plugins *plugin.Set
|
||||
pluginCache []api.Plugin
|
||||
pluginCache []*api.Plugin
|
||||
}
|
||||
|
||||
var _ = (api.IntrospectionClient)(&Local{})
|
||||
@ -79,7 +80,7 @@ func (l *Local) Plugins(ctx context.Context, req *api.PluginsRequest, _ ...grpc.
|
||||
for _, p := range allPlugins {
|
||||
p := p
|
||||
if filter.Match(adaptPlugin(p)) {
|
||||
plugins = append(plugins, &p)
|
||||
plugins = append(plugins, p)
|
||||
}
|
||||
}
|
||||
|
||||
@ -88,7 +89,7 @@ func (l *Local) Plugins(ctx context.Context, req *api.PluginsRequest, _ ...grpc.
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (l *Local) getPlugins() []api.Plugin {
|
||||
func (l *Local) getPlugins() []*api.Plugin {
|
||||
l.mu.Lock()
|
||||
defer l.mu.Unlock()
|
||||
plugins := l.plugins.GetAll()
|
||||
@ -148,7 +149,7 @@ func (l *Local) uuidPath() string {
|
||||
}
|
||||
|
||||
func adaptPlugin(o interface{}) filters.Adaptor {
|
||||
obj := o.(api.Plugin)
|
||||
obj := o.(*api.Plugin)
|
||||
return filters.AdapterFunc(func(fieldpath []string) (string, bool) {
|
||||
if len(fieldpath) == 0 {
|
||||
return "", false
|
||||
@ -174,8 +175,8 @@ func adaptPlugin(o interface{}) filters.Adaptor {
|
||||
})
|
||||
}
|
||||
|
||||
func pluginsToPB(plugins []*plugin.Plugin) []api.Plugin {
|
||||
var pluginsPB []api.Plugin
|
||||
func pluginsToPB(plugins []*plugin.Plugin) []*api.Plugin {
|
||||
var pluginsPB []*api.Plugin
|
||||
for _, p := range plugins {
|
||||
var platforms []*types.Platform
|
||||
for _, p := range p.Meta.Platforms {
|
||||
@ -209,13 +210,13 @@ func pluginsToPB(plugins []*plugin.Plugin) []api.Plugin {
|
||||
}
|
||||
} else {
|
||||
initErr = &rpc.Status{
|
||||
Code: int32(rpc.UNKNOWN),
|
||||
Code: int32(code.Code_UNKNOWN),
|
||||
Message: err.Error(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pluginsPB = append(pluginsPB, api.Plugin{
|
||||
pluginsPB = append(pluginsPB, &api.Plugin{
|
||||
Type: p.Registration.Type.String(),
|
||||
ID: p.Registration.ID,
|
||||
Requires: requires,
|
||||
|
Loading…
Reference in New Issue
Block a user