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:
parent
124f430d44
commit
ccbe92dc08
@ -1,14 +1,10 @@
|
|||||||
package containerd
|
package containerd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"path/filepath"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
tasks "github.com/containerd/containerd/api/services/tasks/v1"
|
|
||||||
"github.com/containerd/containerd/linux/runcopts"
|
"github.com/containerd/containerd/linux/runcopts"
|
||||||
"github.com/gogo/protobuf/proto"
|
|
||||||
protobuf "github.com/gogo/protobuf/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCheckpointRestore(t *testing.T) {
|
func TestCheckpointRestore(t *testing.T) {
|
||||||
@ -68,7 +64,7 @@ func TestCheckpointRestore(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
checkpoint, err := task.Checkpoint(ctx, WithExit)
|
checkpoint, err := task.Checkpoint(ctx, runcopts.WithExit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
@ -161,7 +157,7 @@ func TestCheckpointRestoreNewContainer(t *testing.T) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
checkpoint, err := task.Checkpoint(ctx, WithExit)
|
checkpoint, err := task.Checkpoint(ctx, runcopts.WithExit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
return
|
return
|
||||||
@ -286,25 +282,3 @@ func TestCheckpointLeaveRunning(t *testing.T) {
|
|||||||
|
|
||||||
<-statusC
|
<-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
|
|
||||||
}
|
|
||||||
|
@ -2,13 +2,9 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
|
||||||
|
|
||||||
"github.com/containerd/containerd"
|
"github.com/containerd/containerd"
|
||||||
tasks "github.com/containerd/containerd/api/services/tasks/v1"
|
|
||||||
"github.com/containerd/containerd/linux/runcopts"
|
"github.com/containerd/containerd/linux/runcopts"
|
||||||
"github.com/gogo/protobuf/proto"
|
|
||||||
protobuf "github.com/gogo/protobuf/types"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
@ -47,7 +43,7 @@ var checkpointCommand = cli.Command{
|
|||||||
}
|
}
|
||||||
var opts []containerd.CheckpointOpts
|
var opts []containerd.CheckpointOpts
|
||||||
if context.Bool("exit") {
|
if context.Bool("exit") {
|
||||||
opts = append(opts, WithExit)
|
opts = append(opts, runcopts.WithExit)
|
||||||
}
|
}
|
||||||
checkpoint, err := task.Checkpoint(ctx, opts...)
|
checkpoint, err := task.Checkpoint(ctx, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -57,25 +53,3 @@ var checkpointCommand = cli.Command{
|
|||||||
return nil
|
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
|
|
||||||
}
|
|
||||||
|
@ -1,3 +1,33 @@
|
|||||||
package runcopts
|
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"
|
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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user