From b688af22263237c0591b5e516eaaa70bca49487d Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 26 Aug 2023 12:37:41 +0200 Subject: [PATCH] api/types: move checkpoint-types to api/types/checkpoint Signed-off-by: Sebastiaan van Stijn --- api/server/router/checkpoint/backend.go | 8 +++--- .../router/checkpoint/checkpoint_routes.go | 8 +++--- api/types/checkpoint/list.go | 7 ++++++ api/types/checkpoint/options.go | 19 ++++++++++++++ api/types/client.go | 18 ------------- api/types/types.go | 5 ---- api/types/types_deprecated.go | 25 ++++++++++++++++++- client/checkpoint_create.go | 4 +-- client/checkpoint_create_test.go | 8 +++--- client/checkpoint_delete.go | 4 +-- client/checkpoint_delete_test.go | 6 ++--- client/checkpoint_list.go | 6 ++--- client/checkpoint_list_test.go | 10 ++++---- client/interface_experimental.go | 8 +++--- daemon/checkpoint.go | 12 ++++----- integration/container/checkpoint_test.go | 11 ++++---- 16 files changed, 93 insertions(+), 66 deletions(-) create mode 100644 api/types/checkpoint/list.go create mode 100644 api/types/checkpoint/options.go diff --git a/api/server/router/checkpoint/backend.go b/api/server/router/checkpoint/backend.go index 90c5d1a984..10b343374d 100644 --- a/api/server/router/checkpoint/backend.go +++ b/api/server/router/checkpoint/backend.go @@ -1,10 +1,10 @@ package checkpoint // import "github.com/docker/docker/api/server/router/checkpoint" -import "github.com/docker/docker/api/types" +import "github.com/docker/docker/api/types/checkpoint" // Backend for Checkpoint type Backend interface { - CheckpointCreate(container string, config types.CheckpointCreateOptions) error - CheckpointDelete(container string, config types.CheckpointDeleteOptions) error - CheckpointList(container string, config types.CheckpointListOptions) ([]types.Checkpoint, error) + CheckpointCreate(container string, config checkpoint.CreateOptions) error + CheckpointDelete(container string, config checkpoint.DeleteOptions) error + CheckpointList(container string, config checkpoint.ListOptions) ([]checkpoint.Summary, error) } diff --git a/api/server/router/checkpoint/checkpoint_routes.go b/api/server/router/checkpoint/checkpoint_routes.go index 25f12b280b..98d5826be2 100644 --- a/api/server/router/checkpoint/checkpoint_routes.go +++ b/api/server/router/checkpoint/checkpoint_routes.go @@ -5,7 +5,7 @@ import ( "net/http" "github.com/docker/docker/api/server/httputils" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/checkpoint" ) 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 return err } - var options types.CheckpointCreateOptions + var options checkpoint.CreateOptions if err := httputils.ReadJSON(r, &options); err != nil { return err } @@ -32,7 +32,7 @@ func (s *checkpointRouter) getContainerCheckpoints(ctx context.Context, w http.R return err } - checkpoints, err := s.backend.CheckpointList(vars["name"], types.CheckpointListOptions{ + checkpoints, err := s.backend.CheckpointList(vars["name"], checkpoint.ListOptions{ CheckpointDir: r.Form.Get("dir"), }) if err != nil { @@ -47,7 +47,7 @@ func (s *checkpointRouter) deleteContainerCheckpoint(ctx context.Context, w http return err } - err := s.backend.CheckpointDelete(vars["name"], types.CheckpointDeleteOptions{ + err := s.backend.CheckpointDelete(vars["name"], checkpoint.DeleteOptions{ CheckpointDir: r.Form.Get("dir"), CheckpointID: vars["checkpoint"], }) diff --git a/api/types/checkpoint/list.go b/api/types/checkpoint/list.go new file mode 100644 index 0000000000..94a9c0a47d --- /dev/null +++ b/api/types/checkpoint/list.go @@ -0,0 +1,7 @@ +package checkpoint + +// Summary represents the details of a checkpoint when listing endpoints. +type Summary struct { + // Name is the name of the checkpoint. + Name string +} diff --git a/api/types/checkpoint/options.go b/api/types/checkpoint/options.go new file mode 100644 index 0000000000..9477458c24 --- /dev/null +++ b/api/types/checkpoint/options.go @@ -0,0 +1,19 @@ +package checkpoint + +// CreateOptions holds parameters to create a checkpoint from a container. +type CreateOptions struct { + CheckpointID string + CheckpointDir string + Exit bool +} + +// ListOptions holds parameters to list checkpoints for a container. +type ListOptions struct { + CheckpointDir string +} + +// DeleteOptions holds parameters to delete a checkpoint from a container. +type DeleteOptions struct { + CheckpointID string + CheckpointDir string +} diff --git a/api/types/client.go b/api/types/client.go index d8cd306135..80691034e8 100644 --- a/api/types/client.go +++ b/api/types/client.go @@ -11,24 +11,6 @@ import ( units "github.com/docker/go-units" ) -// CheckpointCreateOptions holds parameters to create a checkpoint from a container -type CheckpointCreateOptions struct { - CheckpointID string - CheckpointDir string - Exit bool -} - -// CheckpointListOptions holds parameters to list checkpoints for a container -type CheckpointListOptions struct { - CheckpointDir string -} - -// CheckpointDeleteOptions holds parameters to delete a checkpoint from a container -type CheckpointDeleteOptions struct { - CheckpointID string - CheckpointDir string -} - // ContainerAttachOptions holds parameters to attach to a container. type ContainerAttachOptions struct { Stream bool diff --git a/api/types/types.go b/api/types/types.go index cb1307aab9..a213f49192 100644 --- a/api/types/types.go +++ b/api/types/types.go @@ -494,11 +494,6 @@ type NetworkInspectOptions struct { Verbose bool } -// Checkpoint represents the details of a checkpoint -type Checkpoint struct { - Name string // Name is the name of the checkpoint -} - // DiskUsageObject represents an object type used for disk usage query filtering. type DiskUsageObject string diff --git a/api/types/types_deprecated.go b/api/types/types_deprecated.go index e12e348810..3d0174b756 100644 --- a/api/types/types_deprecated.go +++ b/api/types/types_deprecated.go @@ -1,6 +1,29 @@ package types -import "github.com/docker/docker/api/types/system" +import ( + "github.com/docker/docker/api/types/checkpoint" + "github.com/docker/docker/api/types/system" +) + +// CheckpointCreateOptions holds parameters to create a checkpoint from a container. +// +// Deprecated: use [checkpoint.CreateOptions]. +type CheckpointCreateOptions = checkpoint.CreateOptions + +// CheckpointListOptions holds parameters to list checkpoints for a container +// +// Deprecated: use [checkpoint.ListOptions]. +type CheckpointListOptions = checkpoint.ListOptions + +// CheckpointDeleteOptions holds parameters to delete a checkpoint from a container +// +// Deprecated: use [checkpoint.DeleteOptions]. +type CheckpointDeleteOptions = checkpoint.DeleteOptions + +// Checkpoint represents the details of a checkpoint when listing endpoints. +// +// Deprecated: use [checkpoint.Summary]. +type Checkpoint = checkpoint.Summary // Info contains response of Engine API: // GET "/info" diff --git a/client/checkpoint_create.go b/client/checkpoint_create.go index 921024fe4f..9746d288df 100644 --- a/client/checkpoint_create.go +++ b/client/checkpoint_create.go @@ -3,11 +3,11 @@ package client // import "github.com/docker/docker/client" import ( "context" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/checkpoint" ) // CheckpointCreate creates a checkpoint from the given container with the given name -func (cli *Client) CheckpointCreate(ctx context.Context, container string, options types.CheckpointCreateOptions) error { +func (cli *Client) CheckpointCreate(ctx context.Context, container string, options checkpoint.CreateOptions) error { resp, err := cli.post(ctx, "/containers/"+container+"/checkpoints", nil, options, nil) ensureReaderClosed(resp) return err diff --git a/client/checkpoint_create_test.go b/client/checkpoint_create_test.go index 240394188b..44dc4a3bc7 100644 --- a/client/checkpoint_create_test.go +++ b/client/checkpoint_create_test.go @@ -10,7 +10,7 @@ import ( "strings" "testing" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/checkpoint" "github.com/docker/docker/errdefs" "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" @@ -20,7 +20,7 @@ func TestCheckpointCreateError(t *testing.T) { client := &Client{ client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), } - err := client.CheckpointCreate(context.Background(), "nothing", types.CheckpointCreateOptions{ + err := client.CheckpointCreate(context.Background(), "nothing", checkpoint.CreateOptions{ CheckpointID: "noting", Exit: true, }) @@ -43,7 +43,7 @@ func TestCheckpointCreate(t *testing.T) { return nil, fmt.Errorf("expected POST method, got %s", req.Method) } - createOptions := &types.CheckpointCreateOptions{} + createOptions := &checkpoint.CreateOptions{} if err := json.NewDecoder(req.Body).Decode(createOptions); err != nil { return nil, err } @@ -63,7 +63,7 @@ func TestCheckpointCreate(t *testing.T) { }), } - err := client.CheckpointCreate(context.Background(), expectedContainerID, types.CheckpointCreateOptions{ + err := client.CheckpointCreate(context.Background(), expectedContainerID, checkpoint.CreateOptions{ CheckpointID: expectedCheckpointID, Exit: true, }) diff --git a/client/checkpoint_delete.go b/client/checkpoint_delete.go index 54f55fa76e..b968c2b237 100644 --- a/client/checkpoint_delete.go +++ b/client/checkpoint_delete.go @@ -4,11 +4,11 @@ import ( "context" "net/url" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/checkpoint" ) // CheckpointDelete deletes the checkpoint with the given name from the given container -func (cli *Client) CheckpointDelete(ctx context.Context, containerID string, options types.CheckpointDeleteOptions) error { +func (cli *Client) CheckpointDelete(ctx context.Context, containerID string, options checkpoint.DeleteOptions) error { query := url.Values{} if options.CheckpointDir != "" { query.Set("dir", options.CheckpointDir) diff --git a/client/checkpoint_delete_test.go b/client/checkpoint_delete_test.go index 843995a2e2..7ce3af2a06 100644 --- a/client/checkpoint_delete_test.go +++ b/client/checkpoint_delete_test.go @@ -9,7 +9,7 @@ import ( "strings" "testing" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/checkpoint" "github.com/docker/docker/errdefs" "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" @@ -20,7 +20,7 @@ func TestCheckpointDeleteError(t *testing.T) { client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), } - err := client.CheckpointDelete(context.Background(), "container_id", types.CheckpointDeleteOptions{ + err := client.CheckpointDelete(context.Background(), "container_id", checkpoint.DeleteOptions{ CheckpointID: "checkpoint_id", }) @@ -45,7 +45,7 @@ func TestCheckpointDelete(t *testing.T) { }), } - err := client.CheckpointDelete(context.Background(), "container_id", types.CheckpointDeleteOptions{ + err := client.CheckpointDelete(context.Background(), "container_id", checkpoint.DeleteOptions{ CheckpointID: "checkpoint_id", }) if err != nil { diff --git a/client/checkpoint_list.go b/client/checkpoint_list.go index 39cfb959ff..8feb1f3f7d 100644 --- a/client/checkpoint_list.go +++ b/client/checkpoint_list.go @@ -5,12 +5,12 @@ import ( "encoding/json" "net/url" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/checkpoint" ) // CheckpointList returns the checkpoints of the given container in the docker host -func (cli *Client) CheckpointList(ctx context.Context, container string, options types.CheckpointListOptions) ([]types.Checkpoint, error) { - var checkpoints []types.Checkpoint +func (cli *Client) CheckpointList(ctx context.Context, container string, options checkpoint.ListOptions) ([]checkpoint.Summary, error) { + var checkpoints []checkpoint.Summary query := url.Values{} if options.CheckpointDir != "" { diff --git a/client/checkpoint_list_test.go b/client/checkpoint_list_test.go index 43aca75135..532ba1adb5 100644 --- a/client/checkpoint_list_test.go +++ b/client/checkpoint_list_test.go @@ -10,7 +10,7 @@ import ( "strings" "testing" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/checkpoint" "github.com/docker/docker/errdefs" "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" @@ -21,7 +21,7 @@ func TestCheckpointListError(t *testing.T) { client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), } - _, err := client.CheckpointList(context.Background(), "container_id", types.CheckpointListOptions{}) + _, err := client.CheckpointList(context.Background(), "container_id", checkpoint.ListOptions{}) assert.Check(t, is.ErrorType(err, errdefs.IsSystem)) } @@ -33,7 +33,7 @@ func TestCheckpointList(t *testing.T) { if !strings.HasPrefix(req.URL.Path, expectedURL) { return nil, fmt.Errorf("Expected URL '%s', got '%s'", expectedURL, req.URL) } - content, err := json.Marshal([]types.Checkpoint{ + content, err := json.Marshal([]checkpoint.Summary{ { Name: "checkpoint", }, @@ -48,7 +48,7 @@ func TestCheckpointList(t *testing.T) { }), } - checkpoints, err := client.CheckpointList(context.Background(), "container_id", types.CheckpointListOptions{}) + checkpoints, err := client.CheckpointList(context.Background(), "container_id", checkpoint.ListOptions{}) if err != nil { t.Fatal(err) } @@ -62,6 +62,6 @@ func TestCheckpointListContainerNotFound(t *testing.T) { client: newMockClient(errorMock(http.StatusNotFound, "Server error")), } - _, err := client.CheckpointList(context.Background(), "unknown", types.CheckpointListOptions{}) + _, err := client.CheckpointList(context.Background(), "unknown", checkpoint.ListOptions{}) assert.Check(t, is.ErrorType(err, errdefs.IsNotFound)) } diff --git a/client/interface_experimental.go b/client/interface_experimental.go index 402ffb512c..c585c10459 100644 --- a/client/interface_experimental.go +++ b/client/interface_experimental.go @@ -3,7 +3,7 @@ package client // import "github.com/docker/docker/client" import ( "context" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/checkpoint" ) type apiClientExperimental interface { @@ -12,7 +12,7 @@ type apiClientExperimental interface { // CheckpointAPIClient defines API client methods for the checkpoints type CheckpointAPIClient interface { - CheckpointCreate(ctx context.Context, container string, options types.CheckpointCreateOptions) error - CheckpointDelete(ctx context.Context, container string, options types.CheckpointDeleteOptions) error - CheckpointList(ctx context.Context, container string, options types.CheckpointListOptions) ([]types.Checkpoint, error) + CheckpointCreate(ctx context.Context, container string, options checkpoint.CreateOptions) error + CheckpointDelete(ctx context.Context, container string, options checkpoint.DeleteOptions) error + CheckpointList(ctx context.Context, container string, options checkpoint.ListOptions) ([]checkpoint.Summary, error) } diff --git a/daemon/checkpoint.go b/daemon/checkpoint.go index 9da1cc3ee9..d849bd0414 100644 --- a/daemon/checkpoint.go +++ b/daemon/checkpoint.go @@ -6,7 +6,7 @@ import ( "os" "path/filepath" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/checkpoint" "github.com/docker/docker/daemon/names" ) @@ -51,7 +51,7 @@ func getCheckpointDir(checkDir, checkpointID, ctrName, ctrID, ctrCheckpointDir s } // CheckpointCreate checkpoints the process running in a container with CRIU -func (daemon *Daemon) CheckpointCreate(name string, config types.CheckpointCreateOptions) error { +func (daemon *Daemon) CheckpointCreate(name string, config checkpoint.CreateOptions) error { container, err := daemon.GetContainer(name) if err != nil { return err @@ -85,7 +85,7 @@ func (daemon *Daemon) CheckpointCreate(name string, config types.CheckpointCreat } // CheckpointDelete deletes the specified checkpoint -func (daemon *Daemon) CheckpointDelete(name string, config types.CheckpointDeleteOptions) error { +func (daemon *Daemon) CheckpointDelete(name string, config checkpoint.DeleteOptions) error { container, err := daemon.GetContainer(name) if err != nil { return err @@ -98,8 +98,8 @@ func (daemon *Daemon) CheckpointDelete(name string, config types.CheckpointDelet } // CheckpointList lists all checkpoints of the specified container -func (daemon *Daemon) CheckpointList(name string, config types.CheckpointListOptions) ([]types.Checkpoint, error) { - var out []types.Checkpoint +func (daemon *Daemon) CheckpointList(name string, config checkpoint.ListOptions) ([]checkpoint.Summary, error) { + var out []checkpoint.Summary container, err := daemon.GetContainer(name) if err != nil { @@ -124,7 +124,7 @@ func (daemon *Daemon) CheckpointList(name string, config types.CheckpointListOpt if !d.IsDir() { continue } - cpt := types.Checkpoint{Name: d.Name()} + cpt := checkpoint.Summary{Name: d.Name()} out = append(out, cpt) } diff --git a/integration/container/checkpoint_test.go b/integration/container/checkpoint_test.go index 71a3a94296..edb07fe87f 100644 --- a/integration/container/checkpoint_test.go +++ b/integration/container/checkpoint_test.go @@ -9,6 +9,7 @@ import ( "time" "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/checkpoint" mounttypes "github.com/docker/docker/api/types/mount" "github.com/docker/docker/client" "github.com/docker/docker/integration/internal/container" @@ -56,7 +57,7 @@ func TestCheckpoint(t *testing.T) { poll.WithDelay(100*time.Millisecond), ) - cptOpt := types.CheckpointCreateOptions{ + cptOpt := checkpoint.CreateOptions{ Exit: false, CheckpointID: "test", } @@ -100,7 +101,7 @@ func TestCheckpoint(t *testing.T) { assert.NilError(t, err) assert.Check(t, is.Equal(true, inspect.State.Running)) - checkpoints, err := apiClient.CheckpointList(ctx, cID, types.CheckpointListOptions{}) + checkpoints, err := apiClient.CheckpointList(ctx, cID, checkpoint.ListOptions{}) assert.NilError(t, err) assert.Equal(t, len(checkpoints), 1) assert.Equal(t, checkpoints[0].Name, "test") @@ -109,7 +110,7 @@ func TestCheckpoint(t *testing.T) { containerExec(t, apiClient, cID, []string{"touch", "/tmp/test-file"}) // Do a second checkpoint - cptOpt = types.CheckpointCreateOptions{ + cptOpt = checkpoint.CreateOptions{ Exit: true, CheckpointID: "test2", } @@ -127,7 +128,7 @@ func TestCheckpoint(t *testing.T) { assert.Check(t, is.Equal(false, inspect.State.Running)) // Check that both checkpoints are listed. - checkpoints, err = apiClient.CheckpointList(ctx, cID, types.CheckpointListOptions{}) + checkpoints, err = apiClient.CheckpointList(ctx, cID, checkpoint.ListOptions{}) assert.NilError(t, err) assert.Equal(t, len(checkpoints), 2) cptNames := make([]string, 2) @@ -154,7 +155,7 @@ func TestCheckpoint(t *testing.T) { containerExec(t, apiClient, cID, []string{"test", "-f", "/tmp/test-file"}) for _, id := range []string{"test", "test2"} { - cptDelOpt := types.CheckpointDeleteOptions{ + cptDelOpt := checkpoint.DeleteOptions{ CheckpointID: id, }