Browse code

api/types: move checkpoint-types to api/types/checkpoint

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2023/08/26 19:37:41
Showing 16 changed files
... ...
@@ -1,10 +1,10 @@
1 1
 package checkpoint // import "github.com/docker/docker/api/server/router/checkpoint"
2 2
 
3
-import "github.com/docker/docker/api/types"
3
+import "github.com/docker/docker/api/types/checkpoint"
4 4
 
5 5
 // Backend for Checkpoint
6 6
 type Backend interface {
7
-	CheckpointCreate(container string, config types.CheckpointCreateOptions) error
8
-	CheckpointDelete(container string, config types.CheckpointDeleteOptions) error
9
-	CheckpointList(container string, config types.CheckpointListOptions) ([]types.Checkpoint, error)
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 10
 }
... ...
@@ -5,7 +5,7 @@ import (
5 5
 	"net/http"
6 6
 
7 7
 	"github.com/docker/docker/api/server/httputils"
8
-	"github.com/docker/docker/api/types"
8
+	"github.com/docker/docker/api/types/checkpoint"
9 9
 )
10 10
 
11 11
 func (s *checkpointRouter) postContainerCheckpoint(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
... ...
@@ -13,7 +13,7 @@ func (s *checkpointRouter) postContainerCheckpoint(ctx context.Context, w http.R
13 13
 		return err
14 14
 	}
15 15
 
16
-	var options types.CheckpointCreateOptions
16
+	var options checkpoint.CreateOptions
17 17
 	if err := httputils.ReadJSON(r, &options); err != nil {
18 18
 		return err
19 19
 	}
... ...
@@ -32,7 +32,7 @@ func (s *checkpointRouter) getContainerCheckpoints(ctx context.Context, w http.R
32 32
 		return err
33 33
 	}
34 34
 
35
-	checkpoints, err := s.backend.CheckpointList(vars["name"], types.CheckpointListOptions{
35
+	checkpoints, err := s.backend.CheckpointList(vars["name"], checkpoint.ListOptions{
36 36
 		CheckpointDir: r.Form.Get("dir"),
37 37
 	})
38 38
 	if err != nil {
... ...
@@ -47,7 +47,7 @@ func (s *checkpointRouter) deleteContainerCheckpoint(ctx context.Context, w http
47 47
 		return err
48 48
 	}
49 49
 
50
-	err := s.backend.CheckpointDelete(vars["name"], types.CheckpointDeleteOptions{
50
+	err := s.backend.CheckpointDelete(vars["name"], checkpoint.DeleteOptions{
51 51
 		CheckpointDir: r.Form.Get("dir"),
52 52
 		CheckpointID:  vars["checkpoint"],
53 53
 	})
54 54
new file mode 100644
... ...
@@ -0,0 +1,7 @@
0
+package checkpoint
1
+
2
+// Summary represents the details of a checkpoint when listing endpoints.
3
+type Summary struct {
4
+	// Name is the name of the checkpoint.
5
+	Name string
6
+}
0 7
new file mode 100644
... ...
@@ -0,0 +1,19 @@
0
+package checkpoint
1
+
2
+// CreateOptions holds parameters to create a checkpoint from a container.
3
+type CreateOptions struct {
4
+	CheckpointID  string
5
+	CheckpointDir string
6
+	Exit          bool
7
+}
8
+
9
+// ListOptions holds parameters to list checkpoints for a container.
10
+type ListOptions struct {
11
+	CheckpointDir string
12
+}
13
+
14
+// DeleteOptions holds parameters to delete a checkpoint from a container.
15
+type DeleteOptions struct {
16
+	CheckpointID  string
17
+	CheckpointDir string
18
+}
... ...
@@ -11,24 +11,6 @@ import (
11 11
 	units "github.com/docker/go-units"
12 12
 )
13 13
 
14
-// CheckpointCreateOptions holds parameters to create a checkpoint from a container
15
-type CheckpointCreateOptions struct {
16
-	CheckpointID  string
17
-	CheckpointDir string
18
-	Exit          bool
19
-}
20
-
21
-// CheckpointListOptions holds parameters to list checkpoints for a container
22
-type CheckpointListOptions struct {
23
-	CheckpointDir string
24
-}
25
-
26
-// CheckpointDeleteOptions holds parameters to delete a checkpoint from a container
27
-type CheckpointDeleteOptions struct {
28
-	CheckpointID  string
29
-	CheckpointDir string
30
-}
31
-
32 14
 // ContainerAttachOptions holds parameters to attach to a container.
33 15
 type ContainerAttachOptions struct {
34 16
 	Stream     bool
... ...
@@ -494,11 +494,6 @@ type NetworkInspectOptions struct {
494 494
 	Verbose bool
495 495
 }
496 496
 
497
-// Checkpoint represents the details of a checkpoint
498
-type Checkpoint struct {
499
-	Name string // Name is the name of the checkpoint
500
-}
501
-
502 497
 // DiskUsageObject represents an object type used for disk usage query filtering.
503 498
 type DiskUsageObject string
504 499
 
... ...
@@ -1,6 +1,29 @@
1 1
 package types
2 2
 
3
-import "github.com/docker/docker/api/types/system"
3
+import (
4
+	"github.com/docker/docker/api/types/checkpoint"
5
+	"github.com/docker/docker/api/types/system"
6
+)
7
+
8
+// CheckpointCreateOptions holds parameters to create a checkpoint from a container.
9
+//
10
+// Deprecated: use [checkpoint.CreateOptions].
11
+type CheckpointCreateOptions = checkpoint.CreateOptions
12
+
13
+// CheckpointListOptions holds parameters to list checkpoints for a container
14
+//
15
+// Deprecated: use [checkpoint.ListOptions].
16
+type CheckpointListOptions = checkpoint.ListOptions
17
+
18
+// CheckpointDeleteOptions holds parameters to delete a checkpoint from a container
19
+//
20
+// Deprecated: use [checkpoint.DeleteOptions].
21
+type CheckpointDeleteOptions = checkpoint.DeleteOptions
22
+
23
+// Checkpoint represents the details of a checkpoint when listing endpoints.
24
+//
25
+// Deprecated: use [checkpoint.Summary].
26
+type Checkpoint = checkpoint.Summary
4 27
 
5 28
 // Info contains response of Engine API:
6 29
 // GET "/info"
... ...
@@ -3,11 +3,11 @@ package client // import "github.com/docker/docker/client"
3 3
 import (
4 4
 	"context"
5 5
 
6
-	"github.com/docker/docker/api/types"
6
+	"github.com/docker/docker/api/types/checkpoint"
7 7
 )
8 8
 
9 9
 // CheckpointCreate creates a checkpoint from the given container with the given name
10
-func (cli *Client) CheckpointCreate(ctx context.Context, container string, options types.CheckpointCreateOptions) error {
10
+func (cli *Client) CheckpointCreate(ctx context.Context, container string, options checkpoint.CreateOptions) error {
11 11
 	resp, err := cli.post(ctx, "/containers/"+container+"/checkpoints", nil, options, nil)
12 12
 	ensureReaderClosed(resp)
13 13
 	return err
... ...
@@ -10,7 +10,7 @@ import (
10 10
 	"strings"
11 11
 	"testing"
12 12
 
13
-	"github.com/docker/docker/api/types"
13
+	"github.com/docker/docker/api/types/checkpoint"
14 14
 	"github.com/docker/docker/errdefs"
15 15
 	"gotest.tools/v3/assert"
16 16
 	is "gotest.tools/v3/assert/cmp"
... ...
@@ -20,7 +20,7 @@ func TestCheckpointCreateError(t *testing.T) {
20 20
 	client := &Client{
21 21
 		client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
22 22
 	}
23
-	err := client.CheckpointCreate(context.Background(), "nothing", types.CheckpointCreateOptions{
23
+	err := client.CheckpointCreate(context.Background(), "nothing", checkpoint.CreateOptions{
24 24
 		CheckpointID: "noting",
25 25
 		Exit:         true,
26 26
 	})
... ...
@@ -43,7 +43,7 @@ func TestCheckpointCreate(t *testing.T) {
43 43
 				return nil, fmt.Errorf("expected POST method, got %s", req.Method)
44 44
 			}
45 45
 
46
-			createOptions := &types.CheckpointCreateOptions{}
46
+			createOptions := &checkpoint.CreateOptions{}
47 47
 			if err := json.NewDecoder(req.Body).Decode(createOptions); err != nil {
48 48
 				return nil, err
49 49
 			}
... ...
@@ -63,7 +63,7 @@ func TestCheckpointCreate(t *testing.T) {
63 63
 		}),
64 64
 	}
65 65
 
66
-	err := client.CheckpointCreate(context.Background(), expectedContainerID, types.CheckpointCreateOptions{
66
+	err := client.CheckpointCreate(context.Background(), expectedContainerID, checkpoint.CreateOptions{
67 67
 		CheckpointID: expectedCheckpointID,
68 68
 		Exit:         true,
69 69
 	})
... ...
@@ -4,11 +4,11 @@ import (
4 4
 	"context"
5 5
 	"net/url"
6 6
 
7
-	"github.com/docker/docker/api/types"
7
+	"github.com/docker/docker/api/types/checkpoint"
8 8
 )
9 9
 
10 10
 // CheckpointDelete deletes the checkpoint with the given name from the given container
11
-func (cli *Client) CheckpointDelete(ctx context.Context, containerID string, options types.CheckpointDeleteOptions) error {
11
+func (cli *Client) CheckpointDelete(ctx context.Context, containerID string, options checkpoint.DeleteOptions) error {
12 12
 	query := url.Values{}
13 13
 	if options.CheckpointDir != "" {
14 14
 		query.Set("dir", options.CheckpointDir)
... ...
@@ -9,7 +9,7 @@ import (
9 9
 	"strings"
10 10
 	"testing"
11 11
 
12
-	"github.com/docker/docker/api/types"
12
+	"github.com/docker/docker/api/types/checkpoint"
13 13
 	"github.com/docker/docker/errdefs"
14 14
 	"gotest.tools/v3/assert"
15 15
 	is "gotest.tools/v3/assert/cmp"
... ...
@@ -20,7 +20,7 @@ func TestCheckpointDeleteError(t *testing.T) {
20 20
 		client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
21 21
 	}
22 22
 
23
-	err := client.CheckpointDelete(context.Background(), "container_id", types.CheckpointDeleteOptions{
23
+	err := client.CheckpointDelete(context.Background(), "container_id", checkpoint.DeleteOptions{
24 24
 		CheckpointID: "checkpoint_id",
25 25
 	})
26 26
 
... ...
@@ -45,7 +45,7 @@ func TestCheckpointDelete(t *testing.T) {
45 45
 		}),
46 46
 	}
47 47
 
48
-	err := client.CheckpointDelete(context.Background(), "container_id", types.CheckpointDeleteOptions{
48
+	err := client.CheckpointDelete(context.Background(), "container_id", checkpoint.DeleteOptions{
49 49
 		CheckpointID: "checkpoint_id",
50 50
 	})
51 51
 	if err != nil {
... ...
@@ -5,12 +5,12 @@ import (
5 5
 	"encoding/json"
6 6
 	"net/url"
7 7
 
8
-	"github.com/docker/docker/api/types"
8
+	"github.com/docker/docker/api/types/checkpoint"
9 9
 )
10 10
 
11 11
 // CheckpointList returns the checkpoints of the given container in the docker host
12
-func (cli *Client) CheckpointList(ctx context.Context, container string, options types.CheckpointListOptions) ([]types.Checkpoint, error) {
13
-	var checkpoints []types.Checkpoint
12
+func (cli *Client) CheckpointList(ctx context.Context, container string, options checkpoint.ListOptions) ([]checkpoint.Summary, error) {
13
+	var checkpoints []checkpoint.Summary
14 14
 
15 15
 	query := url.Values{}
16 16
 	if options.CheckpointDir != "" {
... ...
@@ -10,7 +10,7 @@ import (
10 10
 	"strings"
11 11
 	"testing"
12 12
 
13
-	"github.com/docker/docker/api/types"
13
+	"github.com/docker/docker/api/types/checkpoint"
14 14
 	"github.com/docker/docker/errdefs"
15 15
 	"gotest.tools/v3/assert"
16 16
 	is "gotest.tools/v3/assert/cmp"
... ...
@@ -21,7 +21,7 @@ func TestCheckpointListError(t *testing.T) {
21 21
 		client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
22 22
 	}
23 23
 
24
-	_, err := client.CheckpointList(context.Background(), "container_id", types.CheckpointListOptions{})
24
+	_, err := client.CheckpointList(context.Background(), "container_id", checkpoint.ListOptions{})
25 25
 	assert.Check(t, is.ErrorType(err, errdefs.IsSystem))
26 26
 }
27 27
 
... ...
@@ -33,7 +33,7 @@ func TestCheckpointList(t *testing.T) {
33 33
 			if !strings.HasPrefix(req.URL.Path, expectedURL) {
34 34
 				return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL)
35 35
 			}
36
-			content, err := json.Marshal([]types.Checkpoint{
36
+			content, err := json.Marshal([]checkpoint.Summary{
37 37
 				{
38 38
 					Name: "checkpoint",
39 39
 				},
... ...
@@ -48,7 +48,7 @@ func TestCheckpointList(t *testing.T) {
48 48
 		}),
49 49
 	}
50 50
 
51
-	checkpoints, err := client.CheckpointList(context.Background(), "container_id", types.CheckpointListOptions{})
51
+	checkpoints, err := client.CheckpointList(context.Background(), "container_id", checkpoint.ListOptions{})
52 52
 	if err != nil {
53 53
 		t.Fatal(err)
54 54
 	}
... ...
@@ -62,6 +62,6 @@ func TestCheckpointListContainerNotFound(t *testing.T) {
62 62
 		client: newMockClient(errorMock(http.StatusNotFound, "Server error")),
63 63
 	}
64 64
 
65
-	_, err := client.CheckpointList(context.Background(), "unknown", types.CheckpointListOptions{})
65
+	_, err := client.CheckpointList(context.Background(), "unknown", checkpoint.ListOptions{})
66 66
 	assert.Check(t, is.ErrorType(err, errdefs.IsNotFound))
67 67
 }
... ...
@@ -3,7 +3,7 @@ package client // import "github.com/docker/docker/client"
3 3
 import (
4 4
 	"context"
5 5
 
6
-	"github.com/docker/docker/api/types"
6
+	"github.com/docker/docker/api/types/checkpoint"
7 7
 )
8 8
 
9 9
 type apiClientExperimental interface {
... ...
@@ -12,7 +12,7 @@ type apiClientExperimental interface {
12 12
 
13 13
 // CheckpointAPIClient defines API client methods for the checkpoints
14 14
 type CheckpointAPIClient interface {
15
-	CheckpointCreate(ctx context.Context, container string, options types.CheckpointCreateOptions) error
16
-	CheckpointDelete(ctx context.Context, container string, options types.CheckpointDeleteOptions) error
17
-	CheckpointList(ctx context.Context, container string, options types.CheckpointListOptions) ([]types.Checkpoint, error)
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)
18 18
 }
... ...
@@ -6,7 +6,7 @@ import (
6 6
 	"os"
7 7
 	"path/filepath"
8 8
 
9
-	"github.com/docker/docker/api/types"
9
+	"github.com/docker/docker/api/types/checkpoint"
10 10
 	"github.com/docker/docker/daemon/names"
11 11
 )
12 12
 
... ...
@@ -51,7 +51,7 @@ func getCheckpointDir(checkDir, checkpointID, ctrName, ctrID, ctrCheckpointDir s
51 51
 }
52 52
 
53 53
 // CheckpointCreate checkpoints the process running in a container with CRIU
54
-func (daemon *Daemon) CheckpointCreate(name string, config types.CheckpointCreateOptions) error {
54
+func (daemon *Daemon) CheckpointCreate(name string, config checkpoint.CreateOptions) error {
55 55
 	container, err := daemon.GetContainer(name)
56 56
 	if err != nil {
57 57
 		return err
... ...
@@ -85,7 +85,7 @@ func (daemon *Daemon) CheckpointCreate(name string, config types.CheckpointCreat
85 85
 }
86 86
 
87 87
 // CheckpointDelete deletes the specified checkpoint
88
-func (daemon *Daemon) CheckpointDelete(name string, config types.CheckpointDeleteOptions) error {
88
+func (daemon *Daemon) CheckpointDelete(name string, config checkpoint.DeleteOptions) error {
89 89
 	container, err := daemon.GetContainer(name)
90 90
 	if err != nil {
91 91
 		return err
... ...
@@ -98,8 +98,8 @@ func (daemon *Daemon) CheckpointDelete(name string, config types.CheckpointDelet
98 98
 }
99 99
 
100 100
 // CheckpointList lists all checkpoints of the specified container
101
-func (daemon *Daemon) CheckpointList(name string, config types.CheckpointListOptions) ([]types.Checkpoint, error) {
102
-	var out []types.Checkpoint
101
+func (daemon *Daemon) CheckpointList(name string, config checkpoint.ListOptions) ([]checkpoint.Summary, error) {
102
+	var out []checkpoint.Summary
103 103
 
104 104
 	container, err := daemon.GetContainer(name)
105 105
 	if err != nil {
... ...
@@ -124,7 +124,7 @@ func (daemon *Daemon) CheckpointList(name string, config types.CheckpointListOpt
124 124
 		if !d.IsDir() {
125 125
 			continue
126 126
 		}
127
-		cpt := types.Checkpoint{Name: d.Name()}
127
+		cpt := checkpoint.Summary{Name: d.Name()}
128 128
 		out = append(out, cpt)
129 129
 	}
130 130
 
... ...
@@ -9,6 +9,7 @@ import (
9 9
 	"time"
10 10
 
11 11
 	"github.com/docker/docker/api/types"
12
+	"github.com/docker/docker/api/types/checkpoint"
12 13
 	mounttypes "github.com/docker/docker/api/types/mount"
13 14
 	"github.com/docker/docker/client"
14 15
 	"github.com/docker/docker/integration/internal/container"
... ...
@@ -56,7 +57,7 @@ func TestCheckpoint(t *testing.T) {
56 56
 		poll.WithDelay(100*time.Millisecond),
57 57
 	)
58 58
 
59
-	cptOpt := types.CheckpointCreateOptions{
59
+	cptOpt := checkpoint.CreateOptions{
60 60
 		Exit:         false,
61 61
 		CheckpointID: "test",
62 62
 	}
... ...
@@ -100,7 +101,7 @@ func TestCheckpoint(t *testing.T) {
100 100
 	assert.NilError(t, err)
101 101
 	assert.Check(t, is.Equal(true, inspect.State.Running))
102 102
 
103
-	checkpoints, err := apiClient.CheckpointList(ctx, cID, types.CheckpointListOptions{})
103
+	checkpoints, err := apiClient.CheckpointList(ctx, cID, checkpoint.ListOptions{})
104 104
 	assert.NilError(t, err)
105 105
 	assert.Equal(t, len(checkpoints), 1)
106 106
 	assert.Equal(t, checkpoints[0].Name, "test")
... ...
@@ -109,7 +110,7 @@ func TestCheckpoint(t *testing.T) {
109 109
 	containerExec(t, apiClient, cID, []string{"touch", "/tmp/test-file"})
110 110
 
111 111
 	// Do a second checkpoint
112
-	cptOpt = types.CheckpointCreateOptions{
112
+	cptOpt = checkpoint.CreateOptions{
113 113
 		Exit:         true,
114 114
 		CheckpointID: "test2",
115 115
 	}
... ...
@@ -127,7 +128,7 @@ func TestCheckpoint(t *testing.T) {
127 127
 	assert.Check(t, is.Equal(false, inspect.State.Running))
128 128
 
129 129
 	// Check that both checkpoints are listed.
130
-	checkpoints, err = apiClient.CheckpointList(ctx, cID, types.CheckpointListOptions{})
130
+	checkpoints, err = apiClient.CheckpointList(ctx, cID, checkpoint.ListOptions{})
131 131
 	assert.NilError(t, err)
132 132
 	assert.Equal(t, len(checkpoints), 2)
133 133
 	cptNames := make([]string, 2)
... ...
@@ -154,7 +155,7 @@ func TestCheckpoint(t *testing.T) {
154 154
 	containerExec(t, apiClient, cID, []string{"test", "-f", "/tmp/test-file"})
155 155
 
156 156
 	for _, id := range []string{"test", "test2"} {
157
-		cptDelOpt := types.CheckpointDeleteOptions{
157
+		cptDelOpt := checkpoint.DeleteOptions{
158 158
 			CheckpointID: id,
159 159
 		}
160 160