From 21e475c1c3b2ca26958a115f11ed5681321a1187 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 14 Feb 2022 10:23:57 +0100 Subject: [PATCH 1/8] api/swagger: add missing 400 response for POST /containers/{id}/wait The /containers/{id}/wait can return a 400 (invalid argument) error if httputils.ParseForm() fails. Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 0e5929f99dd4b0a4896dc21a93f33654714b58d3) Signed-off-by: Bjorn Neergaard --- api/swagger.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/api/swagger.yaml b/api/swagger.yaml index c24f57bc9a7a1..427bd2f279e66 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -6910,6 +6910,10 @@ paths: Message: description: "Details of an error" type: "string" + 400: + description: "bad parameter" + schema: + $ref: "#/definitions/ErrorResponse" 404: description: "no such container" schema: From 7e7b59b8ae3a6a125ebc55d74ab42a4e58311fc4 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 5 Mar 2022 15:02:03 +0100 Subject: [PATCH 2/8] api: swagger: move Volume examples inline Signed-off-by: Sebastiaan van Stijn (cherry picked from commit e444ac3470c67509ca19afcbac02af0c5e921d3c) Signed-off-by: Bjorn Neergaard --- api/swagger.yaml | 43 ++++++++++++++----------------------------- 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/api/swagger.yaml b/api/swagger.yaml index 427bd2f279e66..8644ae417f3ca 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -1680,18 +1680,22 @@ definitions: type: "string" description: "Name of the volume." x-nullable: false + example: "tardis" Driver: type: "string" description: "Name of the volume driver used by the volume." x-nullable: false + example: "custom" Mountpoint: type: "string" description: "Mount path of the volume on the host." x-nullable: false + example: "/var/lib/docker/volumes/tardis" CreatedAt: type: "string" format: "dateTime" description: "Date/Time the volume was created." + example: "2016-06-07T20:31:11.853781916Z" Status: type: "object" description: | @@ -1703,12 +1707,17 @@ definitions: does not support this feature. additionalProperties: type: "object" + example: + hello: "world" Labels: type: "object" description: "User-defined key/value metadata." x-nullable: false additionalProperties: type: "string" + example: + com.example.some-label: "some-value" + com.example.some-other-label: "some-other-value" Scope: type: "string" description: | @@ -1717,12 +1726,17 @@ definitions: default: "local" x-nullable: false enum: ["local", "global"] + example: "local" Options: type: "object" description: | The driver specific options used when creating the volume. additionalProperties: type: "string" + example: + device: "tmpfs" + o: "size=100m,uid=1000" + type: "tmpfs" UsageData: type: "object" x-nullable: true @@ -1748,18 +1762,6 @@ definitions: is set to `-1` if the reference-count is not available. x-nullable: false - example: - Name: "tardis" - Driver: "custom" - Mountpoint: "/var/lib/docker/volumes/tardis" - Status: - hello: "world" - Labels: - com.example.some-label: "some-value" - com.example.some-other-label: "some-other-value" - Scope: "local" - CreatedAt: "2016-06-07T20:31:11.853781916Z" - Network: type: "object" properties: @@ -8791,23 +8793,6 @@ paths: Warnings that occurred when fetching the list of volumes. items: type: "string" - - examples: - application/json: - Volumes: - - CreatedAt: "2017-07-19T12:00:26Z" - Name: "tardis" - Driver: "local" - Mountpoint: "/var/lib/docker/volumes/tardis" - Labels: - com.example.some-label: "some-value" - com.example.some-other-label: "some-other-value" - Scope: "local" - Options: - device: "tmpfs" - o: "size=100m,uid=1000" - type: "tmpfs" - Warnings: [] 500: description: "Server error" schema: From 726e718a24683aad910921b412aa9d3434eec673 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 5 Mar 2022 15:31:04 +0100 Subject: [PATCH 3/8] api: swagger: move VolumeCreateOptions to definitions Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 0119f7973b75378491653b0e025ca1b63ce58e4f) Signed-off-by: Bjorn Neergaard --- api/swagger.yaml | 71 ++++++++++++++------------ api/types/volume/volume_create.go | 31 ----------- api/types/volume/volume_create_body.go | 26 ++++++++++ hack/generate-swagger-api.sh | 5 +- 4 files changed, 69 insertions(+), 64 deletions(-) delete mode 100644 api/types/volume/volume_create.go create mode 100644 api/types/volume/volume_create_body.go diff --git a/api/swagger.yaml b/api/swagger.yaml index 8644ae417f3ca..7b14869fca2cb 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -1762,6 +1762,44 @@ definitions: is set to `-1` if the reference-count is not available. x-nullable: false + VolumeCreateOptions: + description: "Volume configuration" + type: "object" + title: "VolumeConfig" + x-go-name: "VolumeCreateBody" + properties: + Name: + description: | + The new volume's name. If not specified, Docker generates a name. + type: "string" + x-nullable: false + example: "tardis" + Driver: + description: "Name of the volume driver to use." + type: "string" + default: "local" + x-nullable: false + example: "custom" + DriverOpts: + description: | + A mapping of driver options and values. These options are + passed directly to the driver and are driver specific. + type: "object" + additionalProperties: + type: "string" + example: + device: "tmpfs" + o: "size=100m,uid=1000" + type: "tmpfs" + Labels: + description: "User-defined key/value metadata." + type: "object" + additionalProperties: + type: "string" + example: + com.example.some-label: "some-value" + com.example.some-other-label: "some-other-value" + Network: type: "object" properties: @@ -8837,38 +8875,7 @@ paths: required: true description: "Volume configuration" schema: - type: "object" - description: "Volume configuration" - title: "VolumeConfig" - properties: - Name: - description: | - The new volume's name. If not specified, Docker generates a name. - type: "string" - x-nullable: false - Driver: - description: "Name of the volume driver to use." - type: "string" - default: "local" - x-nullable: false - DriverOpts: - description: | - A mapping of driver options and values. These options are - passed directly to the driver and are driver specific. - type: "object" - additionalProperties: - type: "string" - Labels: - description: "User-defined key/value metadata." - type: "object" - additionalProperties: - type: "string" - example: - Name: "tardis" - Labels: - com.example.some-label: "some-value" - com.example.some-other-label: "some-other-value" - Driver: "custom" + $ref: "#/definitions/VolumeCreateOptions" tags: ["Volume"] /volumes/{name}: diff --git a/api/types/volume/volume_create.go b/api/types/volume/volume_create.go deleted file mode 100644 index 8538078dd663c..0000000000000 --- a/api/types/volume/volume_create.go +++ /dev/null @@ -1,31 +0,0 @@ -package volume // import "github.com/docker/docker/api/types/volume" - -// ---------------------------------------------------------------------------- -// Code generated by `swagger generate operation`. DO NOT EDIT. -// -// See hack/generate-swagger-api.sh -// ---------------------------------------------------------------------------- - -// VolumeCreateBody Volume configuration -// swagger:model VolumeCreateBody -type VolumeCreateBody struct { - - // Name of the volume driver to use. - // Required: true - Driver string `json:"Driver"` - - // A mapping of driver options and values. These options are - // passed directly to the driver and are driver specific. - // - // Required: true - DriverOpts map[string]string `json:"DriverOpts"` - - // User-defined key/value metadata. - // Required: true - Labels map[string]string `json:"Labels"` - - // The new volume's name. If not specified, Docker generates a name. - // - // Required: true - Name string `json:"Name"` -} diff --git a/api/types/volume/volume_create_body.go b/api/types/volume/volume_create_body.go new file mode 100644 index 0000000000000..f40fe1377f5df --- /dev/null +++ b/api/types/volume/volume_create_body.go @@ -0,0 +1,26 @@ +package volume + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +// VolumeCreateBody VolumeConfig +// +// Volume configuration +// swagger:model VolumeCreateBody +type VolumeCreateBody struct { + + // Name of the volume driver to use. + Driver string `json:"Driver,omitempty"` + + // A mapping of driver options and values. These options are + // passed directly to the driver and are driver specific. + // + DriverOpts map[string]string `json:"DriverOpts,omitempty"` + + // User-defined key/value metadata. + Labels map[string]string `json:"Labels,omitempty"` + + // The new volume's name. If not specified, Docker generates a name. + // + Name string `json:"Name,omitempty"` +} diff --git a/hack/generate-swagger-api.sh b/hack/generate-swagger-api.sh index 90a01df02757b..9a54cf9c97997 100755 --- a/hack/generate-swagger-api.sh +++ b/hack/generate-swagger-api.sh @@ -13,6 +13,10 @@ swagger generate model -f api/swagger.yaml \ -n ServiceUpdateResponse \ -n Volume +swagger generate model -f api/swagger.yaml \ + -t api -m types/volume --skip-validator -C api/swagger-gen.yaml \ + -n VolumeCreateOptions + swagger generate operation -f api/swagger.yaml \ -t api -a types -m types -C api/swagger-gen.yaml \ -T api/templates --skip-responses --skip-parameters --skip-validator \ @@ -23,5 +27,4 @@ swagger generate operation -f api/swagger.yaml \ -n ContainerUpdate \ -n ContainerWait \ -n ImageHistory \ - -n VolumeCreate \ -n VolumeList From f020b87f9281508f65027fa7efb5fdae6b9db171 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 18 Feb 2022 18:07:40 +0100 Subject: [PATCH 4/8] daemon/config: DefaultShmSize: minor tweak and improve docs I had to check what the actual size was, so added it to the const's documentation. While at it, also made use of it in a test, so that we're testing against the expected value, and changed one alias to be consistent with other places where we alias this import. Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 821b4d410857debdfb539db18952f86feb7609f8) Signed-off-by: Bjorn Neergaard --- daemon/config/config.go | 4 ++-- daemon/oci_linux.go | 6 +++--- integration-cli/docker_api_containers_test.go | 5 +++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/daemon/config/config.go b/daemon/config/config.go index 69971d370b3f7..8e50b54dbac16 100644 --- a/daemon/config/config.go +++ b/daemon/config/config.go @@ -35,8 +35,8 @@ const ( // maximum number of attempts that // may take place at a time for each pull when the connection is lost. DefaultDownloadAttempts = 5 - // DefaultShmSize is the default value for container's shm size - DefaultShmSize = int64(67108864) + // DefaultShmSize is the default value for container's shm size (64 MiB) + DefaultShmSize int64 = 64 * 1024 * 1024 // DefaultNetworkMtu is the default value for network MTU DefaultNetworkMtu = 1500 // DisableNetworkBridge is the default value of the option to disable network bridge diff --git a/daemon/oci_linux.go b/daemon/oci_linux.go index 7b9a5dd03eb4a..e72c8b5e61792 100644 --- a/daemon/oci_linux.go +++ b/daemon/oci_linux.go @@ -16,7 +16,7 @@ import ( "github.com/containerd/containerd/sys" containertypes "github.com/docker/docker/api/types/container" "github.com/docker/docker/container" - daemonconfig "github.com/docker/docker/daemon/config" + dconfig "github.com/docker/docker/daemon/config" "github.com/docker/docker/oci" "github.com/docker/docker/oci/caps" "github.com/docker/docker/pkg/idtools" @@ -35,7 +35,7 @@ import ( "golang.org/x/sys/unix" ) -const inContainerInitPath = "/sbin/" + daemonconfig.DefaultInitBinary +const inContainerInitPath = "/sbin/" + dconfig.DefaultInitBinary // WithRlimits sets the container's rlimits along with merging the daemon's rlimits func WithRlimits(daemon *Daemon, c *container.Container) coci.SpecOpts { @@ -740,7 +740,7 @@ func WithCommonOptions(daemon *Daemon, c *container.Container) coci.SpecOpts { s.Process.Args = append([]string{inContainerInitPath, "--", c.Path}, c.Args...) path := daemon.configStore.InitPath if path == "" { - path, err = exec.LookPath(daemonconfig.DefaultInitBinary) + path, err = exec.LookPath(dconfig.DefaultInitBinary) if err != nil { return err } diff --git a/integration-cli/docker_api_containers_test.go b/integration-cli/docker_api_containers_test.go index 75af8fe2d2257..878ddfe0e13f6 100644 --- a/integration-cli/docker_api_containers_test.go +++ b/integration-cli/docker_api_containers_test.go @@ -22,6 +22,7 @@ import ( networktypes "github.com/docker/docker/api/types/network" "github.com/docker/docker/api/types/versions" "github.com/docker/docker/client" + dconfig "github.com/docker/docker/daemon/config" "github.com/docker/docker/integration-cli/cli" "github.com/docker/docker/integration-cli/cli/build" "github.com/docker/docker/pkg/ioutils" @@ -1441,7 +1442,7 @@ func (s *DockerSuite) TestPostContainersCreateShmSizeNegative(c *testing.T) { func (s *DockerSuite) TestPostContainersCreateShmSizeHostConfigOmitted(c *testing.T) { // ShmSize is not supported on Windows testRequires(c, DaemonIsLinux) - var defaultSHMSize int64 = 67108864 + config := containertypes.Config{ Image: "busybox", Cmd: []string{"mount"}, @@ -1457,7 +1458,7 @@ func (s *DockerSuite) TestPostContainersCreateShmSizeHostConfigOmitted(c *testin containerJSON, err := cli.ContainerInspect(context.Background(), container.ID) assert.NilError(c, err) - assert.Equal(c, containerJSON.HostConfig.ShmSize, defaultSHMSize) + assert.Equal(c, containerJSON.HostConfig.ShmSize, dconfig.DefaultShmSize) out, _ := dockerCmd(c, "start", "-i", containerJSON.ID) shmRegexp := regexp.MustCompile(`shm on /dev/shm type tmpfs(.*)size=65536k`) From 1ad3c5073b672d6b34f8ec32577433dbc59ddc2e Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 5 Mar 2022 17:02:03 +0100 Subject: [PATCH 5/8] api: swagger: move ContainerWaitResponse to definitions This should help with CI being unstable when generating the types (due to Go randomizing order). Unfortunately, the (file) names are a bit ugly, but addressing that in a follow-up. Signed-off-by: Sebastiaan van Stijn (cherry picked from commit e4c6ca36aea01bfebe34d09c728e60ebe35a0442) Signed-off-by: Bjorn Neergaard --- api/swagger.yaml | 40 +++++++++++-------- api/types/container/container_wait.go | 28 ------------- .../container/container_wait_o_k_body.go | 19 +++++++++ .../container_wait_o_k_body_error.go | 12 ++++++ hack/generate-swagger-api.sh | 6 ++- 5 files changed, 60 insertions(+), 45 deletions(-) delete mode 100644 api/types/container/container_wait.go create mode 100644 api/types/container/container_wait_o_k_body.go create mode 100644 api/types/container/container_wait_o_k_body_error.go diff --git a/api/swagger.yaml b/api/swagger.yaml index 7b14869fca2cb..40c5e1870669a 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -4340,6 +4340,29 @@ definitions: x-nullable: true $ref: "#/definitions/Health" + ContainerWaitResponse: + description: "OK response to ContainerWait operation" + type: "object" + x-go-name: "ContainerWaitOKBody" + title: "ContainerWaitResponse" + required: [StatusCode, Error] + properties: + StatusCode: + description: "Exit code of the container" + type: "integer" + x-nullable: false + Error: + $ref: "#/definitions/ContainerWaitExitError" + + ContainerWaitExitError: + description: "container waiting error, if any" + type: "object" + x-go-name: "ContainerWaitOKBodyError" + properties: + Message: + description: "Details of an error" + type: "string" + SystemVersion: type: "object" description: | @@ -6934,22 +6957,7 @@ paths: 200: description: "The container has exit." schema: - type: "object" - title: "ContainerWaitResponse" - description: "OK response to ContainerWait operation" - required: [StatusCode] - properties: - StatusCode: - description: "Exit code of the container" - type: "integer" - x-nullable: false - Error: - description: "container waiting error, if any" - type: "object" - properties: - Message: - description: "Details of an error" - type: "string" + $ref: "#/definitions/ContainerWaitResponse" 400: description: "bad parameter" schema: diff --git a/api/types/container/container_wait.go b/api/types/container/container_wait.go deleted file mode 100644 index 49e05ae669449..0000000000000 --- a/api/types/container/container_wait.go +++ /dev/null @@ -1,28 +0,0 @@ -package container // import "github.com/docker/docker/api/types/container" - -// ---------------------------------------------------------------------------- -// Code generated by `swagger generate operation`. DO NOT EDIT. -// -// See hack/generate-swagger-api.sh -// ---------------------------------------------------------------------------- - -// ContainerWaitOKBodyError container waiting error, if any -// swagger:model ContainerWaitOKBodyError -type ContainerWaitOKBodyError struct { - - // Details of an error - Message string `json:"Message,omitempty"` -} - -// ContainerWaitOKBody OK response to ContainerWait operation -// swagger:model ContainerWaitOKBody -type ContainerWaitOKBody struct { - - // error - // Required: true - Error *ContainerWaitOKBodyError `json:"Error"` - - // Exit code of the container - // Required: true - StatusCode int64 `json:"StatusCode"` -} diff --git a/api/types/container/container_wait_o_k_body.go b/api/types/container/container_wait_o_k_body.go new file mode 100644 index 0000000000000..3219207fbbdbc --- /dev/null +++ b/api/types/container/container_wait_o_k_body.go @@ -0,0 +1,19 @@ +package container + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +// ContainerWaitOKBody ContainerWaitResponse +// +// OK response to ContainerWait operation +// swagger:model ContainerWaitOKBody +type ContainerWaitOKBody struct { + + // error + // Required: true + Error *ContainerWaitOKBodyError `json:"Error"` + + // Exit code of the container + // Required: true + StatusCode int64 `json:"StatusCode"` +} diff --git a/api/types/container/container_wait_o_k_body_error.go b/api/types/container/container_wait_o_k_body_error.go new file mode 100644 index 0000000000000..ee598973ec5fe --- /dev/null +++ b/api/types/container/container_wait_o_k_body_error.go @@ -0,0 +1,12 @@ +package container + +// This file was generated by the swagger tool. +// Editing this file might prove futile when you re-run the swagger generate command + +// ContainerWaitOKBodyError container waiting error, if any +// swagger:model ContainerWaitOKBodyError +type ContainerWaitOKBodyError struct { + + // Details of an error + Message string `json:"Message,omitempty"` +} diff --git a/hack/generate-swagger-api.sh b/hack/generate-swagger-api.sh index 9a54cf9c97997..e300212e359c5 100755 --- a/hack/generate-swagger-api.sh +++ b/hack/generate-swagger-api.sh @@ -13,6 +13,11 @@ swagger generate model -f api/swagger.yaml \ -n ServiceUpdateResponse \ -n Volume +swagger generate model -f api/swagger.yaml \ + -t api -m types/container --skip-validator -C api/swagger-gen.yaml \ + -n ContainerWaitResponse \ + -n ContainerWaitExitError + swagger generate model -f api/swagger.yaml \ -t api -m types/volume --skip-validator -C api/swagger-gen.yaml \ -n VolumeCreateOptions @@ -25,6 +30,5 @@ swagger generate operation -f api/swagger.yaml \ -n ContainerCreate \ -n ContainerTop \ -n ContainerUpdate \ - -n ContainerWait \ -n ImageHistory \ -n VolumeList From 011d9f0cc34f9da43c10f0154464e7a384b96871 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sun, 17 Apr 2022 13:47:37 +0200 Subject: [PATCH 6/8] client, integration-cli: remove unneeded import aliases Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 9060126639e9141082ab0edbdce921895058af88) Signed-off-by: Bjorn Neergaard --- client/interface.go | 22 +- integration-cli/docker_api_containers_test.go | 314 +++++++++--------- 2 files changed, 168 insertions(+), 168 deletions(-) diff --git a/client/interface.go b/client/interface.go index aabad4a911050..09bc111116adb 100644 --- a/client/interface.go +++ b/client/interface.go @@ -8,14 +8,14 @@ import ( "time" "github.com/docker/docker/api/types" - containertypes "github.com/docker/docker/api/types/container" + "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/events" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/image" - networktypes "github.com/docker/docker/api/types/network" + "github.com/docker/docker/api/types/network" "github.com/docker/docker/api/types/registry" "github.com/docker/docker/api/types/swarm" - volumetypes "github.com/docker/docker/api/types/volume" + "github.com/docker/docker/api/types/volume" specs "github.com/opencontainers/image-spec/specs-go/v1" ) @@ -48,8 +48,8 @@ type CommonAPIClient interface { type ContainerAPIClient interface { ContainerAttach(ctx context.Context, container string, options types.ContainerAttachOptions) (types.HijackedResponse, error) ContainerCommit(ctx context.Context, container string, options types.ContainerCommitOptions) (types.IDResponse, error) - ContainerCreate(ctx context.Context, config *containertypes.Config, hostConfig *containertypes.HostConfig, networkingConfig *networktypes.NetworkingConfig, platform *specs.Platform, containerName string) (containertypes.ContainerCreateCreatedBody, error) - ContainerDiff(ctx context.Context, container string) ([]containertypes.ContainerChangeResponseItem, error) + ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, platform *specs.Platform, containerName string) (container.ContainerCreateCreatedBody, error) + ContainerDiff(ctx context.Context, container string) ([]container.ContainerChangeResponseItem, error) ContainerExecAttach(ctx context.Context, execID string, config types.ExecStartCheck) (types.HijackedResponse, error) ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.IDResponse, error) ContainerExecInspect(ctx context.Context, execID string) (types.ContainerExecInspect, error) @@ -71,10 +71,10 @@ type ContainerAPIClient interface { ContainerStatsOneShot(ctx context.Context, container string) (types.ContainerStats, error) ContainerStart(ctx context.Context, container string, options types.ContainerStartOptions) error ContainerStop(ctx context.Context, container string, timeout *time.Duration) error - ContainerTop(ctx context.Context, container string, arguments []string) (containertypes.ContainerTopOKBody, error) + ContainerTop(ctx context.Context, container string, arguments []string) (container.ContainerTopOKBody, error) ContainerUnpause(ctx context.Context, container string) error - ContainerUpdate(ctx context.Context, container string, updateConfig containertypes.UpdateConfig) (containertypes.ContainerUpdateOKBody, error) - ContainerWait(ctx context.Context, container string, condition containertypes.WaitCondition) (<-chan containertypes.ContainerWaitOKBody, <-chan error) + ContainerUpdate(ctx context.Context, container string, updateConfig container.UpdateConfig) (container.ContainerUpdateOKBody, error) + ContainerWait(ctx context.Context, container string, condition container.WaitCondition) (<-chan container.ContainerWaitOKBody, <-chan error) CopyFromContainer(ctx context.Context, container, srcPath string) (io.ReadCloser, types.ContainerPathStat, error) CopyToContainer(ctx context.Context, container, path string, content io.Reader, options types.CopyToContainerOptions) error ContainersPrune(ctx context.Context, pruneFilters filters.Args) (types.ContainersPruneReport, error) @@ -107,7 +107,7 @@ type ImageAPIClient interface { // NetworkAPIClient defines API client methods for the networks type NetworkAPIClient interface { - NetworkConnect(ctx context.Context, network, container string, config *networktypes.EndpointSettings) error + NetworkConnect(ctx context.Context, network, container string, config *network.EndpointSettings) error NetworkCreate(ctx context.Context, name string, options types.NetworkCreate) (types.NetworkCreateResponse, error) NetworkDisconnect(ctx context.Context, network, container string, force bool) error NetworkInspect(ctx context.Context, network string, options types.NetworkInspectOptions) (types.NetworkResource, error) @@ -174,10 +174,10 @@ type SystemAPIClient interface { // VolumeAPIClient defines API client methods for the volumes type VolumeAPIClient interface { - VolumeCreate(ctx context.Context, options volumetypes.VolumeCreateBody) (types.Volume, error) + VolumeCreate(ctx context.Context, options volume.VolumeCreateBody) (types.Volume, error) VolumeInspect(ctx context.Context, volumeID string) (types.Volume, error) VolumeInspectWithRaw(ctx context.Context, volumeID string) (types.Volume, []byte, error) - VolumeList(ctx context.Context, filter filters.Args) (volumetypes.VolumeListOKBody, error) + VolumeList(ctx context.Context, filter filters.Args) (volume.VolumeListOKBody, error) VolumeRemove(ctx context.Context, volumeID string, force bool) error VolumesPrune(ctx context.Context, pruneFilter filters.Args) (types.VolumesPruneReport, error) } diff --git a/integration-cli/docker_api_containers_test.go b/integration-cli/docker_api_containers_test.go index 878ddfe0e13f6..19df33c0bd76c 100644 --- a/integration-cli/docker_api_containers_test.go +++ b/integration-cli/docker_api_containers_test.go @@ -17,9 +17,9 @@ import ( "time" "github.com/docker/docker/api/types" - containertypes "github.com/docker/docker/api/types/container" - mounttypes "github.com/docker/docker/api/types/mount" - networktypes "github.com/docker/docker/api/types/network" + "github.com/docker/docker/api/types/container" + "github.com/docker/docker/api/types/mount" + "github.com/docker/docker/api/types/network" "github.com/docker/docker/api/types/versions" "github.com/docker/docker/client" dconfig "github.com/docker/docker/daemon/config" @@ -475,7 +475,7 @@ func (s *DockerSuite) TestContainerAPICommitWithLabelInConfig(c *testing.T) { assert.NilError(c, err) defer cli.Close() - config := containertypes.Config{ + config := container.Config{ Labels: map[string]string{"key1": "value1", "key2": "value2"}} options := types.ContainerCommitOptions{ @@ -503,12 +503,12 @@ func (s *DockerSuite) TestContainerAPIBadPort(c *testing.T) { // TODO Windows to Windows CI - Port this test testRequires(c, DaemonIsLinux) - config := containertypes.Config{ + config := container.Config{ Image: "busybox", Cmd: []string{"/bin/sh", "-c", "echo test"}, } - hostConfig := containertypes.HostConfig{ + hostConfig := container.HostConfig{ PortBindings: nat.PortMap{ "8080/tcp": []nat.PortBinding{ { @@ -522,12 +522,12 @@ func (s *DockerSuite) TestContainerAPIBadPort(c *testing.T) { assert.NilError(c, err) defer cli.Close() - _, err = cli.ContainerCreate(context.Background(), &config, &hostConfig, &networktypes.NetworkingConfig{}, nil, "") + _, err = cli.ContainerCreate(context.Background(), &config, &hostConfig, &network.NetworkingConfig{}, nil, "") assert.ErrorContains(c, err, `invalid port specification: "aa80"`) } func (s *DockerSuite) TestContainerAPICreate(c *testing.T) { - config := containertypes.Config{ + config := container.Config{ Image: "busybox", Cmd: []string{"/bin/sh", "-c", "touch /test && ls /test"}, } @@ -536,7 +536,7 @@ func (s *DockerSuite) TestContainerAPICreate(c *testing.T) { assert.NilError(c, err) defer cli.Close() - container, err := cli.ContainerCreate(context.Background(), &config, &containertypes.HostConfig{}, &networktypes.NetworkingConfig{}, nil, "") + container, err := cli.ContainerCreate(context.Background(), &config, &container.HostConfig{}, &network.NetworkingConfig{}, nil, "") assert.NilError(c, err) out, _ := dockerCmd(c, "start", "-a", container.ID) @@ -549,7 +549,7 @@ func (s *DockerSuite) TestContainerAPICreateEmptyConfig(c *testing.T) { assert.NilError(c, err) defer cli.Close() - _, err = cli.ContainerCreate(context.Background(), &containertypes.Config{}, &containertypes.HostConfig{}, &networktypes.NetworkingConfig{}, nil, "") + _, err = cli.ContainerCreate(context.Background(), &container.Config{}, &container.HostConfig{}, &network.NetworkingConfig{}, nil, "") expected := "No command specified" assert.ErrorContains(c, err, expected) @@ -557,12 +557,12 @@ func (s *DockerSuite) TestContainerAPICreateEmptyConfig(c *testing.T) { func (s *DockerSuite) TestContainerAPICreateMultipleNetworksConfig(c *testing.T) { // Container creation must fail if client specified configurations for more than one network - config := containertypes.Config{ + config := container.Config{ Image: "busybox", } - networkingConfig := networktypes.NetworkingConfig{ - EndpointsConfig: map[string]*networktypes.EndpointSettings{ + networkingConfig := network.NetworkingConfig{ + EndpointsConfig: map[string]*network.EndpointSettings{ "net1": {}, "net2": {}, "net3": {}, @@ -573,7 +573,7 @@ func (s *DockerSuite) TestContainerAPICreateMultipleNetworksConfig(c *testing.T) assert.NilError(c, err) defer cli.Close() - _, err = cli.ContainerCreate(context.Background(), &config, &containertypes.HostConfig{}, &networkingConfig, nil, "") + _, err = cli.ContainerCreate(context.Background(), &config, &container.HostConfig{}, &networkingConfig, nil, "") msg := err.Error() // network name order in error message is not deterministic assert.Assert(c, strings.Contains(msg, "Container cannot be connected to network endpoints")) @@ -595,12 +595,12 @@ func (s *DockerSuite) TestContainerAPICreateOtherNetworkModes(c *testing.T) { UtilCreateNetworkMode(c, "container:web1") } -func UtilCreateNetworkMode(c *testing.T, networkMode containertypes.NetworkMode) { - config := containertypes.Config{ +func UtilCreateNetworkMode(c *testing.T, networkMode container.NetworkMode) { + config := container.Config{ Image: "busybox", } - hostConfig := containertypes.HostConfig{ + hostConfig := container.HostConfig{ NetworkMode: networkMode, } @@ -608,7 +608,7 @@ func UtilCreateNetworkMode(c *testing.T, networkMode containertypes.NetworkMode) assert.NilError(c, err) defer cli.Close() - container, err := cli.ContainerCreate(context.Background(), &config, &hostConfig, &networktypes.NetworkingConfig{}, nil, "") + container, err := cli.ContainerCreate(context.Background(), &config, &hostConfig, &network.NetworkingConfig{}, nil, "") assert.NilError(c, err) containerJSON, err := cli.ContainerInspect(context.Background(), container.ID) @@ -620,12 +620,12 @@ func UtilCreateNetworkMode(c *testing.T, networkMode containertypes.NetworkMode) func (s *DockerSuite) TestContainerAPICreateWithCpuSharesCpuset(c *testing.T) { // TODO Windows to Windows CI. The CpuShares part could be ported. testRequires(c, DaemonIsLinux) - config := containertypes.Config{ + config := container.Config{ Image: "busybox", } - hostConfig := containertypes.HostConfig{ - Resources: containertypes.Resources{ + hostConfig := container.HostConfig{ + Resources: container.Resources{ CPUShares: 512, CpusetCpus: "0", }, @@ -635,7 +635,7 @@ func (s *DockerSuite) TestContainerAPICreateWithCpuSharesCpuset(c *testing.T) { assert.NilError(c, err) defer cli.Close() - container, err := cli.ContainerCreate(context.Background(), &config, &hostConfig, &networktypes.NetworkingConfig{}, nil, "") + container, err := cli.ContainerCreate(context.Background(), &config, &hostConfig, &network.NetworkingConfig{}, nil, "") assert.NilError(c, err) containerJSON, err := cli.ContainerInspect(context.Background(), container.ID) @@ -937,7 +937,7 @@ func (s *DockerSuite) TestContainerAPIRestartNotimeoutParam(c *testing.T) { func (s *DockerSuite) TestContainerAPIStart(c *testing.T) { name := "testing-start" - config := containertypes.Config{ + config := container.Config{ Image: "busybox", Cmd: append([]string{"/bin/sh", "-c"}, sleepCommandForDaemonPlatform()...), OpenStdin: true, @@ -947,7 +947,7 @@ func (s *DockerSuite) TestContainerAPIStart(c *testing.T) { assert.NilError(c, err) defer cli.Close() - _, err = cli.ContainerCreate(context.Background(), &config, &containertypes.HostConfig{}, &networktypes.NetworkingConfig{}, nil, name) + _, err = cli.ContainerCreate(context.Background(), &config, &container.HostConfig{}, &network.NetworkingConfig{}, nil, name) assert.NilError(c, err) err = cli.ContainerStart(context.Background(), name, types.ContainerStartOptions{}) @@ -1261,7 +1261,7 @@ func (s *DockerSuite) TestContainerAPIPostContainerStop(c *testing.T) { // #14170 func (s *DockerSuite) TestPostContainerAPICreateWithStringOrSliceEntrypoint(c *testing.T) { - config := containertypes.Config{ + config := container.Config{ Image: "busybox", Entrypoint: []string{"echo"}, Cmd: []string{"hello", "world"}, @@ -1271,7 +1271,7 @@ func (s *DockerSuite) TestPostContainerAPICreateWithStringOrSliceEntrypoint(c *t assert.NilError(c, err) defer cli.Close() - _, err = cli.ContainerCreate(context.Background(), &config, &containertypes.HostConfig{}, &networktypes.NetworkingConfig{}, nil, "echotest") + _, err = cli.ContainerCreate(context.Background(), &config, &container.HostConfig{}, &network.NetworkingConfig{}, nil, "echotest") assert.NilError(c, err) out, _ := dockerCmd(c, "start", "-a", "echotest") assert.Equal(c, strings.TrimSpace(out), "hello world") @@ -1289,7 +1289,7 @@ func (s *DockerSuite) TestPostContainerAPICreateWithStringOrSliceEntrypoint(c *t // #14170 func (s *DockerSuite) TestPostContainersCreateWithStringOrSliceCmd(c *testing.T) { - config := containertypes.Config{ + config := container.Config{ Image: "busybox", Cmd: []string{"echo", "hello", "world"}, } @@ -1298,7 +1298,7 @@ func (s *DockerSuite) TestPostContainersCreateWithStringOrSliceCmd(c *testing.T) assert.NilError(c, err) defer cli.Close() - _, err = cli.ContainerCreate(context.Background(), &config, &containertypes.HostConfig{}, &networktypes.NetworkingConfig{}, nil, "echotest") + _, err = cli.ContainerCreate(context.Background(), &config, &container.HostConfig{}, &network.NetworkingConfig{}, nil, "echotest") assert.NilError(c, err) out, _ := dockerCmd(c, "start", "-a", "echotest") assert.Equal(c, strings.TrimSpace(out), "hello world") @@ -1329,10 +1329,10 @@ func (s *DockerSuite) TestPostContainersCreateWithStringOrSliceCapAddDrop(c *tes assert.NilError(c, err) assert.Equal(c, res.StatusCode, http.StatusCreated) - config2 := containertypes.Config{ + config2 := container.Config{ Image: "busybox", } - hostConfig := containertypes.HostConfig{ + hostConfig := container.HostConfig{ CapAdd: []string{"net_admin", "SYS_ADMIN"}, CapDrop: []string{"SETGID", "CAP_SETPCAP"}, } @@ -1341,21 +1341,21 @@ func (s *DockerSuite) TestPostContainersCreateWithStringOrSliceCapAddDrop(c *tes assert.NilError(c, err) defer cli.Close() - _, err = cli.ContainerCreate(context.Background(), &config2, &hostConfig, &networktypes.NetworkingConfig{}, nil, "capaddtest1") + _, err = cli.ContainerCreate(context.Background(), &config2, &hostConfig, &network.NetworkingConfig{}, nil, "capaddtest1") assert.NilError(c, err) } // #14915 func (s *DockerSuite) TestContainerAPICreateNoHostConfig118(c *testing.T) { testRequires(c, DaemonIsLinux) // Windows only support 1.25 or later - config := containertypes.Config{ + config := container.Config{ Image: "busybox", } cli, err := client.NewClientWithOpts(client.FromEnv, client.WithVersion("v1.18")) assert.NilError(c, err) - _, err = cli.ContainerCreate(context.Background(), &config, &containertypes.HostConfig{}, &networktypes.NetworkingConfig{}, nil, "") + _, err = cli.ContainerCreate(context.Background(), &config, &container.HostConfig{}, &network.NetworkingConfig{}, nil, "") assert.NilError(c, err) } @@ -1396,27 +1396,27 @@ func (s *DockerSuite) TestPostContainersCreateWithWrongCpusetValues(c *testing.T assert.NilError(c, err) defer cli.Close() - config := containertypes.Config{ + config := container.Config{ Image: "busybox", } - hostConfig1 := containertypes.HostConfig{ - Resources: containertypes.Resources{ + hostConfig1 := container.HostConfig{ + Resources: container.Resources{ CpusetCpus: "1-42,,", }, } name := "wrong-cpuset-cpus" - _, err = cli.ContainerCreate(context.Background(), &config, &hostConfig1, &networktypes.NetworkingConfig{}, nil, name) + _, err = cli.ContainerCreate(context.Background(), &config, &hostConfig1, &network.NetworkingConfig{}, nil, name) expected := "Invalid value 1-42,, for cpuset cpus" assert.ErrorContains(c, err, expected) - hostConfig2 := containertypes.HostConfig{ - Resources: containertypes.Resources{ + hostConfig2 := container.HostConfig{ + Resources: container.Resources{ CpusetMems: "42-3,1--", }, } name = "wrong-cpuset-mems" - _, err = cli.ContainerCreate(context.Background(), &config, &hostConfig2, &networktypes.NetworkingConfig{}, nil, name) + _, err = cli.ContainerCreate(context.Background(), &config, &hostConfig2, &network.NetworkingConfig{}, nil, name) expected = "Invalid value 42-3,1-- for cpuset mems" assert.ErrorContains(c, err, expected) } @@ -1424,10 +1424,10 @@ func (s *DockerSuite) TestPostContainersCreateWithWrongCpusetValues(c *testing.T func (s *DockerSuite) TestPostContainersCreateShmSizeNegative(c *testing.T) { // ShmSize is not supported on Windows testRequires(c, DaemonIsLinux) - config := containertypes.Config{ + config := container.Config{ Image: "busybox", } - hostConfig := containertypes.HostConfig{ + hostConfig := container.HostConfig{ ShmSize: -1, } @@ -1435,7 +1435,7 @@ func (s *DockerSuite) TestPostContainersCreateShmSizeNegative(c *testing.T) { assert.NilError(c, err) defer cli.Close() - _, err = cli.ContainerCreate(context.Background(), &config, &hostConfig, &networktypes.NetworkingConfig{}, nil, "") + _, err = cli.ContainerCreate(context.Background(), &config, &hostConfig, &network.NetworkingConfig{}, nil, "") assert.ErrorContains(c, err, "SHM size can not be less than 0") } @@ -1443,7 +1443,7 @@ func (s *DockerSuite) TestPostContainersCreateShmSizeHostConfigOmitted(c *testin // ShmSize is not supported on Windows testRequires(c, DaemonIsLinux) - config := containertypes.Config{ + config := container.Config{ Image: "busybox", Cmd: []string{"mount"}, } @@ -1452,7 +1452,7 @@ func (s *DockerSuite) TestPostContainersCreateShmSizeHostConfigOmitted(c *testin assert.NilError(c, err) defer cli.Close() - container, err := cli.ContainerCreate(context.Background(), &config, &containertypes.HostConfig{}, &networktypes.NetworkingConfig{}, nil, "") + container, err := cli.ContainerCreate(context.Background(), &config, &container.HostConfig{}, &network.NetworkingConfig{}, nil, "") assert.NilError(c, err) containerJSON, err := cli.ContainerInspect(context.Background(), container.ID) @@ -1470,7 +1470,7 @@ func (s *DockerSuite) TestPostContainersCreateShmSizeHostConfigOmitted(c *testin func (s *DockerSuite) TestPostContainersCreateShmSizeOmitted(c *testing.T) { // ShmSize is not supported on Windows testRequires(c, DaemonIsLinux) - config := containertypes.Config{ + config := container.Config{ Image: "busybox", Cmd: []string{"mount"}, } @@ -1479,7 +1479,7 @@ func (s *DockerSuite) TestPostContainersCreateShmSizeOmitted(c *testing.T) { assert.NilError(c, err) defer cli.Close() - container, err := cli.ContainerCreate(context.Background(), &config, &containertypes.HostConfig{}, &networktypes.NetworkingConfig{}, nil, "") + container, err := cli.ContainerCreate(context.Background(), &config, &container.HostConfig{}, &network.NetworkingConfig{}, nil, "") assert.NilError(c, err) containerJSON, err := cli.ContainerInspect(context.Background(), container.ID) @@ -1497,12 +1497,12 @@ func (s *DockerSuite) TestPostContainersCreateShmSizeOmitted(c *testing.T) { func (s *DockerSuite) TestPostContainersCreateWithShmSize(c *testing.T) { // ShmSize is not supported on Windows testRequires(c, DaemonIsLinux) - config := containertypes.Config{ + config := container.Config{ Image: "busybox", Cmd: []string{"mount"}, } - hostConfig := containertypes.HostConfig{ + hostConfig := container.HostConfig{ ShmSize: 1073741824, } @@ -1510,7 +1510,7 @@ func (s *DockerSuite) TestPostContainersCreateWithShmSize(c *testing.T) { assert.NilError(c, err) defer cli.Close() - container, err := cli.ContainerCreate(context.Background(), &config, &hostConfig, &networktypes.NetworkingConfig{}, nil, "") + container, err := cli.ContainerCreate(context.Background(), &config, &hostConfig, &network.NetworkingConfig{}, nil, "") assert.NilError(c, err) containerJSON, err := cli.ContainerInspect(context.Background(), container.ID) @@ -1528,7 +1528,7 @@ func (s *DockerSuite) TestPostContainersCreateWithShmSize(c *testing.T) { func (s *DockerSuite) TestPostContainersCreateMemorySwappinessHostConfigOmitted(c *testing.T) { // Swappiness is not supported on Windows testRequires(c, DaemonIsLinux) - config := containertypes.Config{ + config := container.Config{ Image: "busybox", } @@ -1536,7 +1536,7 @@ func (s *DockerSuite) TestPostContainersCreateMemorySwappinessHostConfigOmitted( assert.NilError(c, err) defer cli.Close() - container, err := cli.ContainerCreate(context.Background(), &config, &containertypes.HostConfig{}, &networktypes.NetworkingConfig{}, nil, "") + container, err := cli.ContainerCreate(context.Background(), &config, &container.HostConfig{}, &network.NetworkingConfig{}, nil, "") assert.NilError(c, err) containerJSON, err := cli.ContainerInspect(context.Background(), container.ID) @@ -1554,11 +1554,11 @@ func (s *DockerSuite) TestPostContainersCreateWithOomScoreAdjInvalidRange(c *tes // OomScoreAdj is not supported on Windows testRequires(c, DaemonIsLinux) - config := containertypes.Config{ + config := container.Config{ Image: "busybox", } - hostConfig := containertypes.HostConfig{ + hostConfig := container.HostConfig{ OomScoreAdj: 1001, } @@ -1567,17 +1567,17 @@ func (s *DockerSuite) TestPostContainersCreateWithOomScoreAdjInvalidRange(c *tes defer cli.Close() name := "oomscoreadj-over" - _, err = cli.ContainerCreate(context.Background(), &config, &hostConfig, &networktypes.NetworkingConfig{}, nil, name) + _, err = cli.ContainerCreate(context.Background(), &config, &hostConfig, &network.NetworkingConfig{}, nil, name) expected := "Invalid value 1001, range for oom score adj is [-1000, 1000]" assert.ErrorContains(c, err, expected) - hostConfig = containertypes.HostConfig{ + hostConfig = container.HostConfig{ OomScoreAdj: -1001, } name = "oomscoreadj-low" - _, err = cli.ContainerCreate(context.Background(), &config, &hostConfig, &networktypes.NetworkingConfig{}, nil, name) + _, err = cli.ContainerCreate(context.Background(), &config, &hostConfig, &network.NetworkingConfig{}, nil, name) expected = "Invalid value -1001, range for oom score adj is [-1000, 1000]" assert.ErrorContains(c, err, expected) @@ -1599,7 +1599,7 @@ func (s *DockerSuite) TestContainerAPIStatsWithNetworkDisabled(c *testing.T) { name := "testing-network-disabled" - config := containertypes.Config{ + config := container.Config{ Image: "busybox", Cmd: []string{"top"}, NetworkDisabled: true, @@ -1609,7 +1609,7 @@ func (s *DockerSuite) TestContainerAPIStatsWithNetworkDisabled(c *testing.T) { assert.NilError(c, err) defer cli.Close() - _, err = cli.ContainerCreate(context.Background(), &config, &containertypes.HostConfig{}, &networktypes.NetworkingConfig{}, nil, name) + _, err = cli.ContainerCreate(context.Background(), &config, &container.HostConfig{}, &network.NetworkingConfig{}, nil, name) assert.NilError(c, err) err = cli.ContainerStart(context.Background(), name, types.ContainerStartOptions{}) @@ -1644,8 +1644,8 @@ func (s *DockerSuite) TestContainerAPIStatsWithNetworkDisabled(c *testing.T) { func (s *DockerSuite) TestContainersAPICreateMountsValidation(c *testing.T) { type testCase struct { - config containertypes.Config - hostConfig containertypes.HostConfig + config container.Config + hostConfig container.HostConfig msg string } @@ -1655,11 +1655,11 @@ func (s *DockerSuite) TestContainersAPICreateMountsValidation(c *testing.T) { cases := []testCase{ { - config: containertypes.Config{ + config: container.Config{ Image: "busybox", }, - hostConfig: containertypes.HostConfig{ - Mounts: []mounttypes.Mount{{ + hostConfig: container.HostConfig{ + Mounts: []mount.Mount{{ Type: "notreal", Target: destPath, }, @@ -1669,30 +1669,30 @@ func (s *DockerSuite) TestContainersAPICreateMountsValidation(c *testing.T) { msg: "mount type unknown", }, { - config: containertypes.Config{ + config: container.Config{ Image: "busybox", }, - hostConfig: containertypes.HostConfig{ - Mounts: []mounttypes.Mount{{ + hostConfig: container.HostConfig{ + Mounts: []mount.Mount{{ Type: "bind"}}}, msg: "Target must not be empty", }, { - config: containertypes.Config{ + config: container.Config{ Image: "busybox", }, - hostConfig: containertypes.HostConfig{ - Mounts: []mounttypes.Mount{{ + hostConfig: container.HostConfig{ + Mounts: []mount.Mount{{ Type: "bind", Target: destPath}}}, msg: "Source must not be empty", }, { - config: containertypes.Config{ + config: container.Config{ Image: "busybox", }, - hostConfig: containertypes.HostConfig{ - Mounts: []mounttypes.Mount{{ + hostConfig: container.HostConfig{ + Mounts: []mount.Mount{{ Type: "bind", Source: notExistPath, Target: destPath}}}, @@ -1701,36 +1701,36 @@ func (s *DockerSuite) TestContainersAPICreateMountsValidation(c *testing.T) { // msg: "source path does not exist: " + notExistPath, }, { - config: containertypes.Config{ + config: container.Config{ Image: "busybox", }, - hostConfig: containertypes.HostConfig{ - Mounts: []mounttypes.Mount{{ + hostConfig: container.HostConfig{ + Mounts: []mount.Mount{{ Type: "volume"}}}, msg: "Target must not be empty", }, { - config: containertypes.Config{ + config: container.Config{ Image: "busybox", }, - hostConfig: containertypes.HostConfig{ - Mounts: []mounttypes.Mount{{ + hostConfig: container.HostConfig{ + Mounts: []mount.Mount{{ Type: "volume", Source: "hello", Target: destPath}}}, msg: "", }, { - config: containertypes.Config{ + config: container.Config{ Image: "busybox", }, - hostConfig: containertypes.HostConfig{ - Mounts: []mounttypes.Mount{{ + hostConfig: container.HostConfig{ + Mounts: []mount.Mount{{ Type: "volume", Source: "hello2", Target: destPath, - VolumeOptions: &mounttypes.VolumeOptions{ - DriverConfig: &mounttypes.Driver{ + VolumeOptions: &mount.VolumeOptions{ + DriverConfig: &mount.Driver{ Name: "local"}}}}}, msg: "", }, @@ -1742,26 +1742,26 @@ func (s *DockerSuite) TestContainersAPICreateMountsValidation(c *testing.T) { defer os.RemoveAll(tmpDir) cases = append(cases, []testCase{ { - config: containertypes.Config{ + config: container.Config{ Image: "busybox", }, - hostConfig: containertypes.HostConfig{ - Mounts: []mounttypes.Mount{{ + hostConfig: container.HostConfig{ + Mounts: []mount.Mount{{ Type: "bind", Source: tmpDir, Target: destPath}}}, msg: "", }, { - config: containertypes.Config{ + config: container.Config{ Image: "busybox", }, - hostConfig: containertypes.HostConfig{ - Mounts: []mounttypes.Mount{{ + hostConfig: container.HostConfig{ + Mounts: []mount.Mount{{ Type: "bind", Source: tmpDir, Target: destPath, - VolumeOptions: &mounttypes.VolumeOptions{}}}}, + VolumeOptions: &mount.VolumeOptions{}}}}, msg: "VolumeOptions must not be specified", }, }...) @@ -1770,17 +1770,17 @@ func (s *DockerSuite) TestContainersAPICreateMountsValidation(c *testing.T) { if DaemonIsWindows() { cases = append(cases, []testCase{ { - config: containertypes.Config{ + config: container.Config{ Image: "busybox", }, - hostConfig: containertypes.HostConfig{ - Mounts: []mounttypes.Mount{ + hostConfig: container.HostConfig{ + Mounts: []mount.Mount{ { Type: "volume", Source: "not-supported-on-windows", Target: destPath, - VolumeOptions: &mounttypes.VolumeOptions{ - DriverConfig: &mounttypes.Driver{ + VolumeOptions: &mount.VolumeOptions{ + DriverConfig: &mount.Driver{ Name: "local", Options: map[string]string{"type": "tmpfs"}, }, @@ -1796,17 +1796,17 @@ func (s *DockerSuite) TestContainersAPICreateMountsValidation(c *testing.T) { if DaemonIsLinux() { cases = append(cases, []testCase{ { - config: containertypes.Config{ + config: container.Config{ Image: "busybox", }, - hostConfig: containertypes.HostConfig{ - Mounts: []mounttypes.Mount{ + hostConfig: container.HostConfig{ + Mounts: []mount.Mount{ { Type: "volume", Source: "missing-device-opt", Target: destPath, - VolumeOptions: &mounttypes.VolumeOptions{ - DriverConfig: &mounttypes.Driver{ + VolumeOptions: &mount.VolumeOptions{ + DriverConfig: &mount.Driver{ Name: "local", Options: map[string]string{"foobar": "foobaz"}, }, @@ -1817,17 +1817,17 @@ func (s *DockerSuite) TestContainersAPICreateMountsValidation(c *testing.T) { msg: `invalid option: "foobar"`, }, { - config: containertypes.Config{ + config: container.Config{ Image: "busybox", }, - hostConfig: containertypes.HostConfig{ - Mounts: []mounttypes.Mount{ + hostConfig: container.HostConfig{ + Mounts: []mount.Mount{ { Type: "volume", Source: "missing-device-opt", Target: destPath, - VolumeOptions: &mounttypes.VolumeOptions{ - DriverConfig: &mounttypes.Driver{ + VolumeOptions: &mount.VolumeOptions{ + DriverConfig: &mount.Driver{ Name: "local", Options: map[string]string{"type": "tmpfs"}, }, @@ -1838,17 +1838,17 @@ func (s *DockerSuite) TestContainersAPICreateMountsValidation(c *testing.T) { msg: `missing required option: "device"`, }, { - config: containertypes.Config{ + config: container.Config{ Image: "busybox", }, - hostConfig: containertypes.HostConfig{ - Mounts: []mounttypes.Mount{ + hostConfig: container.HostConfig{ + Mounts: []mount.Mount{ { Type: "volume", Source: "missing-type-opt", Target: destPath, - VolumeOptions: &mounttypes.VolumeOptions{ - DriverConfig: &mounttypes.Driver{ + VolumeOptions: &mount.VolumeOptions{ + DriverConfig: &mount.Driver{ Name: "local", Options: map[string]string{"device": "tmpfs"}, }, @@ -1859,17 +1859,17 @@ func (s *DockerSuite) TestContainersAPICreateMountsValidation(c *testing.T) { msg: `missing required option: "type"`, }, { - config: containertypes.Config{ + config: container.Config{ Image: "busybox", }, - hostConfig: containertypes.HostConfig{ - Mounts: []mounttypes.Mount{ + hostConfig: container.HostConfig{ + Mounts: []mount.Mount{ { Type: "volume", Source: "hello4", Target: destPath, - VolumeOptions: &mounttypes.VolumeOptions{ - DriverConfig: &mounttypes.Driver{ + VolumeOptions: &mount.VolumeOptions{ + DriverConfig: &mount.Driver{ Name: "local", Options: map[string]string{"o": "size=1", "type": "tmpfs", "device": "tmpfs"}, }, @@ -1880,35 +1880,35 @@ func (s *DockerSuite) TestContainersAPICreateMountsValidation(c *testing.T) { msg: "", }, { - config: containertypes.Config{ + config: container.Config{ Image: "busybox", }, - hostConfig: containertypes.HostConfig{ - Mounts: []mounttypes.Mount{{ + hostConfig: container.HostConfig{ + Mounts: []mount.Mount{{ Type: "tmpfs", Target: destPath}}}, msg: "", }, { - config: containertypes.Config{ + config: container.Config{ Image: "busybox", }, - hostConfig: containertypes.HostConfig{ - Mounts: []mounttypes.Mount{{ + hostConfig: container.HostConfig{ + Mounts: []mount.Mount{{ Type: "tmpfs", Target: destPath, - TmpfsOptions: &mounttypes.TmpfsOptions{ + TmpfsOptions: &mount.TmpfsOptions{ SizeBytes: 4096 * 1024, Mode: 0700, }}}}, msg: "", }, { - config: containertypes.Config{ + config: container.Config{ Image: "busybox", }, - hostConfig: containertypes.HostConfig{ - Mounts: []mounttypes.Mount{{ + hostConfig: container.HostConfig{ + Mounts: []mount.Mount{{ Type: "tmpfs", Source: "/shouldnotbespecified", Target: destPath}}}, @@ -1925,7 +1925,7 @@ func (s *DockerSuite) TestContainersAPICreateMountsValidation(c *testing.T) { for i, x := range cases { x := x c.Run(fmt.Sprintf("case %d", i), func(c *testing.T) { - _, err = apiClient.ContainerCreate(context.Background(), &x.config, &x.hostConfig, &networktypes.NetworkingConfig{}, nil, "") + _, err = apiClient.ContainerCreate(context.Background(), &x.config, &x.hostConfig, &network.NetworkingConfig{}, nil, "") if len(x.msg) > 0 { assert.ErrorContains(c, err, x.msg, "%v", cases[i].config) } else { @@ -1945,12 +1945,12 @@ func (s *DockerSuite) TestContainerAPICreateMountsBindRead(c *testing.T) { defer os.RemoveAll(tmpDir) err = os.WriteFile(filepath.Join(tmpDir, "bar"), []byte("hello"), 0666) assert.NilError(c, err) - config := containertypes.Config{ + config := container.Config{ Image: "busybox", Cmd: []string{"/bin/sh", "-c", "cat /foo/bar"}, } - hostConfig := containertypes.HostConfig{ - Mounts: []mounttypes.Mount{ + hostConfig := container.HostConfig{ + Mounts: []mount.Mount{ {Type: "bind", Source: tmpDir, Target: destPath}, }, } @@ -1958,7 +1958,7 @@ func (s *DockerSuite) TestContainerAPICreateMountsBindRead(c *testing.T) { assert.NilError(c, err) defer cli.Close() - _, err = cli.ContainerCreate(context.Background(), &config, &hostConfig, &networktypes.NetworkingConfig{}, nil, "test") + _, err = cli.ContainerCreate(context.Background(), &config, &hostConfig, &network.NetworkingConfig{}, nil, "test") assert.NilError(c, err) out, _ := dockerCmd(c, "start", "-a", "test") @@ -1985,7 +1985,7 @@ func (s *DockerSuite) TestContainersAPICreateMountsCreate(c *testing.T) { } type testCase struct { - spec mounttypes.Mount + spec mount.Mount expected types.MountPoint } @@ -2003,23 +2003,23 @@ func (s *DockerSuite) TestContainersAPICreateMountsCreate(c *testing.T) { // use literal strings here for `Type` instead of the defined constants in the volume package to keep this honest // Validation of the actual `Mount` struct is done in another test is not needed here { - spec: mounttypes.Mount{Type: "volume", Target: destPath}, + spec: mount.Mount{Type: "volume", Target: destPath}, expected: types.MountPoint{Driver: volume.DefaultDriverName, Type: "volume", RW: true, Destination: destPath, Mode: selinuxSharedLabel}, }, { - spec: mounttypes.Mount{Type: "volume", Target: destPath + slash}, + spec: mount.Mount{Type: "volume", Target: destPath + slash}, expected: types.MountPoint{Driver: volume.DefaultDriverName, Type: "volume", RW: true, Destination: destPath, Mode: selinuxSharedLabel}, }, { - spec: mounttypes.Mount{Type: "volume", Target: destPath, Source: "test1"}, + spec: mount.Mount{Type: "volume", Target: destPath, Source: "test1"}, expected: types.MountPoint{Type: "volume", Name: "test1", RW: true, Destination: destPath, Mode: selinuxSharedLabel}, }, { - spec: mounttypes.Mount{Type: "volume", Target: destPath, ReadOnly: true, Source: "test2"}, + spec: mount.Mount{Type: "volume", Target: destPath, ReadOnly: true, Source: "test2"}, expected: types.MountPoint{Type: "volume", Name: "test2", RW: false, Destination: destPath, Mode: selinuxSharedLabel}, }, { - spec: mounttypes.Mount{Type: "volume", Target: destPath, Source: "test3", VolumeOptions: &mounttypes.VolumeOptions{DriverConfig: &mounttypes.Driver{Name: volume.DefaultDriverName}}}, + spec: mount.Mount{Type: "volume", Target: destPath, Source: "test3", VolumeOptions: &mount.VolumeOptions{DriverConfig: &mount.Driver{Name: volume.DefaultDriverName}}}, expected: types.MountPoint{Driver: volume.DefaultDriverName, Type: "volume", Name: "test3", RW: true, Destination: destPath, Mode: selinuxSharedLabel}, }, } @@ -2031,7 +2031,7 @@ func (s *DockerSuite) TestContainersAPICreateMountsCreate(c *testing.T) { defer os.RemoveAll(tmpDir1) cases = append(cases, []testCase{ { - spec: mounttypes.Mount{ + spec: mount.Mount{ Type: "bind", Source: tmpDir1, Target: destPath, @@ -2044,7 +2044,7 @@ func (s *DockerSuite) TestContainersAPICreateMountsCreate(c *testing.T) { }, }, { - spec: mounttypes.Mount{Type: "bind", Source: tmpDir1, Target: destPath, ReadOnly: true}, + spec: mount.Mount{Type: "bind", Source: tmpDir1, Target: destPath, ReadOnly: true}, expected: types.MountPoint{Type: "bind", RW: false, Destination: destPath, Source: tmpDir1}, }, }...) @@ -2059,15 +2059,15 @@ func (s *DockerSuite) TestContainersAPICreateMountsCreate(c *testing.T) { cases = append(cases, []testCase{ { - spec: mounttypes.Mount{Type: "bind", Source: tmpDir3, Target: destPath}, + spec: mount.Mount{Type: "bind", Source: tmpDir3, Target: destPath}, expected: types.MountPoint{Type: "bind", RW: true, Destination: destPath, Source: tmpDir3}, }, { - spec: mounttypes.Mount{Type: "bind", Source: tmpDir3, Target: destPath, ReadOnly: true}, + spec: mount.Mount{Type: "bind", Source: tmpDir3, Target: destPath, ReadOnly: true}, expected: types.MountPoint{Type: "bind", RW: false, Destination: destPath, Source: tmpDir3}, }, { - spec: mounttypes.Mount{Type: "bind", Source: tmpDir3, Target: destPath, ReadOnly: true, BindOptions: &mounttypes.BindOptions{Propagation: "shared"}}, + spec: mount.Mount{Type: "bind", Source: tmpDir3, Target: destPath, ReadOnly: true, BindOptions: &mount.BindOptions{Propagation: "shared"}}, expected: types.MountPoint{Type: "bind", RW: false, Destination: destPath, Source: tmpDir3, Propagation: "shared"}, }, }...) @@ -2077,19 +2077,19 @@ func (s *DockerSuite) TestContainersAPICreateMountsCreate(c *testing.T) { if testEnv.OSType != "windows" { // Windows does not support volume populate cases = append(cases, []testCase{ { - spec: mounttypes.Mount{Type: "volume", Target: destPath, VolumeOptions: &mounttypes.VolumeOptions{NoCopy: true}}, + spec: mount.Mount{Type: "volume", Target: destPath, VolumeOptions: &mount.VolumeOptions{NoCopy: true}}, expected: types.MountPoint{Driver: volume.DefaultDriverName, Type: "volume", RW: true, Destination: destPath, Mode: selinuxSharedLabel}, }, { - spec: mounttypes.Mount{Type: "volume", Target: destPath + slash, VolumeOptions: &mounttypes.VolumeOptions{NoCopy: true}}, + spec: mount.Mount{Type: "volume", Target: destPath + slash, VolumeOptions: &mount.VolumeOptions{NoCopy: true}}, expected: types.MountPoint{Driver: volume.DefaultDriverName, Type: "volume", RW: true, Destination: destPath, Mode: selinuxSharedLabel}, }, { - spec: mounttypes.Mount{Type: "volume", Target: destPath, Source: "test4", VolumeOptions: &mounttypes.VolumeOptions{NoCopy: true}}, + spec: mount.Mount{Type: "volume", Target: destPath, Source: "test4", VolumeOptions: &mount.VolumeOptions{NoCopy: true}}, expected: types.MountPoint{Type: "volume", Name: "test4", RW: true, Destination: destPath, Mode: selinuxSharedLabel}, }, { - spec: mounttypes.Mount{Type: "volume", Target: destPath, Source: "test5", ReadOnly: true, VolumeOptions: &mounttypes.VolumeOptions{NoCopy: true}}, + spec: mount.Mount{Type: "volume", Target: destPath, Source: "test5", ReadOnly: true, VolumeOptions: &mount.VolumeOptions{NoCopy: true}}, expected: types.MountPoint{Type: "volume", Name: "test5", RW: false, Destination: destPath, Mode: selinuxSharedLabel}, }, }...) @@ -2102,9 +2102,9 @@ func (s *DockerSuite) TestContainersAPICreateMountsCreate(c *testing.T) { c.Run(fmt.Sprintf("%d config: %v", i, x.spec), func(c *testing.T) { container, err := apiclient.ContainerCreate( ctx, - &containertypes.Config{Image: testImg}, - &containertypes.HostConfig{Mounts: []mounttypes.Mount{x.spec}}, - &networktypes.NetworkingConfig{}, + &container.Config{Image: testImg}, + &container.HostConfig{Mounts: []mount.Mount{x.spec}}, + &network.NetworkingConfig{}, nil, "") assert.NilError(c, err) @@ -2178,22 +2178,22 @@ func containerExit(apiclient client.APIClient, name string) func(poll.LogT) poll func (s *DockerSuite) TestContainersAPICreateMountsTmpfs(c *testing.T) { testRequires(c, DaemonIsLinux) type testCase struct { - cfg mounttypes.Mount + cfg mount.Mount expectedOptions []string } target := "/foo" cases := []testCase{ { - cfg: mounttypes.Mount{ + cfg: mount.Mount{ Type: "tmpfs", Target: target}, expectedOptions: []string{"rw", "nosuid", "nodev", "noexec", "relatime"}, }, { - cfg: mounttypes.Mount{ + cfg: mount.Mount{ Type: "tmpfs", Target: target, - TmpfsOptions: &mounttypes.TmpfsOptions{ + TmpfsOptions: &mount.TmpfsOptions{ SizeBytes: 4096 * 1024, Mode: 0700}}, expectedOptions: []string{"rw", "nosuid", "nodev", "noexec", "relatime", "size=4096k", "mode=700"}, }, @@ -2203,17 +2203,17 @@ func (s *DockerSuite) TestContainersAPICreateMountsTmpfs(c *testing.T) { assert.NilError(c, err) defer cli.Close() - config := containertypes.Config{ + config := container.Config{ Image: "busybox", Cmd: []string{"/bin/sh", "-c", fmt.Sprintf("mount | grep 'tmpfs on %s'", target)}, } for i, x := range cases { cName := fmt.Sprintf("test-tmpfs-%d", i) - hostConfig := containertypes.HostConfig{ - Mounts: []mounttypes.Mount{x.cfg}, + hostConfig := container.HostConfig{ + Mounts: []mount.Mount{x.cfg}, } - _, err = cli.ContainerCreate(context.Background(), &config, &hostConfig, &networktypes.NetworkingConfig{}, nil, cName) + _, err = cli.ContainerCreate(context.Background(), &config, &hostConfig, &network.NetworkingConfig{}, nil, cName) assert.NilError(c, err) out, _ := dockerCmd(c, "start", "-a", cName) for _, option := range x.expectedOptions { From e27c0438284ae77386045f6cb96cb73ce91ab491 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 5 Mar 2022 19:57:43 +0100 Subject: [PATCH 7/8] api: move types.Volume to volume.Volume Signed-off-by: Sebastiaan van Stijn (cherry picked from commit f19ef20a4414a6f63da8fb2493e6010359652ad1) Signed-off-by: Bjorn Neergaard --- api/types/deprecated.go | 14 ++++++++++++++ api/types/{ => volume}/volume.go | 2 +- hack/generate-swagger-api.sh | 10 +++++++--- 3 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 api/types/deprecated.go rename api/types/{ => volume}/volume.go (99%) diff --git a/api/types/deprecated.go b/api/types/deprecated.go new file mode 100644 index 0000000000000..7666a7173a2e4 --- /dev/null +++ b/api/types/deprecated.go @@ -0,0 +1,14 @@ +package types // import "github.com/docker/docker/api/types" + +import "github.com/docker/docker/api/types/volume" + +// Volume volume +// +// Deprecated: use github.com/docker/docker/api/types/volume.Volume +type Volume = volume.Volume + +// VolumeUsageData Usage details about the volume. This information is used by the +// `GET /system/df` endpoint, and omitted in other endpoints. +// +// Deprecated: use github.com/docker/docker/api/types/volume.VolumeUsageData +type VolumeUsageData = volume.VolumeUsageData diff --git a/api/types/volume.go b/api/types/volume/volume.go similarity index 99% rename from api/types/volume.go rename to api/types/volume/volume.go index c69b08448df4c..047b54c598403 100644 --- a/api/types/volume.go +++ b/api/types/volume/volume.go @@ -1,4 +1,4 @@ -package types +package volume // This file was generated by the swagger tool. // Editing this file might prove futile when you re-run the swagger generate command diff --git a/hack/generate-swagger-api.sh b/hack/generate-swagger-api.sh index e300212e359c5..d9be64c264724 100755 --- a/hack/generate-swagger-api.sh +++ b/hack/generate-swagger-api.sh @@ -8,10 +8,13 @@ swagger generate model -f api/swagger.yaml \ -n IdResponse \ -n ImageDeleteResponseItem \ -n ImageSummary \ - -n Plugin -n PluginDevice -n PluginMount -n PluginEnv -n PluginInterfaceType \ + -n Plugin \ + -n PluginDevice \ + -n PluginMount \ + -n PluginEnv \ + -n PluginInterfaceType \ -n Port \ - -n ServiceUpdateResponse \ - -n Volume + -n ServiceUpdateResponse swagger generate model -f api/swagger.yaml \ -t api -m types/container --skip-validator -C api/swagger-gen.yaml \ @@ -20,6 +23,7 @@ swagger generate model -f api/swagger.yaml \ swagger generate model -f api/swagger.yaml \ -t api -m types/volume --skip-validator -C api/swagger-gen.yaml \ + -n Volume \ -n VolumeCreateOptions swagger generate operation -f api/swagger.yaml \ From 9ddd54fdb76abc469fabe6955fa0605b88c6dc47 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 18 Mar 2022 16:33:43 +0100 Subject: [PATCH 8/8] api/types: replace uses of deprecated types.Volume with volume.Volume Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 176f66df9ca5cdc9466661428f0a3ac33cd1ab1b) Resolved conflicts: client/volume_inspect.go daemon/disk_usage.go integration/system/disk_usage_test.go volume/service/service.go Co-authored-by: Bjorn Neergaard Signed-off-by: Bjorn Neergaard --- api/server/router/volume/backend.go | 7 +++--- api/types/types.go | 3 ++- client/interface.go | 6 ++--- client/volume_create.go | 13 +++++------ client/volume_create_test.go | 21 +++++++++--------- client/volume_inspect.go | 22 +++++++++---------- client/volume_inspect_test.go | 4 ++-- client/volume_list_test.go | 7 +++--- daemon/cluster/executor/backend.go | 3 ++- daemon/disk_usage.go | 1 + daemon/volumes.go | 10 ++++----- .../docker_cli_external_volume_driver_test.go | 3 ++- integration/volume/volume_test.go | 8 +++---- volume/service/convert.go | 12 +++++----- volume/service/service.go | 13 ++++++----- 15 files changed, 68 insertions(+), 65 deletions(-) diff --git a/api/server/router/volume/backend.go b/api/server/router/volume/backend.go index 31558c1789e07..a2f445ebf48a5 100644 --- a/api/server/router/volume/backend.go +++ b/api/server/router/volume/backend.go @@ -7,14 +7,15 @@ import ( // TODO return types need to be refactored into pkg "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" + "github.com/docker/docker/api/types/volume" ) // Backend is the methods that need to be implemented to provide // volume specific functionality type Backend interface { - List(ctx context.Context, filter filters.Args) ([]*types.Volume, []string, error) - Get(ctx context.Context, name string, opts ...opts.GetOption) (*types.Volume, error) - Create(ctx context.Context, name, driverName string, opts ...opts.CreateOption) (*types.Volume, error) + List(ctx context.Context, filter filters.Args) ([]*volume.Volume, []string, error) + Get(ctx context.Context, name string, opts ...opts.GetOption) (*volume.Volume, error) + Create(ctx context.Context, name, driverName string, opts ...opts.CreateOption) (*volume.Volume, error) Remove(ctx context.Context, name string, opts ...opts.RemoveOption) error Prune(ctx context.Context, pruneFilters filters.Args) (*types.VolumesPruneReport, error) } diff --git a/api/types/types.go b/api/types/types.go index e3a159912e22c..66d631d11de91 100644 --- a/api/types/types.go +++ b/api/types/types.go @@ -14,6 +14,7 @@ import ( "github.com/docker/docker/api/types/network" "github.com/docker/docker/api/types/registry" "github.com/docker/docker/api/types/swarm" + "github.com/docker/docker/api/types/volume" "github.com/docker/go-connections/nat" ) @@ -536,7 +537,7 @@ type DiskUsage struct { LayersSize int64 Images []*ImageSummary Containers []*Container - Volumes []*Volume + Volumes []*volume.Volume BuildCache []*BuildCache BuilderSize int64 // deprecated } diff --git a/client/interface.go b/client/interface.go index 09bc111116adb..3e69f6fbf50bd 100644 --- a/client/interface.go +++ b/client/interface.go @@ -174,9 +174,9 @@ type SystemAPIClient interface { // VolumeAPIClient defines API client methods for the volumes type VolumeAPIClient interface { - VolumeCreate(ctx context.Context, options volume.VolumeCreateBody) (types.Volume, error) - VolumeInspect(ctx context.Context, volumeID string) (types.Volume, error) - VolumeInspectWithRaw(ctx context.Context, volumeID string) (types.Volume, []byte, error) + VolumeCreate(ctx context.Context, options volume.VolumeCreateBody) (volume.Volume, error) + VolumeInspect(ctx context.Context, volumeID string) (volume.Volume, error) + VolumeInspectWithRaw(ctx context.Context, volumeID string) (volume.Volume, []byte, error) VolumeList(ctx context.Context, filter filters.Args) (volume.VolumeListOKBody, error) VolumeRemove(ctx context.Context, volumeID string, force bool) error VolumesPrune(ctx context.Context, pruneFilter filters.Args) (types.VolumesPruneReport, error) diff --git a/client/volume_create.go b/client/volume_create.go index 92761b3c639ea..49e9db14411d8 100644 --- a/client/volume_create.go +++ b/client/volume_create.go @@ -4,18 +4,17 @@ import ( "context" "encoding/json" - "github.com/docker/docker/api/types" - volumetypes "github.com/docker/docker/api/types/volume" + "github.com/docker/docker/api/types/volume" ) // VolumeCreate creates a volume in the docker host. -func (cli *Client) VolumeCreate(ctx context.Context, options volumetypes.VolumeCreateBody) (types.Volume, error) { - var volume types.Volume +func (cli *Client) VolumeCreate(ctx context.Context, options volume.VolumeCreateBody) (volume.Volume, error) { + var vol volume.Volume resp, err := cli.post(ctx, "/volumes/create", nil, options, nil) defer ensureReaderClosed(resp) if err != nil { - return volume, err + return vol, err } - err = json.NewDecoder(resp.body).Decode(&volume) - return volume, err + err = json.NewDecoder(resp.body).Decode(&vol) + return vol, err } diff --git a/client/volume_create_test.go b/client/volume_create_test.go index 9f8624a2923d5..3eb52279ccf49 100644 --- a/client/volume_create_test.go +++ b/client/volume_create_test.go @@ -10,8 +10,7 @@ import ( "strings" "testing" - "github.com/docker/docker/api/types" - volumetypes "github.com/docker/docker/api/types/volume" + "github.com/docker/docker/api/types/volume" "github.com/docker/docker/errdefs" ) @@ -20,7 +19,7 @@ func TestVolumeCreateError(t *testing.T) { client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), } - _, err := client.VolumeCreate(context.Background(), volumetypes.VolumeCreateBody{}) + _, err := client.VolumeCreate(context.Background(), volume.VolumeCreateBody{}) if !errdefs.IsSystem(err) { t.Fatalf("expected a Server Error, got %[1]T: %[1]v", err) } @@ -39,7 +38,7 @@ func TestVolumeCreate(t *testing.T) { return nil, fmt.Errorf("expected POST method, got %s", req.Method) } - content, err := json.Marshal(types.Volume{ + content, err := json.Marshal(volume.Volume{ Name: "volume", Driver: "local", Mountpoint: "mountpoint", @@ -54,7 +53,7 @@ func TestVolumeCreate(t *testing.T) { }), } - volume, err := client.VolumeCreate(context.Background(), volumetypes.VolumeCreateBody{ + vol, err := client.VolumeCreate(context.Background(), volume.VolumeCreateBody{ Name: "myvolume", Driver: "mydriver", DriverOpts: map[string]string{ @@ -64,13 +63,13 @@ func TestVolumeCreate(t *testing.T) { if err != nil { t.Fatal(err) } - if volume.Name != "volume" { - t.Fatalf("expected volume.Name to be 'volume', got %s", volume.Name) + if vol.Name != "volume" { + t.Fatalf("expected volume.Name to be 'volume', got %s", vol.Name) } - if volume.Driver != "local" { - t.Fatalf("expected volume.Driver to be 'local', got %s", volume.Driver) + if vol.Driver != "local" { + t.Fatalf("expected volume.Driver to be 'local', got %s", vol.Driver) } - if volume.Mountpoint != "mountpoint" { - t.Fatalf("expected volume.Mountpoint to be 'mountpoint', got %s", volume.Mountpoint) + if vol.Mountpoint != "mountpoint" { + t.Fatalf("expected volume.Mountpoint to be 'mountpoint', got %s", vol.Mountpoint) } } diff --git a/client/volume_inspect.go b/client/volume_inspect.go index 5c5b3f905c54c..6a398ab96d5cd 100644 --- a/client/volume_inspect.go +++ b/client/volume_inspect.go @@ -6,33 +6,33 @@ import ( "encoding/json" "io" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/volume" ) // VolumeInspect returns the information about a specific volume in the docker host. -func (cli *Client) VolumeInspect(ctx context.Context, volumeID string) (types.Volume, error) { - volume, _, err := cli.VolumeInspectWithRaw(ctx, volumeID) - return volume, err +func (cli *Client) VolumeInspect(ctx context.Context, volumeID string) (volume.Volume, error) { + vol, _, err := cli.VolumeInspectWithRaw(ctx, volumeID) + return vol, err } // VolumeInspectWithRaw returns the information about a specific volume in the docker host and its raw representation -func (cli *Client) VolumeInspectWithRaw(ctx context.Context, volumeID string) (types.Volume, []byte, error) { +func (cli *Client) VolumeInspectWithRaw(ctx context.Context, volumeID string) (volume.Volume, []byte, error) { if volumeID == "" { - return types.Volume{}, nil, objectNotFoundError{object: "volume", id: volumeID} + return volume.Volume{}, nil, objectNotFoundError{object: "volume", id: volumeID} } - var volume types.Volume + var vol volume.Volume resp, err := cli.get(ctx, "/volumes/"+volumeID, nil, nil) defer ensureReaderClosed(resp) if err != nil { - return volume, nil, wrapResponseError(err, resp, "volume", volumeID) + return vol, nil, wrapResponseError(err, resp, "volume", volumeID) } body, err := io.ReadAll(resp.body) if err != nil { - return volume, nil, err + return vol, nil, err } rdr := bytes.NewReader(body) - err = json.NewDecoder(rdr).Decode(&volume) - return volume, body, err + err = json.NewDecoder(rdr).Decode(&vol) + return vol, body, err } diff --git a/client/volume_inspect_test.go b/client/volume_inspect_test.go index 1aa2a54448016..70b82729b87b1 100644 --- a/client/volume_inspect_test.go +++ b/client/volume_inspect_test.go @@ -10,7 +10,7 @@ import ( "strings" "testing" - "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/volume" "github.com/docker/docker/errdefs" "github.com/pkg/errors" "gotest.tools/v3/assert" @@ -51,7 +51,7 @@ func TestVolumeInspectWithEmptyID(t *testing.T) { func TestVolumeInspect(t *testing.T) { expectedURL := "/volumes/volume_id" - expected := types.Volume{ + expected := volume.Volume{ Name: "name", Driver: "driver", Mountpoint: "mountpoint", diff --git a/client/volume_list_test.go b/client/volume_list_test.go index d26bb51405e36..0d54f4a597462 100644 --- a/client/volume_list_test.go +++ b/client/volume_list_test.go @@ -10,9 +10,8 @@ import ( "strings" "testing" - "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" - volumetypes "github.com/docker/docker/api/types/volume" + "github.com/docker/docker/api/types/volume" "github.com/docker/docker/errdefs" ) @@ -70,8 +69,8 @@ func TestVolumeList(t *testing.T) { if actualFilters != listCase.expectedFilters { return nil, fmt.Errorf("filters not set in URL query properly. Expected '%s', got %s", listCase.expectedFilters, actualFilters) } - content, err := json.Marshal(volumetypes.VolumeListOKBody{ - Volumes: []*types.Volume{ + content, err := json.Marshal(volume.VolumeListOKBody{ + Volumes: []*volume.Volume{ { Name: "volume", Driver: "local", diff --git a/daemon/cluster/executor/backend.go b/daemon/cluster/executor/backend.go index 16d1363e35c2b..f83875dd59b25 100644 --- a/daemon/cluster/executor/backend.go +++ b/daemon/cluster/executor/backend.go @@ -14,6 +14,7 @@ import ( "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/network" swarmtypes "github.com/docker/docker/api/types/swarm" + "github.com/docker/docker/api/types/volume" containerpkg "github.com/docker/docker/container" clustertypes "github.com/docker/docker/daemon/cluster/provider" networkSettings "github.com/docker/docker/daemon/network" @@ -66,7 +67,7 @@ type Backend interface { // VolumeBackend is used by an executor to perform volume operations type VolumeBackend interface { - Create(ctx context.Context, name, driverName string, opts ...volumeopts.CreateOption) (*types.Volume, error) + Create(ctx context.Context, name, driverName string, opts ...volumeopts.CreateOption) (*volume.Volume, error) } // ImageBackend is used by an executor to perform image operations diff --git a/daemon/disk_usage.go b/daemon/disk_usage.go index 5bec60d174142..8c7e13463f7f7 100644 --- a/daemon/disk_usage.go +++ b/daemon/disk_usage.go @@ -7,6 +7,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" + "github.com/docker/docker/api/types/volume" ) // SystemDiskUsage returns information about the daemon data disk usage diff --git a/daemon/volumes.go b/daemon/volumes.go index c39684383144a..b8e9d22c4db33 100644 --- a/daemon/volumes.go +++ b/daemon/volumes.go @@ -8,10 +8,10 @@ import ( "strings" "time" - "github.com/docker/docker/api/types" containertypes "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/mount" mounttypes "github.com/docker/docker/api/types/mount" + volumetypes "github.com/docker/docker/api/types/volume" "github.com/docker/docker/container" "github.com/docker/docker/errdefs" "github.com/docker/docker/volume" @@ -186,7 +186,7 @@ func (daemon *Daemon) registerMountPoints(container *container.Container, hostCo } if mp.Type == mounttypes.TypeVolume { - var v *types.Volume + var v *volumetypes.Volume if cfg.VolumeOptions != nil { var driverOpts map[string]string if cfg.VolumeOptions.DriverConfig != nil { @@ -385,12 +385,12 @@ func (daemon *Daemon) VolumesService() *service.VolumesService { } type volumeMounter interface { - Mount(ctx context.Context, v *types.Volume, ref string) (string, error) - Unmount(ctx context.Context, v *types.Volume, ref string) error + Mount(ctx context.Context, v *volumetypes.Volume, ref string) (string, error) + Unmount(ctx context.Context, v *volumetypes.Volume, ref string) error } type volumeWrapper struct { - v *types.Volume + v *volumetypes.Volume s volumeMounter } diff --git a/integration-cli/docker_cli_external_volume_driver_test.go b/integration-cli/docker_cli_external_volume_driver_test.go index 8106cd1529a13..46a5555e57bf3 100644 --- a/integration-cli/docker_cli_external_volume_driver_test.go +++ b/integration-cli/docker_cli_external_volume_driver_test.go @@ -14,6 +14,7 @@ import ( "time" "github.com/docker/docker/api/types" + volumetypes "github.com/docker/docker/api/types/volume" "github.com/docker/docker/integration-cli/daemon" "github.com/docker/docker/pkg/stringid" testdaemon "github.com/docker/docker/testutil/daemon" @@ -564,7 +565,7 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverOutOfBandDelete(c *t out, err = s.d.Cmd("volume", "inspect", "test") assert.NilError(c, err, out) - var vs []types.Volume + var vs []volumetypes.Volume err = json.Unmarshal([]byte(out), &vs) assert.NilError(c, err) assert.Equal(c, len(vs), 1) diff --git a/integration/volume/volume_test.go b/integration/volume/volume_test.go index 65f457d6d84ce..67e5ea6491cd7 100644 --- a/integration/volume/volume_test.go +++ b/integration/volume/volume_test.go @@ -10,7 +10,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" - volumetypes "github.com/docker/docker/api/types/volume" + "github.com/docker/docker/api/types/volume" "github.com/docker/docker/integration/internal/container" "github.com/docker/docker/testutil/request" "github.com/google/go-cmp/cmp/cmpopts" @@ -28,12 +28,12 @@ func TestVolumesCreateAndList(t *testing.T) { if testEnv.OSType == "windows" { name = strings.ToLower(name) } - vol, err := client.VolumeCreate(ctx, volumetypes.VolumeCreateBody{ + vol, err := client.VolumeCreate(ctx, volume.VolumeCreateBody{ Name: name, }) assert.NilError(t, err) - expected := types.Volume{ + expected := volume.Volume{ // Ignore timestamp of CreatedAt CreatedAt: vol.CreatedAt, Driver: "local", @@ -90,7 +90,7 @@ func TestVolumesInspect(t *testing.T) { ctx := context.Background() now := time.Now() - vol, err := client.VolumeCreate(ctx, volumetypes.VolumeCreateBody{}) + vol, err := client.VolumeCreate(ctx, volume.VolumeCreateBody{}) assert.NilError(t, err) inspected, err := client.VolumeInspect(ctx, vol.Name) diff --git a/volume/service/convert.go b/volume/service/convert.go index 2967dc6722163..baad41ab09cef 100644 --- a/volume/service/convert.go +++ b/volume/service/convert.go @@ -4,8 +4,8 @@ import ( "context" "time" - "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" + volumetypes "github.com/docker/docker/api/types/volume" "github.com/docker/docker/pkg/directory" "github.com/docker/docker/volume" "github.com/sirupsen/logrus" @@ -28,9 +28,9 @@ type pathCacher interface { CachedPath() string } -func (s *VolumesService) volumesToAPI(ctx context.Context, volumes []volume.Volume, opts ...convertOpt) []*types.Volume { +func (s *VolumesService) volumesToAPI(ctx context.Context, volumes []volume.Volume, opts ...convertOpt) []*volumetypes.Volume { var ( - out = make([]*types.Volume, 0, len(volumes)) + out = make([]*volumetypes.Volume, 0, len(volumes)) getSize bool cachedPath bool ) @@ -69,7 +69,7 @@ func (s *VolumesService) volumesToAPI(ctx context.Context, volumes []volume.Volu logrus.WithError(err).WithField("volume", v.Name()).Warnf("Failed to determine size of volume") sz = -1 } - apiV.UsageData = &types.VolumeUsageData{Size: sz, RefCount: int64(s.vs.CountReferences(v))} + apiV.UsageData = &volumetypes.VolumeUsageData{Size: sz, RefCount: int64(s.vs.CountReferences(v))} } out = append(out, &apiV) @@ -77,9 +77,9 @@ func (s *VolumesService) volumesToAPI(ctx context.Context, volumes []volume.Volu return out } -func volumeToAPIType(v volume.Volume) types.Volume { +func volumeToAPIType(v volume.Volume) volumetypes.Volume { createdAt, _ := v.CreatedAt() - tv := types.Volume{ + tv := volumetypes.Volume{ Name: v.Name(), Driver: v.DriverName(), CreatedAt: createdAt.Format(time.RFC3339), diff --git a/volume/service/service.go b/volume/service/service.go index b185471a39b67..59ea1f9eca420 100644 --- a/volume/service/service.go +++ b/volume/service/service.go @@ -7,6 +7,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" + volumetypes "github.com/docker/docker/api/types/volume" "github.com/docker/docker/errdefs" "github.com/docker/docker/pkg/directory" "github.com/docker/docker/pkg/idtools" @@ -62,7 +63,7 @@ func (s *VolumesService) GetDriverList() []string { // // A good example for a reference ID is a container's ID. // When whatever is going to reference this volume is removed the caller should defeference the volume by calling `Release`. -func (s *VolumesService) Create(ctx context.Context, name, driverName string, opts ...opts.CreateOption) (*types.Volume, error) { +func (s *VolumesService) Create(ctx context.Context, name, driverName string, opts ...opts.CreateOption) (*volumetypes.Volume, error) { if name == "" { name = stringid.GenerateRandomID() } @@ -77,7 +78,7 @@ func (s *VolumesService) Create(ctx context.Context, name, driverName string, op } // Get returns details about a volume -func (s *VolumesService) Get(ctx context.Context, name string, getOpts ...opts.GetOption) (*types.Volume, error) { +func (s *VolumesService) Get(ctx context.Context, name string, getOpts ...opts.GetOption) (*volumetypes.Volume, error) { v, err := s.vs.Get(ctx, name, getOpts...) if err != nil { return nil, err @@ -104,7 +105,7 @@ func (s *VolumesService) Get(ctx context.Context, name string, getOpts ...opts.G // s.Mount(ctx, vol, mountID) // s.Unmount(ctx, vol, mountID) // ``` -func (s *VolumesService) Mount(ctx context.Context, vol *types.Volume, ref string) (string, error) { +func (s *VolumesService) Mount(ctx context.Context, vol *volumetypes.Volume, ref string) (string, error) { v, err := s.vs.Get(ctx, vol.Name, opts.WithGetDriver(vol.Driver)) if err != nil { if IsNotExist(err) { @@ -121,7 +122,7 @@ func (s *VolumesService) Mount(ctx context.Context, vol *types.Volume, ref strin // The reference specified here should be the same reference specified during `Mount` and should be // unique for each mount/unmount pair. // See `Mount` documentation for an example. -func (s *VolumesService) Unmount(ctx context.Context, vol *types.Volume, ref string) error { +func (s *VolumesService) Unmount(ctx context.Context, vol *volumetypes.Volume, ref string) error { v, err := s.vs.Get(ctx, vol.Name, opts.WithGetDriver(vol.Driver)) if err != nil { if IsNotExist(err) { @@ -184,7 +185,7 @@ var acceptedListFilters = map[string]bool{ // Note that this intentionally skips volumes which have mount options. Typically // volumes with mount options are not really local even if they are using the // local driver. -func (s *VolumesService) LocalVolumesSize(ctx context.Context) ([]*types.Volume, error) { +func (s *VolumesService) LocalVolumesSize(ctx context.Context) ([]*volumetypes.Volume, error) { ls, _, err := s.vs.Find(ctx, And(ByDriver(volume.DefaultDriverName), CustomFilter(func(v volume.Volume) bool { dv, ok := v.(volume.DetailedVolume) return ok && len(dv.Options()) == 0 @@ -247,7 +248,7 @@ func (s *VolumesService) Prune(ctx context.Context, filter filters.Args) (*types // List gets the list of volumes which match the past in filters // If filters is nil or empty all volumes are returned. -func (s *VolumesService) List(ctx context.Context, filter filters.Args) (volumesOut []*types.Volume, warnings []string, err error) { +func (s *VolumesService) List(ctx context.Context, filter filters.Args) (volumesOut []*volumetypes.Volume, warnings []string, err error) { by, err := filtersToBy(filter, acceptedListFilters) if err != nil { return nil, nil, err