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:
parent
82d0208aaa
commit
72831b6985
@ -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{
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user