Skip to content

Commit

Permalink
Use proto.Marshal instead of calling Marshal() on objects
Browse files Browse the repository at this point in the history
With google.golang.org/protobuf, proto-generated objects only have
ProtoReflect(). They don't have Marshal() anymore (see containerd#6564).

Signed-off-by: Kazuyoshi Kato <[email protected]>
  • Loading branch information
kzys authored and Kirtana Ashok committed Jan 18, 2023
1 parent f23bd28 commit c90e09a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion cmd/containerd-shim/main_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/containerd/command/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions container_checkpoint_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion runtime/v2/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion services/tasks/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit c90e09a

Please sign in to comment.