diff --git a/client/client.go b/client/client.go index 7c64dfe83cb0..13b210de457f 100644 --- a/client/client.go +++ b/client/client.go @@ -55,7 +55,6 @@ import ( "github.com/containerd/containerd/v2/defaults" "github.com/containerd/containerd/v2/pkg/dialer" "github.com/containerd/containerd/v2/pkg/namespaces" - "github.com/containerd/containerd/v2/pkg/protobuf" ptypes "github.com/containerd/containerd/v2/pkg/protobuf/types" "github.com/containerd/containerd/v2/plugins" "github.com/containerd/errdefs" @@ -898,7 +897,7 @@ func (c *Client) RuntimeInfo(ctx context.Context, runtimePath string, runtimeOpt } var err error if runtimeOptions != nil { - rr.Options, err = protobuf.MarshalAnyToProto(runtimeOptions) + rr.Options, err = typeurl.MarshalAnyToProto(runtimeOptions) if err != nil { return nil, fmt.Errorf("failed to marshal %T: %w", runtimeOptions, err) } diff --git a/client/container.go b/client/container.go index 320f419b7cb6..41fe63ffa9e4 100644 --- a/client/container.go +++ b/client/container.go @@ -32,7 +32,6 @@ import ( "github.com/containerd/containerd/v2/core/images" "github.com/containerd/containerd/v2/pkg/cio" "github.com/containerd/containerd/v2/pkg/oci" - "github.com/containerd/containerd/v2/pkg/protobuf" "github.com/containerd/errdefs" "github.com/containerd/fifo" "github.com/containerd/typeurl/v2" @@ -288,7 +287,7 @@ func (c *container) NewTask(ctx context.Context, ioCreate cio.Creator, opts ...N if err != nil { return nil, err } - request.Options = protobuf.FromAny(o) + request.Options = typeurl.MarshalProto(o) } t := &task{ client: c.client, diff --git a/client/container_checkpoint_opts.go b/client/container_checkpoint_opts.go index bb07c77ee05e..4edb937f6261 100644 --- a/client/container_checkpoint_opts.go +++ b/client/container_checkpoint_opts.go @@ -28,10 +28,10 @@ import ( "github.com/containerd/containerd/v2/core/containers" "github.com/containerd/containerd/v2/core/diff" "github.com/containerd/containerd/v2/core/images" - "github.com/containerd/containerd/v2/pkg/protobuf" "github.com/containerd/containerd/v2/pkg/protobuf/proto" "github.com/containerd/containerd/v2/pkg/rootfs" "github.com/containerd/platforms" + "github.com/containerd/typeurl/v2" "github.com/opencontainers/go-digest" imagespec "github.com/opencontainers/image-spec/specs-go/v1" ) @@ -54,7 +54,7 @@ func WithCheckpointImage(ctx context.Context, client *Client, c *containers.Cont // WithCheckpointTask includes the running task func WithCheckpointTask(ctx context.Context, client *Client, c *containers.Container, index *imagespec.Index, copts *options.CheckpointOptions) error { - opt, err := protobuf.MarshalAnyToProto(copts) + opt, err := typeurl.MarshalAnyToProto(copts) if err != nil { return nil } @@ -96,7 +96,7 @@ 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 { - opt := protobuf.FromAny(c.Runtime.Options) + opt := typeurl.MarshalProto(c.Runtime.Options) data, err := proto.Marshal(opt) if err != nil { return err diff --git a/client/container_opts.go b/client/container_opts.go index cf5508877c77..04f2a9062114 100644 --- a/client/container_opts.go +++ b/client/container_opts.go @@ -28,7 +28,6 @@ import ( "github.com/containerd/containerd/v2/core/snapshots" "github.com/containerd/containerd/v2/pkg/namespaces" "github.com/containerd/containerd/v2/pkg/oci" - "github.com/containerd/containerd/v2/pkg/protobuf" "github.com/containerd/errdefs" "github.com/containerd/typeurl/v2" "github.com/opencontainers/image-spec/identity" @@ -321,7 +320,7 @@ func WithSpec(s *oci.Spec, opts ...oci.SpecOpts) NewContainerOpts { } var err error - c.Spec, err = protobuf.MarshalAnyToProto(s) + c.Spec, err = typeurl.MarshalAnyToProto(s) return err } } diff --git a/client/containerstore.go b/client/containerstore.go index a41cec086df2..0d5661422f6d 100644 --- a/client/containerstore.go +++ b/client/containerstore.go @@ -152,7 +152,7 @@ func (r *remoteContainers) Delete(ctx context.Context, id string) error { func containerToProto(container *containers.Container) *containersapi.Container { extensions := make(map[string]*ptypes.Any) for k, v := range container.Extensions { - extensions[k] = protobuf.FromAny(v) + extensions[k] = typeurl.MarshalProto(v) } return &containersapi.Container{ ID: container.ID, @@ -160,9 +160,9 @@ func containerToProto(container *containers.Container) *containersapi.Container Image: container.Image, Runtime: &containersapi.Container_Runtime{ Name: container.Runtime.Name, - Options: protobuf.FromAny(container.Runtime.Options), + Options: typeurl.MarshalProto(container.Runtime.Options), }, - Spec: protobuf.FromAny(container.Spec), + Spec: typeurl.MarshalProto(container.Spec), Snapshotter: container.Snapshotter, SnapshotKey: container.SnapshotKey, Extensions: extensions, diff --git a/client/events.go b/client/events.go index 7d42ed84962d..afba8072b266 100644 --- a/client/events.go +++ b/client/events.go @@ -53,7 +53,7 @@ func (e *eventRemote) Publish(ctx context.Context, topic string, event events.Ev } req := &eventsapi.PublishRequest{ Topic: topic, - Event: protobuf.FromAny(evt), + Event: typeurl.MarshalProto(evt), } if _, err := e.client.Publish(ctx, req); err != nil { return errdefs.FromGRPC(err) @@ -67,7 +67,7 @@ func (e *eventRemote) Forward(ctx context.Context, envelope *events.Envelope) er Timestamp: protobuf.ToTimestamp(envelope.Timestamp), Namespace: envelope.Namespace, Topic: envelope.Topic, - Event: protobuf.FromAny(envelope.Event), + Event: typeurl.MarshalProto(envelope.Event), }, } if _, err := e.client.Forward(ctx, req); err != nil { diff --git a/client/task.go b/client/task.go index a60f33e4c2aa..236ae4691e2e 100644 --- a/client/task.go +++ b/client/task.go @@ -363,7 +363,7 @@ func (t *task) Exec(ctx context.Context, id string, spec *specs.Process, ioCreat i.Close() } }() - pSpec, err := protobuf.MarshalAnyToProto(spec) + pSpec, err := typeurl.MarshalAnyToProto(spec) if err != nil { return nil, err } @@ -463,7 +463,7 @@ func (t *task) Checkpoint(ctx context.Context, opts ...CheckpointTaskOpts) (Imag } request.ParentCheckpoint = i.ParentCheckpoint.String() if i.Options != nil { - o, err := protobuf.MarshalAnyToProto(i.Options) + o, err := typeurl.MarshalAnyToProto(i.Options) if err != nil { return nil, err } @@ -552,7 +552,7 @@ func (t *task) Update(ctx context.Context, opts ...UpdateTaskOpts) error { if err != nil { return err } - request.Resources = protobuf.FromAny(r) + request.Resources = typeurl.MarshalProto(r) } if i.Annotations != nil { request.Annotations = i.Annotations diff --git a/cmd/containerd-shim-runc-v2/manager/manager_linux.go b/cmd/containerd-shim-runc-v2/manager/manager_linux.go index ccf7e0d65287..e714fdf81eb9 100644 --- a/cmd/containerd-shim-runc-v2/manager/manager_linux.go +++ b/cmd/containerd-shim-runc-v2/manager/manager_linux.go @@ -41,13 +41,13 @@ import ( "github.com/containerd/containerd/v2/core/mount" "github.com/containerd/containerd/v2/pkg/namespaces" "github.com/containerd/containerd/v2/pkg/oci" - "github.com/containerd/containerd/v2/pkg/protobuf" "github.com/containerd/containerd/v2/pkg/schedcore" "github.com/containerd/containerd/v2/pkg/shim" "github.com/containerd/containerd/v2/version" "github.com/containerd/errdefs" runcC "github.com/containerd/go-runc" "github.com/containerd/log" + "github.com/containerd/typeurl/v2" "github.com/opencontainers/runtime-spec/specs-go/features" "golang.org/x/sys/unix" ) @@ -342,7 +342,7 @@ func (m manager) Info(ctx context.Context, optionsR io.Reader) (*types.RuntimeIn } } if opts != nil { - info.Options, err = protobuf.MarshalAnyToProto(opts) + info.Options, err = typeurl.MarshalAnyToProto(opts) if err != nil { return nil, fmt.Errorf("failed to marshal %T: %w", opts, err) } @@ -362,7 +362,7 @@ func (m manager) Info(ctx context.Context, optionsR io.Reader) (*types.RuntimeIn log.G(ctx).WithError(err).Debug("Failed to get the runtime features. The runc binary does not implement `runc features` command?") } if features != nil { - info.Features, err = protobuf.MarshalAnyToProto(features) + info.Features, err = typeurl.MarshalAnyToProto(features) if err != nil { return nil, fmt.Errorf("failed to marshal %T: %w", features, err) } diff --git a/cmd/containerd-shim-runc-v2/task/service.go b/cmd/containerd-shim-runc-v2/task/service.go index 00e4860547e1..d78dbb2e6102 100644 --- a/cmd/containerd-shim-runc-v2/task/service.go +++ b/cmd/containerd-shim-runc-v2/task/service.go @@ -526,7 +526,7 @@ func (s *service) Pids(ctx context.Context, r *taskAPI.PidsRequest) (*taskAPI.Pi d := &options.ProcessDetails{ ExecID: p.ID(), } - a, err := protobuf.MarshalAnyToProto(d) + a, err := typeurl.MarshalAnyToProto(d) if err != nil { return nil, fmt.Errorf("failed to marshal process %d info: %w", pid, err) } @@ -654,7 +654,7 @@ func (s *service) Stats(ctx context.Context, r *taskAPI.StatsRequest) (*taskAPI. return nil, err } return &taskAPI.StatsResponse{ - Stats: protobuf.FromAny(data), + Stats: typeurl.MarshalProto(data), }, nil } diff --git a/core/diff/proxy/differ.go b/core/diff/proxy/differ.go index da18e648ff16..ceb631edae10 100644 --- a/core/diff/proxy/differ.go +++ b/core/diff/proxy/differ.go @@ -24,11 +24,10 @@ import ( "github.com/containerd/containerd/v2/core/mount" "github.com/containerd/containerd/v2/pkg/epoch" "github.com/containerd/containerd/v2/pkg/oci" - "github.com/containerd/containerd/v2/pkg/protobuf" ptypes "github.com/containerd/containerd/v2/pkg/protobuf/types" "github.com/containerd/errdefs" + "github.com/containerd/typeurl/v2" ocispec "github.com/opencontainers/image-spec/specs-go/v1" - "google.golang.org/protobuf/types/known/timestamppb" ) @@ -54,7 +53,7 @@ func (r *diffRemote) Apply(ctx context.Context, desc ocispec.Descriptor, mounts payloads := make(map[string]*ptypes.Any) for k, v := range config.ProcessorPayloads { - payloads[k] = protobuf.FromAny(v) + payloads[k] = typeurl.MarshalProto(v) } req := &diffapi.ApplyRequest{ diff --git a/core/diff/stream_unix.go b/core/diff/stream_unix.go index b4b6f1a7d6a5..28ef3b45b92d 100644 --- a/core/diff/stream_unix.go +++ b/core/diff/stream_unix.go @@ -28,7 +28,6 @@ import ( "os/exec" "sync" - "github.com/containerd/containerd/v2/pkg/protobuf" "github.com/containerd/containerd/v2/pkg/protobuf/proto" "github.com/containerd/typeurl/v2" ) @@ -41,7 +40,7 @@ func NewBinaryProcessor(ctx context.Context, imt, rmt string, stream StreamProce var payloadC io.Closer if payload != nil { - pb := protobuf.FromAny(payload) + pb := typeurl.MarshalProto(payload) data, err := proto.Marshal(pb) if err != nil { return nil, err diff --git a/core/diff/stream_windows.go b/core/diff/stream_windows.go index 73ad2046c6a8..4f068cfc1500 100644 --- a/core/diff/stream_windows.go +++ b/core/diff/stream_windows.go @@ -29,7 +29,6 @@ import ( "github.com/Microsoft/go-winio" - "github.com/containerd/containerd/v2/pkg/protobuf" "github.com/containerd/containerd/v2/pkg/protobuf/proto" "github.com/containerd/log" "github.com/containerd/typeurl/v2" @@ -44,7 +43,7 @@ func NewBinaryProcessor(ctx context.Context, imt, rmt string, stream StreamProce cmd.Env = append(cmd.Env, env...) if payload != nil { - pb := protobuf.FromAny(payload) + pb := typeurl.MarshalProto(payload) data, err := proto.Marshal(pb) if err != nil { return nil, err diff --git a/core/events/proxy/remote_events.go b/core/events/proxy/remote_events.go index 23252c13494d..eb8a01271e06 100644 --- a/core/events/proxy/remote_events.go +++ b/core/events/proxy/remote_events.go @@ -70,7 +70,7 @@ func (p *grpcEventsProxy) Publish(ctx context.Context, topic string, event event } req := &api.PublishRequest{ Topic: topic, - Event: protobuf.FromAny(evt), + Event: typeurl.MarshalProto(evt), } if _, err := p.client.Publish(ctx, req); err != nil { return errdefs.FromGRPC(err) @@ -84,7 +84,7 @@ func (p *grpcEventsProxy) Forward(ctx context.Context, envelope *events.Envelope Timestamp: protobuf.ToTimestamp(envelope.Timestamp), Namespace: envelope.Namespace, Topic: envelope.Topic, - Event: protobuf.FromAny(envelope.Event), + Event: typeurl.MarshalProto(envelope.Event), }, } if _, err := p.client.Forward(ctx, req); err != nil { @@ -151,7 +151,7 @@ func (p *ttrpcEventsProxy) Publish(ctx context.Context, topic string, event even } req := &api.PublishRequest{ Topic: topic, - Event: protobuf.FromAny(evt), + Event: typeurl.MarshalProto(evt), } if _, err := p.client.Publish(ctx, req); err != nil { return errdefs.FromGRPC(err) @@ -165,7 +165,7 @@ func (p *ttrpcEventsProxy) Forward(ctx context.Context, envelope *events.Envelop Timestamp: protobuf.ToTimestamp(envelope.Timestamp), Namespace: envelope.Namespace, Topic: envelope.Topic, - Event: protobuf.FromAny(envelope.Event), + Event: typeurl.MarshalProto(envelope.Event), }, } if _, err := p.client.Forward(ctx, req); err != nil { diff --git a/core/introspection/proxy/remote.go b/core/introspection/proxy/remote.go index 4bb3bae69000..ad26c6cb6075 100644 --- a/core/introspection/proxy/remote.go +++ b/core/introspection/proxy/remote.go @@ -22,10 +22,10 @@ import ( api "github.com/containerd/containerd/api/services/introspection/v1" "github.com/containerd/containerd/v2/core/introspection" - "github.com/containerd/containerd/v2/pkg/protobuf" "github.com/containerd/errdefs" "github.com/containerd/log" "github.com/containerd/ttrpc" + "github.com/containerd/typeurl/v2" "google.golang.org/grpc" "google.golang.org/protobuf/types/known/anypb" "google.golang.org/protobuf/types/known/emptypb" @@ -79,7 +79,7 @@ func (i *introspectionRemote) Server(ctx context.Context) (*api.ServerResponse, func (i *introspectionRemote) PluginInfo(ctx context.Context, pluginType, id string, options any) (resp *api.PluginInfoResponse, err error) { var optionsPB *anypb.Any if options != nil { - optionsPB, err = protobuf.MarshalAnyToProto(options) + optionsPB, err = typeurl.MarshalAnyToProto(options) if err != nil { return nil, fmt.Errorf("failed to marshal runtime requst: %w", err) } diff --git a/core/metadata/boltutil/helpers.go b/core/metadata/boltutil/helpers.go index 3b081c3f9bfa..30df2e7a91f2 100644 --- a/core/metadata/boltutil/helpers.go +++ b/core/metadata/boltutil/helpers.go @@ -20,7 +20,6 @@ import ( "fmt" "time" - "github.com/containerd/containerd/v2/pkg/protobuf" "github.com/containerd/containerd/v2/pkg/protobuf/proto" "github.com/containerd/containerd/v2/pkg/protobuf/types" "github.com/containerd/typeurl/v2" @@ -164,7 +163,7 @@ func WriteExtensions(bkt *bolt.Bucket, extensions map[string]typeurl.Any) error } for name, ext := range extensions { - ext := protobuf.FromAny(ext) + ext := typeurl.MarshalProto(ext) p, err := proto.Marshal(ext) if err != nil { return err @@ -206,7 +205,7 @@ func ReadExtensions(bkt *bolt.Bucket) (map[string]typeurl.Any, error) { // WriteAny write a protobuf's Any type to the bucket func WriteAny(bkt *bolt.Bucket, name []byte, any typeurl.Any) error { - pbany := protobuf.FromAny(any) + pbany := typeurl.MarshalProto(any) if pbany == nil { return nil } diff --git a/core/metadata/containers_test.go b/core/metadata/containers_test.go index 0cc7eb595a12..fdebd52901b6 100644 --- a/core/metadata/containers_test.go +++ b/core/metadata/containers_test.go @@ -28,7 +28,6 @@ import ( "github.com/containerd/containerd/v2/core/containers" "github.com/containerd/containerd/v2/pkg/filters" "github.com/containerd/containerd/v2/pkg/namespaces" - "github.com/containerd/containerd/v2/pkg/protobuf" "github.com/containerd/containerd/v2/pkg/protobuf/types" "github.com/containerd/errdefs" "github.com/containerd/log/logtest" @@ -48,7 +47,7 @@ func TestContainersList(t *testing.T) { ctx, db := testEnv(t) store := NewContainerStore(NewDB(db, nil, nil)) spec := &specs.Spec{} - encoded, err := protobuf.MarshalAnyToProto(spec) + encoded, err := typeurl.MarshalAnyToProto(spec) require.NoError(t, err) testset := map[string]*containers.Container{} @@ -178,11 +177,11 @@ func TestContainersCreateUpdateDelete(t *testing.T) { spec = &specs.Spec{} ) - encoded, err := protobuf.MarshalAnyToProto(spec) + encoded, err := typeurl.MarshalAnyToProto(spec) require.NoError(t, err) spec.Annotations = map[string]string{"updated": "true"} - encodedUpdated, err := protobuf.MarshalAnyToProto(spec) + encodedUpdated, err := typeurl.MarshalAnyToProto(spec) require.NoError(t, err) for _, testcase := range []struct { diff --git a/core/metrics/cgroups/metrics_test.go b/core/metrics/cgroups/metrics_test.go index c1c1f7108fe1..85836be9f45a 100644 --- a/core/metrics/cgroups/metrics_test.go +++ b/core/metrics/cgroups/metrics_test.go @@ -31,11 +31,10 @@ import ( v2 "github.com/containerd/containerd/v2/core/metrics/cgroups/v2" v1types "github.com/containerd/containerd/v2/core/metrics/types/v1" v2types "github.com/containerd/containerd/v2/core/metrics/types/v2" - "github.com/containerd/containerd/v2/pkg/protobuf" - "github.com/prometheus/client_golang/prometheus" - "github.com/containerd/containerd/v2/pkg/protobuf/types" + "github.com/containerd/typeurl/v2" metrics "github.com/docker/go-metrics" + "github.com/prometheus/client_golang/prometheus" ) // TestRegressionIssue6772 should not have dead-lock when Collect and Add run @@ -151,7 +150,7 @@ func (t *mockStatT) Namespace() string { func (t *mockStatT) Stats(context.Context) (*types.Any, error) { if t.isV1 { - return protobuf.MarshalAnyToProto(&v1types.Metrics{}) + return typeurl.MarshalAnyToProto(&v1types.Metrics{}) } - return protobuf.MarshalAnyToProto(&v2types.Metrics{}) + return typeurl.MarshalAnyToProto(&v2types.Metrics{}) } diff --git a/core/runtime/v2/shim.go b/core/runtime/v2/shim.go index 037d6714d6ca..0b6ed3432b13 100644 --- a/core/runtime/v2/shim.go +++ b/core/runtime/v2/shim.go @@ -28,9 +28,6 @@ import ( "strings" "time" - "github.com/containerd/containerd/v2/pkg/atomicfile" - "github.com/containerd/containerd/v2/pkg/dialer" - "github.com/containerd/ttrpc" "google.golang.org/grpc" "google.golang.org/grpc/connectivity" "google.golang.org/grpc/credentials/insecure" @@ -40,6 +37,8 @@ import ( "github.com/containerd/containerd/api/types" "github.com/containerd/containerd/v2/core/events/exchange" "github.com/containerd/containerd/v2/core/runtime" + "github.com/containerd/containerd/v2/pkg/atomicfile" + "github.com/containerd/containerd/v2/pkg/dialer" "github.com/containerd/containerd/v2/pkg/identifiers" "github.com/containerd/containerd/v2/pkg/protobuf" ptypes "github.com/containerd/containerd/v2/pkg/protobuf/types" @@ -47,6 +46,8 @@ import ( "github.com/containerd/containerd/v2/pkg/timeout" "github.com/containerd/errdefs" "github.com/containerd/log" + "github.com/containerd/ttrpc" + "github.com/containerd/typeurl/v2" ) const ( @@ -564,7 +565,7 @@ func (s *shimTask) Create(ctx context.Context, opts runtime.CreateOpts) (runtime Stderr: opts.IO.Stderr, Terminal: opts.IO.Terminal, Checkpoint: opts.Checkpoint, - Options: protobuf.FromAny(topts), + Options: typeurl.MarshalProto(topts), } for _, m := range opts.Rootfs { request.Rootfs = append(request.Rootfs, &types.Mount{ diff --git a/core/runtime/v2/shim_manager.go b/core/runtime/v2/shim_manager.go index 31629e29d7cc..2fef2f3ace5d 100644 --- a/core/runtime/v2/shim_manager.go +++ b/core/runtime/v2/shim_manager.go @@ -26,10 +26,6 @@ import ( "strings" "sync" - "github.com/containerd/log" - "github.com/containerd/plugin" - "github.com/containerd/plugin/registry" - "github.com/containerd/containerd/v2/core/containers" "github.com/containerd/containerd/v2/core/events/exchange" "github.com/containerd/containerd/v2/core/metadata" @@ -37,11 +33,14 @@ import ( "github.com/containerd/containerd/v2/core/sandbox" "github.com/containerd/containerd/v2/internal/cleanup" "github.com/containerd/containerd/v2/pkg/namespaces" - "github.com/containerd/containerd/v2/pkg/protobuf" shimbinary "github.com/containerd/containerd/v2/pkg/shim" "github.com/containerd/containerd/v2/pkg/timeout" "github.com/containerd/containerd/v2/plugins" "github.com/containerd/containerd/v2/version" + "github.com/containerd/log" + "github.com/containerd/plugin" + "github.com/containerd/plugin/registry" + "github.com/containerd/typeurl/v2" ) // ShimConfig for the shim @@ -256,7 +255,7 @@ func (m *ShimManager) startShim(ctx context.Context, bundle *Bundle, id string, ttrpcAddress: m.containerdTTRPCAddress, env: m.env, }) - shim, err := b.Start(ctx, protobuf.FromAny(topts), func() { + shim, err := b.Start(ctx, typeurl.MarshalProto(topts), func() { log.G(ctx).WithField("id", id).Info("shim disconnected") cleanupAfterDeadShim(cleanup.Background(ctx), id, m.shims, m.events, b) diff --git a/core/runtime/v2/task_manager.go b/core/runtime/v2/task_manager.go index 19219cb17ab4..f396ced52952 100644 --- a/core/runtime/v2/task_manager.go +++ b/core/runtime/v2/task_manager.go @@ -37,7 +37,6 @@ import ( "github.com/containerd/containerd/v2/core/runtime" "github.com/containerd/containerd/v2/internal/cleanup" - "github.com/containerd/containerd/v2/pkg/protobuf" "github.com/containerd/containerd/v2/pkg/protobuf/proto" "github.com/containerd/containerd/v2/pkg/timeout" "github.com/containerd/containerd/v2/plugins" @@ -272,7 +271,7 @@ func (m *TaskManager) validateRuntimeFeatures(ctx context.Context, opts runtime. topts = opts.RuntimeOptions } - pInfo, err := m.PluginInfo(ctx, &apitypes.RuntimeRequest{RuntimePath: opts.Runtime, Options: protobuf.FromAny(topts)}) + pInfo, err := m.PluginInfo(ctx, &apitypes.RuntimeRequest{RuntimePath: opts.Runtime, Options: typeurl.MarshalProto(topts)}) if err != nil { return fmt.Errorf("runtime info: %w", err) } diff --git a/core/sandbox/helpers.go b/core/sandbox/helpers.go index ec3e2dab60fe..86e6fa1130d8 100644 --- a/core/sandbox/helpers.go +++ b/core/sandbox/helpers.go @@ -27,20 +27,20 @@ import ( func ToProto(sandbox *Sandbox) *types.Sandbox { extensions := make(map[string]*gogo_types.Any) for k, v := range sandbox.Extensions { - extensions[k] = protobuf.FromAny(v) + extensions[k] = typeurl.MarshalProto(v) } return &types.Sandbox{ SandboxID: sandbox.ID, Runtime: &types.Sandbox_Runtime{ Name: sandbox.Runtime.Name, - Options: protobuf.FromAny(sandbox.Runtime.Options), + Options: typeurl.MarshalProto(sandbox.Runtime.Options), }, Sandboxer: sandbox.Sandboxer, Labels: sandbox.Labels, CreatedAt: protobuf.ToTimestamp(sandbox.CreatedAt), UpdatedAt: protobuf.ToTimestamp(sandbox.UpdatedAt), Extensions: extensions, - Spec: protobuf.FromAny(sandbox.Spec), + Spec: typeurl.MarshalProto(sandbox.Spec), } } diff --git a/core/sandbox/proxy/controller.go b/core/sandbox/proxy/controller.go index dfb925f3d6dd..100ab1a0b32d 100644 --- a/core/sandbox/proxy/controller.go +++ b/core/sandbox/proxy/controller.go @@ -26,6 +26,7 @@ import ( "github.com/containerd/containerd/v2/core/sandbox" "github.com/containerd/containerd/v2/pkg/protobuf" "github.com/containerd/errdefs" + "github.com/containerd/typeurl/v2" imagespec "github.com/opencontainers/image-spec/specs-go/v1" "google.golang.org/protobuf/types/known/anypb" ) @@ -206,17 +207,17 @@ func (s *remoteSandboxController) Update( } func toAPISandbox(sb sandbox.Sandbox) (types.Sandbox, error) { - options, err := protobuf.MarshalAnyToProto(sb.Runtime.Options) + options, err := typeurl.MarshalAnyToProto(sb.Runtime.Options) if err != nil { return types.Sandbox{}, err } - spec, err := protobuf.MarshalAnyToProto(sb.Spec) + spec, err := typeurl.MarshalAnyToProto(sb.Spec) if err != nil { return types.Sandbox{}, err } extensions := make(map[string]*anypb.Any) for k, v := range sb.Extensions { - pb, err := protobuf.MarshalAnyToProto(v) + pb, err := typeurl.MarshalAnyToProto(v) if err != nil { return types.Sandbox{}, err } diff --git a/core/streaming/proxy/streaming.go b/core/streaming/proxy/streaming.go index 11c66e70eaad..30b3acf05627 100644 --- a/core/streaming/proxy/streaming.go +++ b/core/streaming/proxy/streaming.go @@ -24,7 +24,6 @@ import ( streamingapi "github.com/containerd/containerd/api/services/streaming/v1" "github.com/containerd/containerd/v2/core/streaming" - "github.com/containerd/containerd/v2/pkg/protobuf" "github.com/containerd/errdefs" "github.com/containerd/ttrpc" "github.com/containerd/typeurl/v2" @@ -82,7 +81,7 @@ func (sc *streamCreator) Create(ctx context.Context, id string) (streaming.Strea if err != nil { return nil, err } - err = stream.Send(protobuf.FromAny(a)) + err = stream.Send(typeurl.MarshalProto(a)) if err != nil { if !errors.Is(err, io.EOF) { err = errdefs.FromGRPC(err) @@ -108,7 +107,7 @@ type clientStream struct { } func (cs *clientStream) Send(a typeurl.Any) (err error) { - err = cs.s.Send(protobuf.FromAny(a)) + err = cs.s.Send(typeurl.MarshalProto(a)) if !errors.Is(err, io.EOF) { err = errdefs.FromGRPC(err) } diff --git a/go.mod b/go.mod index f65f1ce7e048..0035317db5c0 100644 --- a/go.mod +++ b/go.mod @@ -25,7 +25,7 @@ require ( github.com/containerd/platforms v0.2.1 github.com/containerd/plugin v0.1.0 github.com/containerd/ttrpc v1.2.5 - github.com/containerd/typeurl/v2 v2.1.1 + github.com/containerd/typeurl/v2 v2.2.0 github.com/containernetworking/cni v1.2.2 github.com/containernetworking/plugins v1.5.1 github.com/coreos/go-systemd/v22 v22.5.0 diff --git a/go.sum b/go.sum index cb1e3267d5b0..291da7186112 100644 --- a/go.sum +++ b/go.sum @@ -61,8 +61,8 @@ github.com/containerd/plugin v0.1.0 h1:CYMyZk9beRAIe1FEKItbMLLAz/z16aXrGc+B+nv0f github.com/containerd/plugin v0.1.0/go.mod h1:j6HlpMtkiZMgT4UsfVNxPBUkwdw9KQGU6nCLfRxnq+w= github.com/containerd/ttrpc v1.2.5 h1:IFckT1EFQoFBMG4c3sMdT8EP3/aKfumK1msY+Ze4oLU= github.com/containerd/ttrpc v1.2.5/go.mod h1:YCXHsb32f+Sq5/72xHubdiJRQY9inL4a4ZQrAbN1q9o= -github.com/containerd/typeurl/v2 v2.1.1 h1:3Q4Pt7i8nYwy2KmQWIw2+1hTvwTE/6w9FqcttATPO/4= -github.com/containerd/typeurl/v2 v2.1.1/go.mod h1:IDp2JFvbwZ31H8dQbEIY7sDl2L3o3HZj1hsSQlywkQ0= +github.com/containerd/typeurl/v2 v2.2.0 h1:6NBDbQzr7I5LHgp34xAXYF5DOTQDn05X58lsPEmzLso= +github.com/containerd/typeurl/v2 v2.2.0/go.mod h1:8XOOxnyatxSWuG8OfsZXVnAF4iZfedjS/8UHSPJnX4g= github.com/containernetworking/cni v1.2.2 h1:9IbP6KJQQxVKo4hhnm8r50YcVKrJbJu3Dqw+Rbt1vYk= github.com/containernetworking/cni v1.2.2/go.mod h1:DuLgF+aPd3DzcTQTtp/Nvl1Kim23oFKdm2okJzBQA5M= github.com/containernetworking/plugins v1.5.1 h1:T5ji+LPYjjgW0QM+KyrigZbLsZ8jaX+E5J/EcKOE4gQ= @@ -497,7 +497,6 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= diff --git a/internal/cri/server/service.go b/internal/cri/server/service.go index 4c215c2a65eb..b4e3ff0f9616 100644 --- a/internal/cri/server/service.go +++ b/internal/cri/server/service.go @@ -55,7 +55,6 @@ import ( "github.com/containerd/containerd/v2/internal/registrar" "github.com/containerd/containerd/v2/pkg/oci" osinterface "github.com/containerd/containerd/v2/pkg/os" - "github.com/containerd/containerd/v2/pkg/protobuf" "github.com/containerd/containerd/v2/plugins" ) @@ -398,7 +397,7 @@ func introspectRuntimeFeatures(ctx context.Context, intro introspection.Service, if r.Type != plugins.RuntimeRuncV2 { return nil, fmt.Errorf("introspecting OCI runtime features needs the runtime type to be %q, got %q", plugins.RuntimeRuncV2, r.Type) - // For other runtimes, protobuf.MarshalAnyToProto will cause nil panic during typeurl dereference + // For other runtimes, typeurl.MarshalAnyToProto will cause nil panic during typeurl dereference } rr := &apitypes.RuntimeRequest{ @@ -412,7 +411,7 @@ func introspectRuntimeFeatures(ctx context.Context, intro introspection.Service, return nil, err } if options != nil { - rr.Options, err = protobuf.MarshalAnyToProto(options) + rr.Options, err = typeurl.MarshalAnyToProto(options) if err != nil { return nil, fmt.Errorf("failed to marshal %T: %w", options, err) } diff --git a/pkg/protobuf/any.go b/pkg/protobuf/any.go deleted file mode 100644 index a6218acc4821..000000000000 --- a/pkg/protobuf/any.go +++ /dev/null @@ -1,47 +0,0 @@ -/* - 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 protobuf - -import ( - "github.com/containerd/typeurl/v2" - "google.golang.org/protobuf/types/known/anypb" -) - -// FromAny converts typeurl.Any to github.com/containerd/containerd/protobuf/types.Any. -func FromAny(from typeurl.Any) *anypb.Any { - if from == nil { - return nil - } - - if pbany, ok := from.(*anypb.Any); ok { - return pbany - } - - return &anypb.Any{ - TypeUrl: from.GetTypeUrl(), - Value: from.GetValue(), - } -} - -// MarshalAnyToProto converts an arbitrary interface to github.com/containerd/containerd/protobuf/types.Any. -func MarshalAnyToProto(from interface{}) (*anypb.Any, error) { - anyType, err := typeurl.MarshalAny(from) - if err != nil { - return nil, err - } - return FromAny(anyType), nil -} diff --git a/pkg/protobuf/any_test.go b/pkg/protobuf/any_test.go deleted file mode 100644 index 7a74ec16c28b..000000000000 --- a/pkg/protobuf/any_test.go +++ /dev/null @@ -1,26 +0,0 @@ -/* - 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 protobuf - -import "testing" - -func TestFromAny(t *testing.T) { - actual := FromAny(nil) - if actual != nil { - t.Fatalf("expected nil, got %v", actual) - } -} diff --git a/pkg/shim/publisher.go b/pkg/shim/publisher.go index cd9fb6274020..aac551247335 100644 --- a/pkg/shim/publisher.go +++ b/pkg/shim/publisher.go @@ -29,6 +29,7 @@ import ( "github.com/containerd/containerd/v2/pkg/ttrpcutil" "github.com/containerd/log" "github.com/containerd/ttrpc" + "github.com/containerd/typeurl/v2" ) const ( @@ -111,7 +112,7 @@ func (l *RemoteEventsPublisher) Publish(ctx context.Context, topic string, event if err != nil { return err } - evt, err := protobuf.MarshalAnyToProto(event) + evt, err := typeurl.MarshalAnyToProto(event) if err != nil { return err } diff --git a/plugins/services/containers/helpers.go b/plugins/services/containers/helpers.go index 0eb0af94daf8..10103fd0542d 100644 --- a/plugins/services/containers/helpers.go +++ b/plugins/services/containers/helpers.go @@ -38,7 +38,7 @@ func containersToProto(containers []containers.Container) []*api.Container { func containerToProto(container *containers.Container) *api.Container { extensions := make(map[string]*types.Any) for k, v := range container.Extensions { - extensions[k] = protobuf.FromAny(v) + extensions[k] = typeurl.MarshalProto(v) } return &api.Container{ ID: container.ID, @@ -46,9 +46,9 @@ func containerToProto(container *containers.Container) *api.Container { Image: container.Image, Runtime: &api.Container_Runtime{ Name: container.Runtime.Name, - Options: protobuf.FromAny(container.Runtime.Options), + Options: typeurl.MarshalProto(container.Runtime.Options), }, - Spec: protobuf.FromAny(container.Spec), + Spec: typeurl.MarshalProto(container.Spec), Snapshotter: container.Snapshotter, SnapshotKey: container.SnapshotKey, CreatedAt: protobuf.ToTimestamp(container.CreatedAt), diff --git a/plugins/services/events/service.go b/plugins/services/events/service.go index 59e4f92efc60..85a9d9c920bf 100644 --- a/plugins/services/events/service.go +++ b/plugins/services/events/service.go @@ -32,6 +32,7 @@ import ( "github.com/containerd/plugin" "github.com/containerd/plugin/registry" "github.com/containerd/ttrpc" + "github.com/containerd/typeurl/v2" "google.golang.org/grpc" ) @@ -120,7 +121,7 @@ func toProto(env *events.Envelope) *types.Envelope { Timestamp: protobuf.ToTimestamp(env.Timestamp), Namespace: env.Namespace, Topic: env.Topic, - Event: protobuf.FromAny(env.Event), + Event: typeurl.MarshalProto(env.Event), } } diff --git a/plugins/services/streaming/service.go b/plugins/services/streaming/service.go index 0c352a79bf0e..d83e4344a9a2 100644 --- a/plugins/services/streaming/service.go +++ b/plugins/services/streaming/service.go @@ -22,7 +22,6 @@ import ( api "github.com/containerd/containerd/api/services/streaming/v1" "github.com/containerd/containerd/v2/core/streaming" - "github.com/containerd/containerd/v2/pkg/protobuf" ptypes "github.com/containerd/containerd/v2/pkg/protobuf/types" "github.com/containerd/containerd/v2/plugins" "github.com/containerd/errdefs" @@ -92,7 +91,7 @@ func (s *service) Stream(srv api.Streaming_StreamServer) error { } // Send response packet after registering stream - if err := srv.Send(protobuf.FromAny(emptyResponse)); err != nil { + if err := srv.Send(typeurl.MarshalProto(emptyResponse)); err != nil { return err } @@ -111,7 +110,7 @@ type serviceStream struct { } func (ss *serviceStream) Send(a typeurl.Any) (err error) { - err = errdefs.FromGRPC(ss.s.Send(protobuf.FromAny(a))) + err = errdefs.FromGRPC(ss.s.Send(typeurl.MarshalProto(a))) if !errors.Is(err, io.EOF) { err = errdefs.FromGRPC(err) } diff --git a/plugins/services/tasks/local.go b/plugins/services/tasks/local.go index baa800d3e3dd..f0d657cd4db8 100644 --- a/plugins/services/tasks/local.go +++ b/plugins/services/tasks/local.go @@ -461,7 +461,7 @@ func (l *local) ListPids(ctx context.Context, r *api.ListPidsRequest, _ ...grpc. Pid: p.Pid, } if p.Info != nil { - a, err := protobuf.MarshalAnyToProto(p.Info) + a, err := typeurl.MarshalAnyToProto(p.Info) if err != nil { return nil, fmt.Errorf("failed to marshal process %d info: %w", p.Pid, err) } @@ -576,7 +576,7 @@ func (l *local) Checkpoint(ctx context.Context, r *api.CheckpointTaskRequest, _ return nil, err } // write the config to the content store - pbany := protobuf.FromAny(container.Spec) + pbany := typeurl.MarshalProto(container.Spec) data, err := proto.Marshal(pbany) if err != nil { return nil, err diff --git a/vendor/github.com/containerd/typeurl/v2/README.md b/vendor/github.com/containerd/typeurl/v2/README.md index e3d0742f456c..8d86600a40b3 100644 --- a/vendor/github.com/containerd/typeurl/v2/README.md +++ b/vendor/github.com/containerd/typeurl/v2/README.md @@ -2,7 +2,7 @@ [![PkgGoDev](https://pkg.go.dev/badge/github.com/containerd/typeurl)](https://pkg.go.dev/github.com/containerd/typeurl) [![Build Status](https://github.com/containerd/typeurl/workflows/CI/badge.svg)](https://github.com/containerd/typeurl/actions?query=workflow%3ACI) -[![codecov](https://codecov.io/gh/containerd/typeurl/branch/master/graph/badge.svg)](https://codecov.io/gh/containerd/typeurl) +[![codecov](https://codecov.io/gh/containerd/typeurl/branch/main/graph/badge.svg)](https://codecov.io/gh/containerd/typeurl) [![Go Report Card](https://goreportcard.com/badge/github.com/containerd/typeurl)](https://goreportcard.com/report/github.com/containerd/typeurl) A Go package for managing the registration, marshaling, and unmarshaling of encoded types. @@ -13,8 +13,8 @@ This package helps when types are sent over a ttrpc/GRPC API and marshaled as a **typeurl** is a containerd sub-project, licensed under the [Apache 2.0 license](./LICENSE). As a containerd sub-project, you will find the: - * [Project governance](https://github.com/containerd/project/blob/master/GOVERNANCE.md), - * [Maintainers](https://github.com/containerd/project/blob/master/MAINTAINERS), - * and [Contributing guidelines](https://github.com/containerd/project/blob/master/CONTRIBUTING.md) + * [Project governance](https://github.com/containerd/project/blob/main/GOVERNANCE.md), + * [Maintainers](https://github.com/containerd/project/blob/main/MAINTAINERS), + * and [Contributing guidelines](https://github.com/containerd/project/blob/main/CONTRIBUTING.md) information in our [`containerd/project`](https://github.com/containerd/project) repository. diff --git a/vendor/github.com/containerd/typeurl/v2/types.go b/vendor/github.com/containerd/typeurl/v2/types.go index 8d6665bb5ba7..78817b701e3a 100644 --- a/vendor/github.com/containerd/typeurl/v2/types.go +++ b/vendor/github.com/containerd/typeurl/v2/types.go @@ -27,6 +27,7 @@ import ( gogoproto "github.com/gogo/protobuf/proto" "google.golang.org/protobuf/proto" "google.golang.org/protobuf/reflect/protoregistry" + "google.golang.org/protobuf/types/known/anypb" ) var ( @@ -122,6 +123,9 @@ func TypeURL(v interface{}) (string, error) { // Is returns true if the type of the Any is the same as v. func Is(any Any, v interface{}) bool { + if any == nil { + return false + } // call to check that v is a pointer tryDereference(v) url, err := TypeURL(v) @@ -193,6 +197,31 @@ func UnmarshalToByTypeURL(typeURL string, value []byte, out interface{}) error { return err } +// MarshalProto converts typeurl.Any to google.golang.org/protobuf/types/known/anypb.Any. +func MarshalProto(from Any) *anypb.Any { + if from == nil { + return nil + } + + if pbany, ok := from.(*anypb.Any); ok { + return pbany + } + + return &anypb.Any{ + TypeUrl: from.GetTypeUrl(), + Value: from.GetValue(), + } +} + +// MarshalAnyToProto converts an arbitrary interface to google.golang.org/protobuf/types/known/anypb.Any. +func MarshalAnyToProto(from interface{}) (*anypb.Any, error) { + anyType, err := MarshalAny(from) + if err != nil { + return nil, err + } + return MarshalProto(anyType), nil +} + func unmarshal(typeURL string, value []byte, v interface{}) (interface{}, error) { t, err := getTypeByUrl(typeURL) if err != nil { diff --git a/vendor/modules.txt b/vendor/modules.txt index 2a6140a6071d..2786daf1df69 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -185,8 +185,8 @@ github.com/containerd/plugin/registry # github.com/containerd/ttrpc v1.2.5 ## explicit; go 1.19 github.com/containerd/ttrpc -# github.com/containerd/typeurl/v2 v2.1.1 -## explicit; go 1.13 +# github.com/containerd/typeurl/v2 v2.2.0 +## explicit; go 1.21 github.com/containerd/typeurl/v2 # github.com/containernetworking/cni v1.2.2 ## explicit; go 1.21