Move WithExit to runcopts package

Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Kenfe-Mickael Laventure 2017-06-29 15:44:47 -07:00 committed by Michael Crosby
parent 124f430d44
commit ccbe92dc08
3 changed files with 33 additions and 55 deletions

View File

@ -1,14 +1,10 @@
package containerd
import (
"path/filepath"
"syscall"
"testing"
tasks "github.com/containerd/containerd/api/services/tasks/v1"
"github.com/containerd/containerd/linux/runcopts"
"github.com/gogo/protobuf/proto"
protobuf "github.com/gogo/protobuf/types"
)
func TestCheckpointRestore(t *testing.T) {
@ -68,7 +64,7 @@ func TestCheckpointRestore(t *testing.T) {
return
}
checkpoint, err := task.Checkpoint(ctx, WithExit)
checkpoint, err := task.Checkpoint(ctx, runcopts.WithExit)
if err != nil {
t.Error(err)
return
@ -161,7 +157,7 @@ func TestCheckpointRestoreNewContainer(t *testing.T) {
return
}
checkpoint, err := task.Checkpoint(ctx, WithExit)
checkpoint, err := task.Checkpoint(ctx, runcopts.WithExit)
if err != nil {
t.Error(err)
return
@ -286,25 +282,3 @@ func TestCheckpointLeaveRunning(t *testing.T) {
<-statusC
}
func WithExit(r *tasks.CheckpointTaskRequest) error {
a, err := marshal(&runcopts.CheckpointOptions{
Exit: true,
}, "CheckpointOptions")
if err != nil {
return err
}
r.Options = a
return nil
}
func marshal(m proto.Message, name string) (*protobuf.Any, error) {
data, err := proto.Marshal(m)
if err != nil {
return nil, err
}
return &protobuf.Any{
TypeUrl: filepath.Join(runcopts.URIBase, name),
Value: data,
}, nil
}

View File

@ -2,13 +2,9 @@ package main
import (
"fmt"
"path/filepath"
"github.com/containerd/containerd"
tasks "github.com/containerd/containerd/api/services/tasks/v1"
"github.com/containerd/containerd/linux/runcopts"
"github.com/gogo/protobuf/proto"
protobuf "github.com/gogo/protobuf/types"
"github.com/pkg/errors"
"github.com/urfave/cli"
)
@ -47,7 +43,7 @@ var checkpointCommand = cli.Command{
}
var opts []containerd.CheckpointOpts
if context.Bool("exit") {
opts = append(opts, WithExit)
opts = append(opts, runcopts.WithExit)
}
checkpoint, err := task.Checkpoint(ctx, opts...)
if err != nil {
@ -57,25 +53,3 @@ var checkpointCommand = cli.Command{
return nil
},
}
func WithExit(r *tasks.CheckpointTaskRequest) error {
a, err := marshal(&runcopts.CheckpointOptions{
Exit: true,
}, "CheckpointOptions")
if err != nil {
return err
}
r.Options = a
return nil
}
func marshal(m proto.Message, name string) (*protobuf.Any, error) {
data, err := proto.Marshal(m)
if err != nil {
return nil, err
}
return &protobuf.Any{
TypeUrl: filepath.Join(runcopts.URIBase, name),
Value: data,
}, nil
}

View File

@ -1,3 +1,33 @@
package runcopts
import (
"path/filepath"
tasks "github.com/containerd/containerd/api/services/tasks/v1"
"github.com/gogo/protobuf/proto"
protobuf "github.com/gogo/protobuf/types"
)
const URIBase = "types.containerd.io/linux/runc"
func WithExit(r *tasks.CheckpointTaskRequest) error {
a, err := marshal(&CheckpointOptions{
Exit: true,
}, "CheckpointOptions")
if err != nil {
return err
}
r.Options = a
return nil
}
func marshal(m proto.Message, name string) (*protobuf.Any, error) {
data, err := proto.Marshal(m)
if err != nil {
return nil, err
}
return &protobuf.Any{
TypeUrl: filepath.Join(URIBase, name),
Value: data,
}, nil
}