Log In
Log In
Places
All Projects
Status Monitor
Collapse sidebar
go
golang-gvisor
golang-gvisor-marshalany.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File golang-gvisor-marshalany.patch of Package golang-gvisor
From 0229aef05db7b0ea8c48bcfafdf168522e03ba2b Mon Sep 17 00:00:00 2001 From: Oleg Girko <ol@infoserver.lv> Date: Wed, 17 Apr 2024 16:39:59 +0100 Subject: [PATCH] Update to newer typeurl API: MarshalAny() from typeurl. The MarshalAny function now returns a different type. Using older implementation of this fnction. Signed-off-by: Oleg Girko <ol@infoserver.lv> --- pkg/shim/service.go | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/pkg/shim/service.go b/pkg/shim/service.go index 0506c6f53..4f69de4f1 100644 --- a/pkg/shim/service.go +++ b/pkg/shim/service.go @@ -17,6 +17,7 @@ package shim import ( "context" + "encoding/json" "fmt" "io" "os" @@ -50,6 +51,7 @@ import ( specs "github.com/opencontainers/runtime-spec/specs-go" "github.com/sirupsen/logrus" "golang.org/x/sys/unix" + "google.golang.org/protobuf/proto" "gvisor.dev/gvisor/pkg/cleanup" "gvisor.dev/gvisor/pkg/shim/runtimeoptions/v14" @@ -752,6 +754,39 @@ func (s *service) Pids(ctx context.Context, r *taskAPI.PidsRequest) (*taskAPI.Pi return resp, errdefs.ToGRPC(err) } +// marshalAny marshals the value v into an any with the correct TypeUrl. +// If the provided object is already a proto.Any message, then it will be +// returned verbatim. If it is of type proto.Message, it will be marshaled as a +// protocol buffer. Otherwise, the object will be marshaled to json. +func marshalAny(v interface{}) (*types.Any, error) { + var marshal func(v interface{}) ([]byte, error) + switch t := v.(type) { + case *types.Any: + // avoid re-serializing the type if we have an any. + return t, nil + case proto.Message: + marshal = func(v interface{}) ([]byte, error) { + return proto.Marshal(t) + } + default: + marshal = json.Marshal + } + + url, err := typeurl.TypeURL(v) + if err != nil { + return nil, err + } + + data, err := marshal(v) + if err != nil { + return nil, err + } + return &types.Any{ + TypeUrl: url, + Value: data, + }, nil +} + func (s *service) pids(ctx context.Context, r *taskAPI.PidsRequest) (*taskAPI.PidsResponse, error) { log.L.Debugf("Pids, id: %s", r.ID) @@ -769,7 +804,7 @@ func (s *service) pids(ctx context.Context, r *taskAPI.PidsRequest) (*taskAPI.Pi d := &runctypes.ProcessDetails{ ExecID: p.ID(), } - a, err := typeurl.MarshalAny(d) + a, err := marshalAny(d) if err != nil { return nil, fmt.Errorf("failed to marshal process %d info: %w", pid, err) } @@ -915,7 +950,7 @@ func (s *service) stats(ctx context.Context, r *taskAPI.StatsRequest) (*taskAPI. Limit: stats.Pids.Limit, }, } - data, err := typeurl.MarshalAny(metrics) + data, err := marshalAny(metrics) if err != nil { log.L.Debugf("Stats error, id: %s: %v", r.ID, err) return nil, err -- 2.44.0
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Contact
Support
@OBShq
The Open Build Service is an
openSUSE project
.
Log In
Places
Places
All Projects
Status Monitor