Use proto.Marshal instead of calling Marshal() on objects

With google.golang.org/protobuf, proto-generated objects only have
ProtoReflect(). They don't have Marshal() anymore (see #6564).

Signed-off-by: Kazuyoshi Kato <katokazu@amazon.com>
This commit is contained in:
Kazuyoshi Kato 2022-04-20 06:07:43 +00:00
parent 95dde4959d
commit aa1526defc
5 changed files with 13 additions and 6 deletions

View File

@ -39,6 +39,7 @@ import (
"github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/pkg/process"
"github.com/containerd/containerd/protobuf"
"github.com/containerd/containerd/protobuf/proto"
ptypes "github.com/containerd/containerd/protobuf/types"
shimlog "github.com/containerd/containerd/runtime/v1"
"github.com/containerd/containerd/runtime/v1/shim"
@ -305,7 +306,7 @@ func (l *remoteEventsPublisher) Publish(ctx context.Context, topic string, event
if err != nil {
return err
}
data, err := encoded.Marshal()
data, err := proto.Marshal(encoded)
if err != nil {
return err
}

View File

@ -28,6 +28,7 @@ import (
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/pkg/dialer"
"github.com/containerd/containerd/protobuf/proto"
"github.com/containerd/containerd/protobuf/types"
"github.com/urfave/cli"
"google.golang.org/grpc"
@ -78,7 +79,7 @@ func getEventPayload(r io.Reader) (*types.Any, error) {
return nil, err
}
var any types.Any
if err := any.Unmarshal(data); err != nil {
if err := proto.Unmarshal(data, &any); err != nil {
return nil, err
}
return &any, nil

View File

@ -29,6 +29,7 @@ import (
"github.com/containerd/containerd/images"
"github.com/containerd/containerd/platforms"
"github.com/containerd/containerd/protobuf"
"github.com/containerd/containerd/protobuf/proto"
"github.com/containerd/containerd/rootfs"
"github.com/containerd/containerd/runtime/v2/runc/options"
"github.com/opencontainers/go-digest"
@ -79,7 +80,7 @@ func WithCheckpointTask(ctx context.Context, client *Client, c *containers.Conta
})
}
// save copts
data, err := any.Marshal()
data, err := proto.Marshal(any)
if err != nil {
return err
}
@ -99,7 +100,8 @@ func WithCheckpointTask(ctx context.Context, client *Client, c *containers.Conta
// WithCheckpointRuntime includes the container runtime info
func WithCheckpointRuntime(ctx context.Context, client *Client, c *containers.Container, index *imagespec.Index, copts *options.CheckpointOptions) error {
if c.Runtime.Options != nil && c.Runtime.Options.GetValue() != nil {
data, err := protobuf.FromAny(c.Runtime.Options).Marshal()
any := protobuf.FromAny(c.Runtime.Options)
data, err := proto.Marshal(any)
if err != nil {
return err
}

View File

@ -30,6 +30,7 @@ import (
"github.com/containerd/containerd/log"
"github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/protobuf"
"github.com/containerd/containerd/protobuf/proto"
"github.com/containerd/containerd/protobuf/types"
"github.com/containerd/containerd/runtime"
client "github.com/containerd/containerd/runtime/v2/shim"
@ -185,7 +186,7 @@ func (b *binary) Delete(ctx context.Context) (*runtime.Exit, error) {
log.G(ctx).Warnf("cleanup warnings %s", s)
}
var response task.DeleteResponse
if err := response.Unmarshal(out.Bytes()); err != nil {
if err := proto.Unmarshal(out.Bytes(), &response); err != nil {
return nil, err
}
if err := b.bundle.Delete(); err != nil {

View File

@ -42,6 +42,7 @@ import (
"github.com/containerd/containerd/pkg/timeout"
"github.com/containerd/containerd/plugin"
"github.com/containerd/containerd/protobuf"
"github.com/containerd/containerd/protobuf/proto"
ptypes "github.com/containerd/containerd/protobuf/types"
"github.com/containerd/containerd/runtime"
"github.com/containerd/containerd/runtime/linux/runctypes"
@ -579,7 +580,8 @@ func (l *local) Checkpoint(ctx context.Context, r *api.CheckpointTaskRequest, _
return nil, err
}
// write the config to the content store
data, err := protobuf.FromAny(container.Spec).Marshal()
pbany := protobuf.FromAny(container.Spec)
data, err := proto.Marshal(pbany)
if err != nil {
return nil, err
}