diff --git a/checkpoint_test.go b/checkpoint_test.go index 45f0cd18d..272422072 100644 --- a/checkpoint_test.go +++ b/checkpoint_test.go @@ -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 -} diff --git a/cmd/ctr/checkpoint.go b/cmd/ctr/checkpoint.go index b259c8fd0..fbed63b44 100644 --- a/cmd/ctr/checkpoint.go +++ b/cmd/ctr/checkpoint.go @@ -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 -} diff --git a/linux/runcopts/options.go b/linux/runcopts/options.go index ed98e36a9..86e04739f 100644 --- a/linux/runcopts/options.go +++ b/linux/runcopts/options.go @@ -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 +}