mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-01 09:42:45 +00:00
shimv2: use the UnmarshalAny() to unmarshal Protobuf.Any
It'll be much clear to unmarshal Protobuf.Any using UnmarshalAny(). Fixes: #1130 Signed-off-by: fupan <lifupan@gmail.com>
This commit is contained in:
parent
3a2c0a6506
commit
5ee838d412
@ -6,13 +6,13 @@
|
||||
package containerdshim
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/containerd/containerd/api/types/task"
|
||||
"github.com/containerd/containerd/errdefs"
|
||||
"github.com/containerd/typeurl"
|
||||
googleProtobuf "github.com/gogo/protobuf/types"
|
||||
"github.com/kata-containers/runtime/virtcontainers/types"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
@ -72,10 +72,15 @@ func newExec(c *container, stdin, stdout, stderr string, terminal bool, jspec *g
|
||||
}
|
||||
|
||||
// process exec request
|
||||
var spec specs.Process
|
||||
if err := json.Unmarshal(jspec.Value, &spec); err != nil {
|
||||
var spec *specs.Process
|
||||
v, err := typeurl.UnmarshalAny(jspec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
spec, ok := v.(*specs.Process)
|
||||
if !ok {
|
||||
return nil, errdefs.ToGRPCf(errdefs.ErrInvalidArgument, "Get an invalid spec type")
|
||||
}
|
||||
|
||||
if spec.ConsoleSize != nil {
|
||||
height = uint32(spec.ConsoleSize.Height)
|
||||
|
@ -7,7 +7,6 @@ package containerdshim
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
sysexec "os/exec"
|
||||
@ -31,6 +30,7 @@ import (
|
||||
"github.com/opencontainers/runtime-spec/specs-go"
|
||||
|
||||
"github.com/containerd/containerd/api/types/task"
|
||||
"github.com/containerd/typeurl"
|
||||
ptypes "github.com/gogo/protobuf/types"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
@ -700,12 +700,17 @@ func (s *service) Update(ctx context.Context, r *taskAPI.UpdateTaskRequest) (*pt
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
|
||||
var resources specs.LinuxResources
|
||||
if err := json.Unmarshal(r.Resources.Value, &resources); err != nil {
|
||||
return empty, err
|
||||
var resources *specs.LinuxResources
|
||||
v, err := typeurl.UnmarshalAny(r.Resources)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resources, ok := v.(*specs.LinuxResources)
|
||||
if !ok {
|
||||
return nil, errdefs.ToGRPCf(errdefs.ErrInvalidArgument, "Invalid resources type for %s", s.id)
|
||||
}
|
||||
|
||||
err := s.sandbox.UpdateContainer(r.ID, resources)
|
||||
err = s.sandbox.UpdateContainer(r.ID, *resources)
|
||||
if err != nil {
|
||||
return nil, errdefs.ToGRPC(err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user