mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-02 02:02:24 +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
|
package containerdshim
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containerd/containerd/api/types/task"
|
"github.com/containerd/containerd/api/types/task"
|
||||||
"github.com/containerd/containerd/errdefs"
|
"github.com/containerd/containerd/errdefs"
|
||||||
|
"github.com/containerd/typeurl"
|
||||||
googleProtobuf "github.com/gogo/protobuf/types"
|
googleProtobuf "github.com/gogo/protobuf/types"
|
||||||
"github.com/kata-containers/runtime/virtcontainers/types"
|
"github.com/kata-containers/runtime/virtcontainers/types"
|
||||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
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
|
// process exec request
|
||||||
var spec specs.Process
|
var spec *specs.Process
|
||||||
if err := json.Unmarshal(jspec.Value, &spec); err != nil {
|
v, err := typeurl.UnmarshalAny(jspec)
|
||||||
|
if err != nil {
|
||||||
return nil, err
|
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 {
|
if spec.ConsoleSize != nil {
|
||||||
height = uint32(spec.ConsoleSize.Height)
|
height = uint32(spec.ConsoleSize.Height)
|
||||||
|
@ -7,7 +7,6 @@ package containerdshim
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
sysexec "os/exec"
|
sysexec "os/exec"
|
||||||
@ -31,6 +30,7 @@ import (
|
|||||||
"github.com/opencontainers/runtime-spec/specs-go"
|
"github.com/opencontainers/runtime-spec/specs-go"
|
||||||
|
|
||||||
"github.com/containerd/containerd/api/types/task"
|
"github.com/containerd/containerd/api/types/task"
|
||||||
|
"github.com/containerd/typeurl"
|
||||||
ptypes "github.com/gogo/protobuf/types"
|
ptypes "github.com/gogo/protobuf/types"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@ -700,12 +700,17 @@ func (s *service) Update(ctx context.Context, r *taskAPI.UpdateTaskRequest) (*pt
|
|||||||
s.Lock()
|
s.Lock()
|
||||||
defer s.Unlock()
|
defer s.Unlock()
|
||||||
|
|
||||||
var resources specs.LinuxResources
|
var resources *specs.LinuxResources
|
||||||
if err := json.Unmarshal(r.Resources.Value, &resources); err != nil {
|
v, err := typeurl.UnmarshalAny(r.Resources)
|
||||||
return empty, err
|
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 {
|
if err != nil {
|
||||||
return nil, errdefs.ToGRPC(err)
|
return nil, errdefs.ToGRPC(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user