Move the option-types to the client and in some cases create a
copy for the backend. These types are used to construct query-
args, and not marshaled to JSON, and can be replaced with functional
options in the client.
The CreateOptions type was used both as options-struct for the client,
and as struct to marshal/unmarshal the request. For this type, a copy
is created in the Client and a new `checkpoint.CreateRequest` is added
in the API.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| 0 | 8 |
deleted file mode 100644 |
| ... | ... |
@@ -1,19 +0,0 @@ |
| 1 |
-package checkpoint |
|
| 2 |
- |
|
| 3 |
-// CreateOptions holds parameters to create a checkpoint from a container. |
|
| 4 |
-type CreateOptions struct {
|
|
| 5 |
- CheckpointID string |
|
| 6 |
- CheckpointDir string |
|
| 7 |
- Exit bool |
|
| 8 |
-} |
|
| 9 |
- |
|
| 10 |
-// ListOptions holds parameters to list checkpoints for a container. |
|
| 11 |
-type ListOptions struct {
|
|
| 12 |
- CheckpointDir string |
|
| 13 |
-} |
|
| 14 |
- |
|
| 15 |
-// DeleteOptions holds parameters to delete a checkpoint from a container. |
|
| 16 |
-type DeleteOptions struct {
|
|
| 17 |
- CheckpointID string |
|
| 18 |
- CheckpointDir string |
|
| 19 |
-} |
| ... | ... |
@@ -12,7 +12,7 @@ import ( |
| 12 | 12 |
// and only available if the daemon is running with experimental features |
| 13 | 13 |
// enabled. |
| 14 | 14 |
type CheckpointAPIClient interface {
|
| 15 |
- CheckpointCreate(ctx context.Context, container string, options checkpoint.CreateOptions) error |
|
| 16 |
- CheckpointDelete(ctx context.Context, container string, options checkpoint.DeleteOptions) error |
|
| 17 |
- CheckpointList(ctx context.Context, container string, options checkpoint.ListOptions) ([]checkpoint.Summary, error) |
|
| 15 |
+ CheckpointCreate(ctx context.Context, container string, options CheckpointCreateOptions) error |
|
| 16 |
+ CheckpointDelete(ctx context.Context, container string, options CheckpointDeleteOptions) error |
|
| 17 |
+ CheckpointList(ctx context.Context, container string, options CheckpointListOptions) ([]checkpoint.Summary, error) |
|
| 18 | 18 |
} |
| ... | ... |
@@ -6,14 +6,26 @@ import ( |
| 6 | 6 |
"github.com/moby/moby/api/types/checkpoint" |
| 7 | 7 |
) |
| 8 | 8 |
|
| 9 |
+// CheckpointCreateOptions holds parameters to create a checkpoint from a container. |
|
| 10 |
+type CheckpointCreateOptions struct {
|
|
| 11 |
+ CheckpointID string |
|
| 12 |
+ CheckpointDir string |
|
| 13 |
+ Exit bool |
|
| 14 |
+} |
|
| 15 |
+ |
|
| 9 | 16 |
// CheckpointCreate creates a checkpoint from the given container. |
| 10 |
-func (cli *Client) CheckpointCreate(ctx context.Context, containerID string, options checkpoint.CreateOptions) error {
|
|
| 17 |
+func (cli *Client) CheckpointCreate(ctx context.Context, containerID string, options CheckpointCreateOptions) error {
|
|
| 11 | 18 |
containerID, err := trimID("container", containerID)
|
| 12 | 19 |
if err != nil {
|
| 13 | 20 |
return err |
| 14 | 21 |
} |
| 22 |
+ requestBody := checkpoint.CreateRequest{
|
|
| 23 |
+ CheckpointID: options.CheckpointID, |
|
| 24 |
+ CheckpointDir: options.CheckpointDir, |
|
| 25 |
+ Exit: options.Exit, |
|
| 26 |
+ } |
|
| 15 | 27 |
|
| 16 |
- resp, err := cli.post(ctx, "/containers/"+containerID+"/checkpoints", nil, options, nil) |
|
| 28 |
+ resp, err := cli.post(ctx, "/containers/"+containerID+"/checkpoints", nil, requestBody, nil) |
|
| 17 | 29 |
defer ensureReaderClosed(resp) |
| 18 | 30 |
return err |
| 19 | 31 |
} |
| ... | ... |
@@ -12,7 +12,6 @@ import ( |
| 12 | 12 |
"testing" |
| 13 | 13 |
|
| 14 | 14 |
cerrdefs "github.com/containerd/errdefs" |
| 15 |
- "github.com/moby/moby/api/types/checkpoint" |
|
| 16 | 15 |
"gotest.tools/v3/assert" |
| 17 | 16 |
is "gotest.tools/v3/assert/cmp" |
| 18 | 17 |
) |
| ... | ... |
@@ -23,18 +22,18 @@ func TestCheckpointCreateError(t *testing.T) {
|
| 23 | 23 |
) |
| 24 | 24 |
assert.NilError(t, err) |
| 25 | 25 |
|
| 26 |
- err = client.CheckpointCreate(context.Background(), "nothing", checkpoint.CreateOptions{
|
|
| 26 |
+ err = client.CheckpointCreate(context.Background(), "nothing", CheckpointCreateOptions{
|
|
| 27 | 27 |
CheckpointID: "noting", |
| 28 | 28 |
Exit: true, |
| 29 | 29 |
}) |
| 30 | 30 |
|
| 31 | 31 |
assert.Check(t, is.ErrorType(err, cerrdefs.IsInternal)) |
| 32 | 32 |
|
| 33 |
- err = client.CheckpointCreate(context.Background(), "", checkpoint.CreateOptions{})
|
|
| 33 |
+ err = client.CheckpointCreate(context.Background(), "", CheckpointCreateOptions{})
|
|
| 34 | 34 |
assert.Check(t, is.ErrorType(err, cerrdefs.IsInvalidArgument)) |
| 35 | 35 |
assert.Check(t, is.ErrorContains(err, "value is empty")) |
| 36 | 36 |
|
| 37 |
- err = client.CheckpointCreate(context.Background(), " ", checkpoint.CreateOptions{})
|
|
| 37 |
+ err = client.CheckpointCreate(context.Background(), " ", CheckpointCreateOptions{})
|
|
| 38 | 38 |
assert.Check(t, is.ErrorType(err, cerrdefs.IsInvalidArgument)) |
| 39 | 39 |
assert.Check(t, is.ErrorContains(err, "value is empty")) |
| 40 | 40 |
} |
| ... | ... |
@@ -54,7 +53,7 @@ func TestCheckpointCreate(t *testing.T) {
|
| 54 | 54 |
return nil, fmt.Errorf("expected POST method, got %s", req.Method)
|
| 55 | 55 |
} |
| 56 | 56 |
|
| 57 |
- createOptions := &checkpoint.CreateOptions{}
|
|
| 57 |
+ createOptions := &CheckpointCreateOptions{}
|
|
| 58 | 58 |
if err := json.NewDecoder(req.Body).Decode(createOptions); err != nil {
|
| 59 | 59 |
return nil, err |
| 60 | 60 |
} |
| ... | ... |
@@ -75,7 +74,7 @@ func TestCheckpointCreate(t *testing.T) {
|
| 75 | 75 |
) |
| 76 | 76 |
assert.NilError(t, err) |
| 77 | 77 |
|
| 78 |
- err = client.CheckpointCreate(context.Background(), expectedContainerID, checkpoint.CreateOptions{
|
|
| 78 |
+ err = client.CheckpointCreate(context.Background(), expectedContainerID, CheckpointCreateOptions{
|
|
| 79 | 79 |
CheckpointID: expectedCheckpointID, |
| 80 | 80 |
Exit: true, |
| 81 | 81 |
}) |
| ... | ... |
@@ -3,12 +3,16 @@ package client |
| 3 | 3 |
import ( |
| 4 | 4 |
"context" |
| 5 | 5 |
"net/url" |
| 6 |
- |
|
| 7 |
- "github.com/moby/moby/api/types/checkpoint" |
|
| 8 | 6 |
) |
| 9 | 7 |
|
| 8 |
+// CheckpointDeleteOptions holds parameters to delete a checkpoint from a container. |
|
| 9 |
+type CheckpointDeleteOptions struct {
|
|
| 10 |
+ CheckpointID string |
|
| 11 |
+ CheckpointDir string |
|
| 12 |
+} |
|
| 13 |
+ |
|
| 10 | 14 |
// CheckpointDelete deletes the checkpoint with the given name from the given container. |
| 11 |
-func (cli *Client) CheckpointDelete(ctx context.Context, containerID string, options checkpoint.DeleteOptions) error {
|
|
| 15 |
+func (cli *Client) CheckpointDelete(ctx context.Context, containerID string, options CheckpointDeleteOptions) error {
|
|
| 12 | 16 |
containerID, err := trimID("container", containerID)
|
| 13 | 17 |
if err != nil {
|
| 14 | 18 |
return err |
| ... | ... |
@@ -10,7 +10,6 @@ import ( |
| 10 | 10 |
"testing" |
| 11 | 11 |
|
| 12 | 12 |
cerrdefs "github.com/containerd/errdefs" |
| 13 |
- "github.com/moby/moby/api/types/checkpoint" |
|
| 14 | 13 |
"gotest.tools/v3/assert" |
| 15 | 14 |
is "gotest.tools/v3/assert/cmp" |
| 16 | 15 |
) |
| ... | ... |
@@ -21,17 +20,17 @@ func TestCheckpointDeleteError(t *testing.T) {
|
| 21 | 21 |
) |
| 22 | 22 |
assert.NilError(t, err) |
| 23 | 23 |
|
| 24 |
- err = client.CheckpointDelete(context.Background(), "container_id", checkpoint.DeleteOptions{
|
|
| 24 |
+ err = client.CheckpointDelete(context.Background(), "container_id", CheckpointDeleteOptions{
|
|
| 25 | 25 |
CheckpointID: "checkpoint_id", |
| 26 | 26 |
}) |
| 27 | 27 |
|
| 28 | 28 |
assert.Check(t, is.ErrorType(err, cerrdefs.IsInternal)) |
| 29 | 29 |
|
| 30 |
- err = client.CheckpointDelete(context.Background(), "", checkpoint.DeleteOptions{})
|
|
| 30 |
+ err = client.CheckpointDelete(context.Background(), "", CheckpointDeleteOptions{})
|
|
| 31 | 31 |
assert.Check(t, is.ErrorType(err, cerrdefs.IsInvalidArgument)) |
| 32 | 32 |
assert.Check(t, is.ErrorContains(err, "value is empty")) |
| 33 | 33 |
|
| 34 |
- err = client.CheckpointDelete(context.Background(), " ", checkpoint.DeleteOptions{})
|
|
| 34 |
+ err = client.CheckpointDelete(context.Background(), " ", CheckpointDeleteOptions{})
|
|
| 35 | 35 |
assert.Check(t, is.ErrorType(err, cerrdefs.IsInvalidArgument)) |
| 36 | 36 |
assert.Check(t, is.ErrorContains(err, "value is empty")) |
| 37 | 37 |
} |
| ... | ... |
@@ -55,7 +54,7 @@ func TestCheckpointDelete(t *testing.T) {
|
| 55 | 55 |
) |
| 56 | 56 |
assert.NilError(t, err) |
| 57 | 57 |
|
| 58 |
- err = client.CheckpointDelete(context.Background(), "container_id", checkpoint.DeleteOptions{
|
|
| 58 |
+ err = client.CheckpointDelete(context.Background(), "container_id", CheckpointDeleteOptions{
|
|
| 59 | 59 |
CheckpointID: "checkpoint_id", |
| 60 | 60 |
}) |
| 61 | 61 |
assert.NilError(t, err) |
| ... | ... |
@@ -8,8 +8,13 @@ import ( |
| 8 | 8 |
"github.com/moby/moby/api/types/checkpoint" |
| 9 | 9 |
) |
| 10 | 10 |
|
| 11 |
+// CheckpointListOptions holds parameters to list checkpoints for a container. |
|
| 12 |
+type CheckpointListOptions struct {
|
|
| 13 |
+ CheckpointDir string |
|
| 14 |
+} |
|
| 15 |
+ |
|
| 11 | 16 |
// CheckpointList returns the checkpoints of the given container in the docker host. |
| 12 |
-func (cli *Client) CheckpointList(ctx context.Context, container string, options checkpoint.ListOptions) ([]checkpoint.Summary, error) {
|
|
| 17 |
+func (cli *Client) CheckpointList(ctx context.Context, container string, options CheckpointListOptions) ([]checkpoint.Summary, error) {
|
|
| 13 | 18 |
var checkpoints []checkpoint.Summary |
| 14 | 19 |
|
| 15 | 20 |
query := url.Values{}
|
| ... | ... |
@@ -22,7 +22,7 @@ func TestCheckpointListError(t *testing.T) {
|
| 22 | 22 |
) |
| 23 | 23 |
assert.NilError(t, err) |
| 24 | 24 |
|
| 25 |
- _, err = client.CheckpointList(context.Background(), "container_id", checkpoint.ListOptions{})
|
|
| 25 |
+ _, err = client.CheckpointList(context.Background(), "container_id", CheckpointListOptions{})
|
|
| 26 | 26 |
assert.Check(t, is.ErrorType(err, cerrdefs.IsInternal)) |
| 27 | 27 |
} |
| 28 | 28 |
|
| ... | ... |
@@ -50,7 +50,7 @@ func TestCheckpointList(t *testing.T) {
|
| 50 | 50 |
) |
| 51 | 51 |
assert.NilError(t, err) |
| 52 | 52 |
|
| 53 |
- checkpoints, err := client.CheckpointList(context.Background(), "container_id", checkpoint.ListOptions{})
|
|
| 53 |
+ checkpoints, err := client.CheckpointList(context.Background(), "container_id", CheckpointListOptions{})
|
|
| 54 | 54 |
assert.NilError(t, err) |
| 55 | 55 |
assert.Check(t, is.Len(checkpoints, 1)) |
| 56 | 56 |
} |
| ... | ... |
@@ -61,6 +61,6 @@ func TestCheckpointListContainerNotFound(t *testing.T) {
|
| 61 | 61 |
) |
| 62 | 62 |
assert.NilError(t, err) |
| 63 | 63 |
|
| 64 |
- _, err = client.CheckpointList(context.Background(), "unknown", checkpoint.ListOptions{})
|
|
| 64 |
+ _, err = client.CheckpointList(context.Background(), "unknown", CheckpointListOptions{})
|
|
| 65 | 65 |
assert.Check(t, is.ErrorType(err, cerrdefs.IsNotFound)) |
| 66 | 66 |
} |
| ... | ... |
@@ -9,6 +9,7 @@ import ( |
| 9 | 9 |
"github.com/moby/moby/api/types/checkpoint" |
| 10 | 10 |
"github.com/moby/moby/api/types/events" |
| 11 | 11 |
"github.com/moby/moby/v2/daemon/names" |
| 12 |
+ "github.com/moby/moby/v2/daemon/server/backend" |
|
| 12 | 13 |
) |
| 13 | 14 |
|
| 14 | 15 |
var ( |
| ... | ... |
@@ -52,7 +53,7 @@ func getCheckpointDir(checkDir, checkpointID, ctrName, ctrID, ctrCheckpointDir s |
| 52 | 52 |
} |
| 53 | 53 |
|
| 54 | 54 |
// CheckpointCreate checkpoints the process running in a container with CRIU |
| 55 |
-func (daemon *Daemon) CheckpointCreate(name string, config checkpoint.CreateOptions) error {
|
|
| 55 |
+func (daemon *Daemon) CheckpointCreate(name string, config checkpoint.CreateRequest) error {
|
|
| 56 | 56 |
container, err := daemon.GetContainer(name) |
| 57 | 57 |
if err != nil {
|
| 58 | 58 |
return err |
| ... | ... |
@@ -86,7 +87,7 @@ func (daemon *Daemon) CheckpointCreate(name string, config checkpoint.CreateOpti |
| 86 | 86 |
} |
| 87 | 87 |
|
| 88 | 88 |
// CheckpointDelete deletes the specified checkpoint |
| 89 |
-func (daemon *Daemon) CheckpointDelete(name string, config checkpoint.DeleteOptions) error {
|
|
| 89 |
+func (daemon *Daemon) CheckpointDelete(name string, config backend.CheckpointDeleteOptions) error {
|
|
| 90 | 90 |
container, err := daemon.GetContainer(name) |
| 91 | 91 |
if err != nil {
|
| 92 | 92 |
return err |
| ... | ... |
@@ -99,7 +100,7 @@ func (daemon *Daemon) CheckpointDelete(name string, config checkpoint.DeleteOpti |
| 99 | 99 |
} |
| 100 | 100 |
|
| 101 | 101 |
// CheckpointList lists all checkpoints of the specified container |
| 102 |
-func (daemon *Daemon) CheckpointList(name string, config checkpoint.ListOptions) ([]checkpoint.Summary, error) {
|
|
| 102 |
+func (daemon *Daemon) CheckpointList(name string, config backend.CheckpointListOptions) ([]checkpoint.Summary, error) {
|
|
| 103 | 103 |
var out []checkpoint.Summary |
| 104 | 104 |
|
| 105 | 105 |
container, err := daemon.GetContainer(name) |
| 106 | 106 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,12 @@ |
| 0 |
+package backend |
|
| 1 |
+ |
|
| 2 |
+// CheckpointListOptions holds parameters to list checkpoints for a container. |
|
| 3 |
+type CheckpointListOptions struct {
|
|
| 4 |
+ CheckpointDir string |
|
| 5 |
+} |
|
| 6 |
+ |
|
| 7 |
+// CheckpointDeleteOptions holds parameters to delete a checkpoint from a container. |
|
| 8 |
+type CheckpointDeleteOptions struct {
|
|
| 9 |
+ CheckpointID string |
|
| 10 |
+ CheckpointDir string |
|
| 11 |
+} |
| ... | ... |
@@ -1,10 +1,13 @@ |
| 1 | 1 |
package checkpoint |
| 2 | 2 |
|
| 3 |
-import "github.com/moby/moby/api/types/checkpoint" |
|
| 3 |
+import ( |
|
| 4 |
+ "github.com/moby/moby/api/types/checkpoint" |
|
| 5 |
+ "github.com/moby/moby/v2/daemon/server/backend" |
|
| 6 |
+) |
|
| 4 | 7 |
|
| 5 | 8 |
// Backend for Checkpoint |
| 6 | 9 |
type Backend interface {
|
| 7 |
- CheckpointCreate(container string, config checkpoint.CreateOptions) error |
|
| 8 |
- CheckpointDelete(container string, config checkpoint.DeleteOptions) error |
|
| 9 |
- CheckpointList(container string, config checkpoint.ListOptions) ([]checkpoint.Summary, error) |
|
| 10 |
+ CheckpointCreate(container string, config checkpoint.CreateRequest) error |
|
| 11 |
+ CheckpointDelete(container string, config backend.CheckpointDeleteOptions) error |
|
| 12 |
+ CheckpointList(container string, config backend.CheckpointListOptions) ([]checkpoint.Summary, error) |
|
| 10 | 13 |
} |
| ... | ... |
@@ -5,6 +5,7 @@ import ( |
| 5 | 5 |
"net/http" |
| 6 | 6 |
|
| 7 | 7 |
"github.com/moby/moby/api/types/checkpoint" |
| 8 |
+ "github.com/moby/moby/v2/daemon/server/backend" |
|
| 8 | 9 |
"github.com/moby/moby/v2/daemon/server/httputils" |
| 9 | 10 |
) |
| 10 | 11 |
|
| ... | ... |
@@ -13,7 +14,7 @@ func (cr *checkpointRouter) postContainerCheckpoint(ctx context.Context, w http. |
| 13 | 13 |
return err |
| 14 | 14 |
} |
| 15 | 15 |
|
| 16 |
- var options checkpoint.CreateOptions |
|
| 16 |
+ var options checkpoint.CreateRequest |
|
| 17 | 17 |
if err := httputils.ReadJSON(r, &options); err != nil {
|
| 18 | 18 |
return err |
| 19 | 19 |
} |
| ... | ... |
@@ -32,7 +33,7 @@ func (cr *checkpointRouter) getContainerCheckpoints(ctx context.Context, w http. |
| 32 | 32 |
return err |
| 33 | 33 |
} |
| 34 | 34 |
|
| 35 |
- checkpoints, err := cr.backend.CheckpointList(vars["name"], checkpoint.ListOptions{
|
|
| 35 |
+ checkpoints, err := cr.backend.CheckpointList(vars["name"], backend.CheckpointListOptions{
|
|
| 36 | 36 |
CheckpointDir: r.Form.Get("dir"),
|
| 37 | 37 |
}) |
| 38 | 38 |
if err != nil {
|
| ... | ... |
@@ -47,7 +48,7 @@ func (cr *checkpointRouter) deleteContainerCheckpoint(ctx context.Context, w htt |
| 47 | 47 |
return err |
| 48 | 48 |
} |
| 49 | 49 |
|
| 50 |
- err := cr.backend.CheckpointDelete(vars["name"], checkpoint.DeleteOptions{
|
|
| 50 |
+ err := cr.backend.CheckpointDelete(vars["name"], backend.CheckpointDeleteOptions{
|
|
| 51 | 51 |
CheckpointDir: r.Form.Get("dir"),
|
| 52 | 52 |
CheckpointID: vars["checkpoint"], |
| 53 | 53 |
}) |
| ... | ... |
@@ -6,7 +6,6 @@ import ( |
| 6 | 6 |
"sort" |
| 7 | 7 |
"testing" |
| 8 | 8 |
|
| 9 |
- "github.com/moby/moby/api/types/checkpoint" |
|
| 10 | 9 |
containertypes "github.com/moby/moby/api/types/container" |
| 11 | 10 |
mounttypes "github.com/moby/moby/api/types/mount" |
| 12 | 11 |
"github.com/moby/moby/client" |
| ... | ... |
@@ -55,7 +54,7 @@ func TestCheckpoint(t *testing.T) {
|
| 55 | 55 |
}() |
| 56 | 56 |
|
| 57 | 57 |
t.Log("Do a checkpoint and leave the container running")
|
| 58 |
- err = apiClient.CheckpointCreate(ctx, cID, checkpoint.CreateOptions{
|
|
| 58 |
+ err = apiClient.CheckpointCreate(ctx, cID, client.CheckpointCreateOptions{
|
|
| 59 | 59 |
Exit: false, |
| 60 | 60 |
CheckpointID: "test", |
| 61 | 61 |
}) |
| ... | ... |
@@ -78,7 +77,7 @@ func TestCheckpoint(t *testing.T) {
|
| 78 | 78 |
assert.NilError(t, err) |
| 79 | 79 |
assert.Check(t, is.Equal(true, inspect.State.Running)) |
| 80 | 80 |
|
| 81 |
- checkpoints, err := apiClient.CheckpointList(ctx, cID, checkpoint.ListOptions{})
|
|
| 81 |
+ checkpoints, err := apiClient.CheckpointList(ctx, cID, client.CheckpointListOptions{})
|
|
| 82 | 82 |
assert.NilError(t, err) |
| 83 | 83 |
assert.Equal(t, len(checkpoints), 1) |
| 84 | 84 |
assert.Equal(t, checkpoints[0].Name, "test") |
| ... | ... |
@@ -91,7 +90,7 @@ func TestCheckpoint(t *testing.T) {
|
| 91 | 91 |
|
| 92 | 92 |
// Do a second checkpoint |
| 93 | 93 |
t.Log("Do a checkpoint and stop the container")
|
| 94 |
- err = apiClient.CheckpointCreate(ctx, cID, checkpoint.CreateOptions{
|
|
| 94 |
+ err = apiClient.CheckpointCreate(ctx, cID, client.CheckpointCreateOptions{
|
|
| 95 | 95 |
Exit: true, |
| 96 | 96 |
CheckpointID: "test2", |
| 97 | 97 |
}) |
| ... | ... |
@@ -104,7 +103,7 @@ func TestCheckpoint(t *testing.T) {
|
| 104 | 104 |
assert.Check(t, is.Equal(false, inspect.State.Running)) |
| 105 | 105 |
|
| 106 | 106 |
// Check that both checkpoints are listed. |
| 107 |
- checkpoints, err = apiClient.CheckpointList(ctx, cID, checkpoint.ListOptions{})
|
|
| 107 |
+ checkpoints, err = apiClient.CheckpointList(ctx, cID, client.CheckpointListOptions{})
|
|
| 108 | 108 |
assert.NilError(t, err) |
| 109 | 109 |
assert.Equal(t, len(checkpoints), 2) |
| 110 | 110 |
cptNames := make([]string, 2) |
| ... | ... |
@@ -133,7 +132,7 @@ func TestCheckpoint(t *testing.T) {
|
| 133 | 133 |
r.AssertSuccess(t) |
| 134 | 134 |
|
| 135 | 135 |
for _, id := range []string{"test", "test2"} {
|
| 136 |
- err = apiClient.CheckpointDelete(ctx, cID, checkpoint.DeleteOptions{
|
|
| 136 |
+ err = apiClient.CheckpointDelete(ctx, cID, client.CheckpointDeleteOptions{
|
|
| 137 | 137 |
CheckpointID: id, |
| 138 | 138 |
}) |
| 139 | 139 |
assert.NilError(t, err) |
| 0 | 8 |
deleted file mode 100644 |
| ... | ... |
@@ -1,19 +0,0 @@ |
| 1 |
-package checkpoint |
|
| 2 |
- |
|
| 3 |
-// CreateOptions holds parameters to create a checkpoint from a container. |
|
| 4 |
-type CreateOptions struct {
|
|
| 5 |
- CheckpointID string |
|
| 6 |
- CheckpointDir string |
|
| 7 |
- Exit bool |
|
| 8 |
-} |
|
| 9 |
- |
|
| 10 |
-// ListOptions holds parameters to list checkpoints for a container. |
|
| 11 |
-type ListOptions struct {
|
|
| 12 |
- CheckpointDir string |
|
| 13 |
-} |
|
| 14 |
- |
|
| 15 |
-// DeleteOptions holds parameters to delete a checkpoint from a container. |
|
| 16 |
-type DeleteOptions struct {
|
|
| 17 |
- CheckpointID string |
|
| 18 |
- CheckpointDir string |
|
| 19 |
-} |
| ... | ... |
@@ -12,7 +12,7 @@ import ( |
| 12 | 12 |
// and only available if the daemon is running with experimental features |
| 13 | 13 |
// enabled. |
| 14 | 14 |
type CheckpointAPIClient interface {
|
| 15 |
- CheckpointCreate(ctx context.Context, container string, options checkpoint.CreateOptions) error |
|
| 16 |
- CheckpointDelete(ctx context.Context, container string, options checkpoint.DeleteOptions) error |
|
| 17 |
- CheckpointList(ctx context.Context, container string, options checkpoint.ListOptions) ([]checkpoint.Summary, error) |
|
| 15 |
+ CheckpointCreate(ctx context.Context, container string, options CheckpointCreateOptions) error |
|
| 16 |
+ CheckpointDelete(ctx context.Context, container string, options CheckpointDeleteOptions) error |
|
| 17 |
+ CheckpointList(ctx context.Context, container string, options CheckpointListOptions) ([]checkpoint.Summary, error) |
|
| 18 | 18 |
} |
| ... | ... |
@@ -6,14 +6,26 @@ import ( |
| 6 | 6 |
"github.com/moby/moby/api/types/checkpoint" |
| 7 | 7 |
) |
| 8 | 8 |
|
| 9 |
+// CheckpointCreateOptions holds parameters to create a checkpoint from a container. |
|
| 10 |
+type CheckpointCreateOptions struct {
|
|
| 11 |
+ CheckpointID string |
|
| 12 |
+ CheckpointDir string |
|
| 13 |
+ Exit bool |
|
| 14 |
+} |
|
| 15 |
+ |
|
| 9 | 16 |
// CheckpointCreate creates a checkpoint from the given container. |
| 10 |
-func (cli *Client) CheckpointCreate(ctx context.Context, containerID string, options checkpoint.CreateOptions) error {
|
|
| 17 |
+func (cli *Client) CheckpointCreate(ctx context.Context, containerID string, options CheckpointCreateOptions) error {
|
|
| 11 | 18 |
containerID, err := trimID("container", containerID)
|
| 12 | 19 |
if err != nil {
|
| 13 | 20 |
return err |
| 14 | 21 |
} |
| 22 |
+ requestBody := checkpoint.CreateRequest{
|
|
| 23 |
+ CheckpointID: options.CheckpointID, |
|
| 24 |
+ CheckpointDir: options.CheckpointDir, |
|
| 25 |
+ Exit: options.Exit, |
|
| 26 |
+ } |
|
| 15 | 27 |
|
| 16 |
- resp, err := cli.post(ctx, "/containers/"+containerID+"/checkpoints", nil, options, nil) |
|
| 28 |
+ resp, err := cli.post(ctx, "/containers/"+containerID+"/checkpoints", nil, requestBody, nil) |
|
| 17 | 29 |
defer ensureReaderClosed(resp) |
| 18 | 30 |
return err |
| 19 | 31 |
} |
| ... | ... |
@@ -3,12 +3,16 @@ package client |
| 3 | 3 |
import ( |
| 4 | 4 |
"context" |
| 5 | 5 |
"net/url" |
| 6 |
- |
|
| 7 |
- "github.com/moby/moby/api/types/checkpoint" |
|
| 8 | 6 |
) |
| 9 | 7 |
|
| 8 |
+// CheckpointDeleteOptions holds parameters to delete a checkpoint from a container. |
|
| 9 |
+type CheckpointDeleteOptions struct {
|
|
| 10 |
+ CheckpointID string |
|
| 11 |
+ CheckpointDir string |
|
| 12 |
+} |
|
| 13 |
+ |
|
| 10 | 14 |
// CheckpointDelete deletes the checkpoint with the given name from the given container. |
| 11 |
-func (cli *Client) CheckpointDelete(ctx context.Context, containerID string, options checkpoint.DeleteOptions) error {
|
|
| 15 |
+func (cli *Client) CheckpointDelete(ctx context.Context, containerID string, options CheckpointDeleteOptions) error {
|
|
| 12 | 16 |
containerID, err := trimID("container", containerID)
|
| 13 | 17 |
if err != nil {
|
| 14 | 18 |
return err |
| ... | ... |
@@ -8,8 +8,13 @@ import ( |
| 8 | 8 |
"github.com/moby/moby/api/types/checkpoint" |
| 9 | 9 |
) |
| 10 | 10 |
|
| 11 |
+// CheckpointListOptions holds parameters to list checkpoints for a container. |
|
| 12 |
+type CheckpointListOptions struct {
|
|
| 13 |
+ CheckpointDir string |
|
| 14 |
+} |
|
| 15 |
+ |
|
| 11 | 16 |
// CheckpointList returns the checkpoints of the given container in the docker host. |
| 12 |
-func (cli *Client) CheckpointList(ctx context.Context, container string, options checkpoint.ListOptions) ([]checkpoint.Summary, error) {
|
|
| 17 |
+func (cli *Client) CheckpointList(ctx context.Context, container string, options CheckpointListOptions) ([]checkpoint.Summary, error) {
|
|
| 13 | 18 |
var checkpoints []checkpoint.Summary |
| 14 | 19 |
|
| 15 | 20 |
query := url.Values{}
|