Use Any instead of []byte

This allows us to get the fully TypeURL for consuming code.

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby 2017-06-29 15:06:59 -07:00
parent 82d0208aaa
commit 72831b6985
5 changed files with 22 additions and 37 deletions

View File

@ -25,7 +25,6 @@ import (
"github.com/containerd/containerd/plugin" "github.com/containerd/containerd/plugin"
"github.com/containerd/containerd/runtime" "github.com/containerd/containerd/runtime"
runc "github.com/containerd/go-runc" runc "github.com/containerd/go-runc"
protobuf "github.com/gogo/protobuf/types"
google_protobuf "github.com/golang/protobuf/ptypes/empty" google_protobuf "github.com/golang/protobuf/ptypes/empty"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -172,9 +171,7 @@ func (r *Runtime) Create(ctx context.Context, id string, opts runtime.CreateOpts
Stderr: opts.IO.Stderr, Stderr: opts.IO.Stderr,
Terminal: opts.IO.Terminal, Terminal: opts.IO.Terminal,
Checkpoint: opts.Checkpoint, Checkpoint: opts.Checkpoint,
Options: &protobuf.Any{ Options: opts.Options,
Value: opts.Options,
},
} }
for _, m := range opts.Rootfs { for _, m := range opts.Rootfs {
sopts.Rootfs = append(sopts.Rootfs, &types.Mount{ sopts.Rootfs = append(sopts.Rootfs, &types.Mount{

View File

@ -11,8 +11,7 @@ import (
client "github.com/containerd/containerd/linux/shim" client "github.com/containerd/containerd/linux/shim"
shim "github.com/containerd/containerd/linux/shim/v1" shim "github.com/containerd/containerd/linux/shim/v1"
"github.com/containerd/containerd/runtime" "github.com/containerd/containerd/runtime"
protobuf "github.com/gogo/protobuf/types" "github.com/gogo/protobuf/types"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -111,10 +110,7 @@ func (t *Task) Exec(ctx context.Context, opts runtime.ExecOpts) (runtime.Process
Stdout: opts.IO.Stdout, Stdout: opts.IO.Stdout,
Stderr: opts.IO.Stderr, Stderr: opts.IO.Stderr,
Terminal: opts.IO.Terminal, Terminal: opts.IO.Terminal,
Spec: &protobuf.Any{ Spec: opts.Spec,
TypeUrl: specs.Version,
Value: opts.Spec,
},
} }
resp, err := t.shim.Exec(ctx, request) resp, err := t.shim.Exec(ctx, request)
if err != nil { if err != nil {
@ -160,12 +156,10 @@ func (t *Task) CloseIO(ctx context.Context, pid uint32) error {
return err 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{ r := &shim.CheckpointTaskRequest{
Path: path, Path: path,
Options: &protobuf.Any{ Options: options,
Value: options,
},
} }
if _, err := t.shim.Checkpoint(ctx, r); err != nil { if _, err := t.shim.Checkpoint(ctx, r); err != nil {
return errors.New(grpc.ErrorDesc(err)) return errors.New(grpc.ErrorDesc(err))
@ -187,12 +181,9 @@ func (t *Task) DeleteProcess(ctx context.Context, pid uint32) (*runtime.Exit, er
}, nil }, 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{ _, err := t.shim.Update(ctx, &shim.UpdateTaskRequest{
Resources: &protobuf.Any{ Resources: resources,
TypeUrl: specs.Version,
Value: resources,
},
}) })
return err return err
} }

View File

@ -5,6 +5,7 @@ import (
"time" "time"
"github.com/containerd/containerd/mount" "github.com/containerd/containerd/mount"
"github.com/gogo/protobuf/types"
) )
type IO struct { type IO struct {
@ -24,7 +25,7 @@ type CreateOpts struct {
// Checkpoint digest to restore container state // Checkpoint digest to restore container state
Checkpoint string Checkpoint string
// Options for the runtime and container // Options for the runtime and container
Options []byte Options *types.Any
} }
type Exit struct { type Exit struct {

View File

@ -1,6 +1,10 @@
package runtime package runtime
import "context" import (
"context"
"github.com/gogo/protobuf/types"
)
type TaskInfo struct { type TaskInfo struct {
ID string ID string
@ -32,15 +36,15 @@ type Task interface {
// CloseStdin closes the processes stdin // CloseStdin closes the processes stdin
CloseIO(context.Context, uint32) error CloseIO(context.Context, uint32) error
// Checkpoint checkpoints a container to an image with live system data // 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 deletes a specific exec process via the pid
DeleteProcess(context.Context, uint32) (*Exit, error) DeleteProcess(context.Context, uint32) (*Exit, error)
// Update sets the provided resources to a running task // Update sets the provided resources to a running task
Update(context.Context, []byte) error Update(context.Context, *types.Any) error
} }
type ExecOpts struct { type ExecOpts struct {
Spec []byte Spec *types.Any
IO IO IO IO
} }

View File

@ -121,10 +121,6 @@ func (s *Service) Create(ctx context.Context, r *api.CreateTaskRequest) (*api.Cr
if err != nil { if err != nil {
return nil, errdefs.ToGRPC(err) return nil, errdefs.ToGRPC(err)
} }
var options []byte
if r.Options != nil {
options = r.Options.Value
}
opts := runtime.CreateOpts{ opts := runtime.CreateOpts{
Spec: container.Spec, Spec: container.Spec,
IO: runtime.IO{ IO: runtime.IO{
@ -134,7 +130,7 @@ func (s *Service) Create(ctx context.Context, r *api.CreateTaskRequest) (*api.Cr
Terminal: r.Terminal, Terminal: r.Terminal,
}, },
Checkpoint: checkpointPath, Checkpoint: checkpointPath,
Options: options, Options: r.Options,
} }
for _, m := range r.Rootfs { for _, m := range r.Rootfs {
opts.Rootfs = append(opts.Rootfs, mount.Mount{ 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 return nil, err
} }
process, err := t.Exec(ctx, runtime.ExecOpts{ process, err := t.Exec(ctx, runtime.ExecOpts{
Spec: r.Spec.Value, Spec: r.Spec,
IO: runtime.IO{ IO: runtime.IO{
Stdin: r.Stdin, Stdin: r.Stdin,
Stdout: r.Stdout, Stdout: r.Stdout,
@ -418,11 +414,7 @@ func (s *Service) Checkpoint(ctx context.Context, r *api.CheckpointTaskRequest)
return nil, err return nil, err
} }
defer os.RemoveAll(image) defer os.RemoveAll(image)
var options []byte if err := t.Checkpoint(ctx, image, r.Options); err != nil {
if r.Options != nil {
options = r.Options.Value
}
if err := t.Checkpoint(ctx, image, options); err != nil {
return nil, err return nil, err
} }
// write checkpoint to the content store // write checkpoint to the content store
@ -454,7 +446,7 @@ func (s *Service) Update(ctx context.Context, r *api.UpdateTaskRequest) (*google
if err != nil { if err != nil {
return nil, err 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 nil, err
} }
return empty, nil return empty, nil