From 72831b698579d89ff1eb2ea142247a62f0d5a47a Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Thu, 29 Jun 2017 15:06:59 -0700 Subject: [PATCH] Use Any instead of []byte This allows us to get the fully TypeURL for consuming code. Signed-off-by: Michael Crosby --- linux/runtime.go | 5 +---- linux/task.go | 23 +++++++---------------- runtime/runtime.go | 3 ++- runtime/task.go | 12 ++++++++---- services/tasks/service.go | 16 ++++------------ 5 files changed, 22 insertions(+), 37 deletions(-) diff --git a/linux/runtime.go b/linux/runtime.go index a65e0d139..417c51246 100644 --- a/linux/runtime.go +++ b/linux/runtime.go @@ -25,7 +25,6 @@ import ( "github.com/containerd/containerd/plugin" "github.com/containerd/containerd/runtime" runc "github.com/containerd/go-runc" - protobuf "github.com/gogo/protobuf/types" google_protobuf "github.com/golang/protobuf/ptypes/empty" "github.com/pkg/errors" @@ -172,9 +171,7 @@ func (r *Runtime) Create(ctx context.Context, id string, opts runtime.CreateOpts Stderr: opts.IO.Stderr, Terminal: opts.IO.Terminal, Checkpoint: opts.Checkpoint, - Options: &protobuf.Any{ - Value: opts.Options, - }, + Options: opts.Options, } for _, m := range opts.Rootfs { sopts.Rootfs = append(sopts.Rootfs, &types.Mount{ diff --git a/linux/task.go b/linux/task.go index a4b3d7f22..1ba459dea 100644 --- a/linux/task.go +++ b/linux/task.go @@ -11,8 +11,7 @@ import ( client "github.com/containerd/containerd/linux/shim" shim "github.com/containerd/containerd/linux/shim/v1" "github.com/containerd/containerd/runtime" - protobuf "github.com/gogo/protobuf/types" - specs "github.com/opencontainers/runtime-spec/specs-go" + "github.com/gogo/protobuf/types" "github.com/pkg/errors" ) @@ -111,10 +110,7 @@ func (t *Task) Exec(ctx context.Context, opts runtime.ExecOpts) (runtime.Process Stdout: opts.IO.Stdout, Stderr: opts.IO.Stderr, Terminal: opts.IO.Terminal, - Spec: &protobuf.Any{ - TypeUrl: specs.Version, - Value: opts.Spec, - }, + Spec: opts.Spec, } resp, err := t.shim.Exec(ctx, request) if err != nil { @@ -160,12 +156,10 @@ func (t *Task) CloseIO(ctx context.Context, pid uint32) error { return err } -func (t *Task) Checkpoint(ctx context.Context, path string, options []byte) error { +func (t *Task) Checkpoint(ctx context.Context, path string, options *types.Any) error { r := &shim.CheckpointTaskRequest{ - Path: path, - Options: &protobuf.Any{ - Value: options, - }, + Path: path, + Options: options, } if _, err := t.shim.Checkpoint(ctx, r); err != nil { return errors.New(grpc.ErrorDesc(err)) @@ -187,12 +181,9 @@ func (t *Task) DeleteProcess(ctx context.Context, pid uint32) (*runtime.Exit, er }, nil } -func (t *Task) Update(ctx context.Context, resources []byte) error { +func (t *Task) Update(ctx context.Context, resources *types.Any) error { _, err := t.shim.Update(ctx, &shim.UpdateTaskRequest{ - Resources: &protobuf.Any{ - TypeUrl: specs.Version, - Value: resources, - }, + Resources: resources, }) return err } diff --git a/runtime/runtime.go b/runtime/runtime.go index a6893cfd9..1d5527d47 100644 --- a/runtime/runtime.go +++ b/runtime/runtime.go @@ -5,6 +5,7 @@ import ( "time" "github.com/containerd/containerd/mount" + "github.com/gogo/protobuf/types" ) type IO struct { @@ -24,7 +25,7 @@ type CreateOpts struct { // Checkpoint digest to restore container state Checkpoint string // Options for the runtime and container - Options []byte + Options *types.Any } type Exit struct { diff --git a/runtime/task.go b/runtime/task.go index 5afd43361..4c7ab15ea 100644 --- a/runtime/task.go +++ b/runtime/task.go @@ -1,6 +1,10 @@ package runtime -import "context" +import ( + "context" + + "github.com/gogo/protobuf/types" +) type TaskInfo struct { ID string @@ -32,15 +36,15 @@ type Task interface { // CloseStdin closes the processes stdin CloseIO(context.Context, uint32) error // Checkpoint checkpoints a container to an image with live system data - Checkpoint(context.Context, string, []byte) error + Checkpoint(context.Context, string, *types.Any) error // DeleteProcess deletes a specific exec process via the pid DeleteProcess(context.Context, uint32) (*Exit, error) // Update sets the provided resources to a running task - Update(context.Context, []byte) error + Update(context.Context, *types.Any) error } type ExecOpts struct { - Spec []byte + Spec *types.Any IO IO } diff --git a/services/tasks/service.go b/services/tasks/service.go index 32a68598a..33fac9fb7 100644 --- a/services/tasks/service.go +++ b/services/tasks/service.go @@ -121,10 +121,6 @@ func (s *Service) Create(ctx context.Context, r *api.CreateTaskRequest) (*api.Cr if err != nil { return nil, errdefs.ToGRPC(err) } - var options []byte - if r.Options != nil { - options = r.Options.Value - } opts := runtime.CreateOpts{ Spec: container.Spec, IO: runtime.IO{ @@ -134,7 +130,7 @@ func (s *Service) Create(ctx context.Context, r *api.CreateTaskRequest) (*api.Cr Terminal: r.Terminal, }, Checkpoint: checkpointPath, - Options: options, + Options: r.Options, } for _, m := range r.Rootfs { opts.Rootfs = append(opts.Rootfs, mount.Mount{ @@ -361,7 +357,7 @@ func (s *Service) Exec(ctx context.Context, r *api.ExecProcessRequest) (*api.Exe return nil, err } process, err := t.Exec(ctx, runtime.ExecOpts{ - Spec: r.Spec.Value, + Spec: r.Spec, IO: runtime.IO{ Stdin: r.Stdin, Stdout: r.Stdout, @@ -418,11 +414,7 @@ func (s *Service) Checkpoint(ctx context.Context, r *api.CheckpointTaskRequest) return nil, err } defer os.RemoveAll(image) - var options []byte - if r.Options != nil { - options = r.Options.Value - } - if err := t.Checkpoint(ctx, image, options); err != nil { + if err := t.Checkpoint(ctx, image, r.Options); err != nil { return nil, err } // write checkpoint to the content store @@ -454,7 +446,7 @@ func (s *Service) Update(ctx context.Context, r *api.UpdateTaskRequest) (*google if err != nil { return nil, err } - if err := t.Update(ctx, r.Resources.Value); err != nil { + if err := t.Update(ctx, r.Resources); err != nil { return nil, err } return empty, nil