Commit graph

435 commits

Author SHA1 Message Date
Sebastiaan van Stijn
a5f6500958
replace deprecated gotest.tools' env.Patch() with t.SetEnv()
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-05-28 12:12:39 +02:00
Paweł Gronowski
85a7f5a09a daemon/linux: Set console size on creation
On Linux the daemon was not respecting the HostConfig.ConsoleSize
property and relied on cli initializing the tty size after the container
was created. This caused a delay between container creation and
the tty actually being resized.

This is also a small change to the api description, because
HostConfig.ConsoleSize is no longer Windows-only.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2022-05-19 07:57:27 +02:00
Sebastiaan van Stijn
d9524d92a9
api/types/swarm: Version: implement stringer interface
makes the code a bit more DRY.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-05-13 02:40:14 +02:00
Drew Erny
240a9fcb83
Add Swarm cluster volume supports
Adds code to support Cluster Volumes in Swarm using CSI drivers.

Signed-off-by: Drew Erny <derny@mirantis.com>
2022-05-13 00:55:44 +02:00
Nicolas De Loof
af5d83a641
Make it explicit raw|multiplexed stream implementation being used
fix #35761

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2022-05-12 11:36:31 +02:00
Sebastiaan van Stijn
41b96bff55
update uses of container.ContainerCreateCreatedBody to CreateResponse
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-04-28 22:39:20 +02:00
Sebastiaan van Stijn
64e96932bd
api: rename volume.VolumeCreateBody to volume.CreateOptions
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-04-28 22:39:14 +02:00
Sebastiaan van Stijn
18281c92fa
api: rename volume.VolumeListOKBody to volume.ListResponse
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-04-28 22:39:12 +02:00
Sebastiaan van Stijn
3cae9fef16
imports: remove "volumetypes" aliases for api/types/volume
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-04-28 22:39:04 +02:00
Sebastiaan van Stijn
7293857456
api: rename ContainerWaitOKBody to container.WaitResponse
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-04-28 22:38:20 +02:00
Brian Goff
b3332b851a
Merge pull request #43517 from Juneezee/test/t.Setenv
test: use `T.Setenv` to set env vars in tests
2022-04-28 12:02:01 -07:00
Eng Zer Jun
36049a04d2
test: use T.Setenv to set env vars in tests
This commit replaces `os.Setenv` with `t.Setenv` in tests. The
environment variable is automatically restored to its original value
when the test and all its subtests complete.

Reference: https://pkg.go.dev/testing#T.Setenv
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-04-23 17:44:16 +08:00
Sebastiaan van Stijn
176f66df9c
api/types: replace uses of deprecated types.Volume with volume.Volume
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-04-21 19:50:59 +02:00
Sebastiaan van Stijn
e8fa708ae5
client: ContainerStop(), ContainerRestart(): support stop-signal
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-04-20 21:29:34 +02:00
Sebastiaan van Stijn
9060126639
client, integration-cli: remove unneeded import aliases
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-04-20 21:29:33 +02:00
Brian Goff
c4e3a16373
Merge pull request #43494 from thaJeztah/client_cp_error_handling
client: CopyToContainer(), CopyFromContainer(): remove status-code handling
2022-04-20 10:36:19 -07:00
Sebastiaan van Stijn
b365924ec3
client: ContainerKill(): don't send signal query-param if none was set
Just a small clean-up (there's more endpoints to do this for, but
I was working on changes in this area on the CLI when I noticed we
were setting this query-parameter unconditionally.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-04-19 17:40:33 +02:00
Sebastiaan van Stijn
013d648888
client: CopyToContainer(), CopyFromContainer(): remove status-code handling
This was added in 93c3e6c91e, at which time only
some basic handling of non-succesful status codes was present;
93c3e6c91e/api/client/utils.go (L112-L121)

Given that since 38e6d474af non-successful status-
codes are already handled, and a 204 ("no content") status should not be an error,
this special case should no longer be needed.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-04-19 08:28:20 +02:00
Sebastiaan van Stijn
890231f46b
client: container ps: don't set "limit" if none was set
both -1 and 0 are accepted as "no limit", so don't send the
limit option if no limit was set. For simplicity, we're ignoring
values <= 0.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-03-31 19:59:17 +02:00
Sebastiaan van Stijn
1e645fb70f
client: Ping(): add handling for swarm status headers
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-03-25 23:57:58 +01:00
Sebastiaan van Stijn
45067cda33
client: remove wrapResponseError()
The wrapResponseError() utility converted some specific errors, but in
doing so, could hide the actual error message returned by the daemon.
In addition, starting with 38e6d474af,
HTTP status codes were already mapped to their corresponding errdefs
types on the client-side, making this conversion redundant.

This patch removes the wrapResponseError() utility; it's worth noting
that some error-messages will change slightly (as they now return the
error as returned by the daemon), but may cointain more details as
before, and in some cases prevents hiding the actual error.

Before this change:

    docker container rm nosuchcontainer
    Error: No such container: nosuchcontainer

    docker container cp mycontainer:/no/such/path .
    Error: No such container:path: mycontainer:/no/such/path

    docker container cp ./Dockerfile mycontainer:/no/such/path
    Error: No such container:path: mycontainer:/no/such

    docker image rm nosuchimage
    Error: No such image: nosuchimage

    docker network rm nosuchnetwork
    Error: No such network: nosuchnetwork

    docker volume rm nosuchvolume
    Error: No such volume: nosuchvolume

    docker plugin rm nosuchplugin
    Error: No such plugin: nosuchplugin

    docker checkpoint rm nosuchcontainer nosuchcheckpoint
    Error response from daemon: No such container: nosuchcontainer

    docker checkpoint rm mycontainer nosuchcheckpoint
    Error response from daemon: checkpoint nosuchcheckpoint does not exist for container mycontainer

    docker service rm nosuchservice
    Error: No such service: nosuchservice

    docker node rm nosuchnode
    Error: No such node: nosuchnode

    docker config rm nosuschconfig
    Error: No such config: nosuschconfig

    docker secret rm nosuchsecret
    Error: No such secret: nosuchsecret

After this change:

    docker container rm nosuchcontainer
    Error response from daemon: No such container: nosuchcontainer

    docker container cp mycontainer:/no/such/path .
    Error response from daemon: Could not find the file /no/such/path in container mycontainer

    docker container cp ./Dockerfile mycontainer:/no/such/path
    Error response from daemon: Could not find the file /no/such in container mycontainer

    docker image rm nosuchimage
    Error response from daemon: No such image: nosuchimage:latest

    docker network rm nosuchnetwork
    Error response from daemon: network nosuchnetwork not found

    docker volume rm nosuchvolume
    Error response from daemon: get nosuchvolume: no such volume

    docker plugin rm nosuchplugin
    Error response from daemon: plugin "nosuchplugin" not found

    docker checkpoint rm nosuchcontainer nosuchcheckpoint
    Error response from daemon: No such container: nosuchcontainer

    docker checkpoint rm mycontainer nosuchcheckpoint
    Error response from daemon: checkpoint nosuchcheckpoint does not exist for container mycontainer

    docker service rm nosuchservice
    Error response from daemon: service nosuchservice not found

    docker node rm nosuchnode
    Error response from daemon: node nosuchnode not found

    docker config rm nosuchconfig
    Error response from daemon: config nosuchconfig not found

    docker secret rm nosuchsecret
    Error response from daemon: secret nosuchsecret not found

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-03-20 19:04:52 +01:00
Sebastiaan van Stijn
165fe27979
Merge pull request #43380 from thaJeztah/client_search_limits
client: ImageSearch(): don't send limit if none was specified
2022-03-17 10:43:14 +01:00
Sebastiaan van Stijn
ce7a919a15
Merge pull request #43342 from thaJeztah/client_test_cleanup
client: cleanup and fix some tests
2022-03-16 14:47:43 +01:00
Sebastiaan van Stijn
8ba83f63a0
client: ImageSearch(): don't send limit if none was specified
The API defines a default limit for searches, but when removing the
default from the cli, the client still sends "0" as a limit, which
is not allowed by existing versions of the API:

    docker search --limit=0 busybox
    Error response from daemon: Limit 0 is outside the range of [1, 100]

This patch changes the client so that no limit is sent if none was set ("0"),
allowing the daemon to use its (or the registry's) default.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-03-15 14:53:46 +01:00
Sebastiaan van Stijn
5979d6e7e3
client: add const for environment variables, and document them
This adds consts for the environment variables that are supported
by the client. These environment variables are unlikely to change,
or at least, unlikely to be removed, but having consts allows for
them to be documented.

I did not change all occurrences of these variables to use the const,
as they're used in various tests, and it's ok to use a fixture for
those, but it's nice to have a const available for (external) consumers
of the client package, and to have their purpose (and caveats)
documented in the code.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-03-07 12:35:55 +01:00
Sebastiaan van Stijn
c2c7e9d449
client: improve GoDoc, and minor touch-ups
- Improve documentation of various functions to better describe their behavior.
- Rename some variables to be more descriptive (as this is client code, used
  by external consumers, it's nice to be a bit more explicit).
- Remove a redundant check in `WithVersionFromEnv()`, as `WithVersion()`
  already checks for empty values.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-03-07 12:35:38 +01:00
Sebastiaan van Stijn
8512cf076c
client: TestNegotiateAPIVersion(), TestClientRedirect(): use sub-tests
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-03-07 11:13:52 +01:00
Sebastiaan van Stijn
25a336ab6a
client: TestGetAPIPath(): update test to use more realistic results
This test was setting the non-exported `Client.basePath` directly, however,
it was setting it to a value that would never realistically happen, because
`NewClientWithOpts()` initializes the Client with the default API version:
ea5b4765d9/client/client.go (L119-L130)

Which is used by `getAPIPath()` to construct the URL/path:
ea5b4765d9/client/client.go (L176-L190)

While this didn't render the test "invalid", using a Client that's constructed
in the usual way, makes it more representative.

Given that we deprecated (but still support) the non-versioned API paths, with
the exception of the `/_ping` API endpoint, we should probably change `getAPIPath()`
to default to the "current version", instead of allowing it to use an empty string.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-03-07 11:13:02 +01:00
Sebastiaan van Stijn
65e4ea27cd
client: various small test-improvements
- avoid accessing non-exported fields where possible, and test using accessors
  instead, so that we're closer to how it's actually used.
- use a variable or const for "expected" in some tests, so that "expected" is
  printed as part of the test-failure output (instead of just a "value").
- swap the order of "actual" and "expected" for consistency, and to make it
  easier to see what the "expected" value is in some cases ("expected" on the
  right, so that it reads `val (actual) != val (expected)`).
- don't set fields in the Ping response that are not relevant to the test.
- rename some variables for consistency.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-03-07 10:58:03 +01:00
Sebastiaan van Stijn
948c2c45bb
client: use canonical names for HTTP Headers
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-03-06 10:49:02 +01:00
Sebastiaan van Stijn
a0230f3d9a
remove unneeded "digest" alias for "go-digest"
I think this was there for historic reasons (may have been goimports expected
this, and we used to have a linter that wanted it), but it's not needed, so
let's remove it (to make my IDE less complaining about unneeded aliases).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-03-04 14:49:42 +01:00
Sebastiaan van Stijn
a832635e51
client.ContainerWait(): don't send empty "condition" query parameter
The client would always send a value, even if no `condition` was set;

    Calling POST /v1.41/containers/foo/wait?condition=

This patch changes the client to not send the parameter if it's empty (and the
API default value should be used).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-02-14 21:47:53 +01:00
Akihiro Suda
3b02526c1e
Merge pull request #42224 from thaJeztah/more_client_opts
client: extract FromEnv parts to separate WithXX options
2022-02-11 13:17:05 +09:00
Sebastiaan van Stijn
eae20b1a1b
client: extract FromEnv parts to separate WithXX options
Implements three options;

- WithTLSClientConfigFromEnv()
- WithHostFromEnv()
- WithVersionFromEnv()

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-02-10 17:15:40 +01:00
Sebastiaan van Stijn
99935ff803
client.NewClientWithOpts(): remove redundant type assertion (gosimple)
As caught by gosimple:

    client/client.go:138:14: S1040: type assertion to the same type: c.client.Transport already has type http.RoundTripper (gosimple)
        if _, ok := c.client.Transport.(http.RoundTripper); !ok {
                    ^

This check was originally added in dc9f5c2ca3, to
check if the passed option was a `http.Transport`, and later changed in
e345cd12f9 to check for `http.RoundTripper` instead.

Client.client is a http.Client, for which the Transport field is a RoundTripper,
so this check is redundant.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-02-08 09:43:25 +01:00
Sebastiaan van Stijn
2cff05e960
client/request.go:157:8: SA1019: err.Temporary is deprecated (staticcheck)
It's deprecated in Go 1.18:

    client/request.go:157:8: SA1019: err.Temporary is deprecated: Temporary errors are not well-defined. Most "temporary" errors are timeouts, and the few exceptions are surprising. Do not use this method. (staticcheck)
        if !err.Temporary() {
            ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-01-31 15:59:51 +01:00
Akihiro Suda
33a3680e08
Merge pull request #42738 from thaJeztah/client_networkinspect_test
client: use subtests for TestNetworkInspect
2021-11-09 18:37:44 +09:00
Akihiro Suda
0cd1bd42b4
Merge pull request #42770 from thaJeztah/eventtype_enums
api/types/events: add "Type" type for event-type enum
2021-08-28 00:23:56 +09:00
Sebastiaan van Stijn
4045c4ceaf
client: use subtests for TestNetworkInspect
Unify the NetworkInspect tests to remove some boilerplating

Before this change:

    go test -v -run TestNetworkInspect ./client/
    === RUN   TestNetworkInspectError
    --- PASS: TestNetworkInspectError (0.00s)
    === RUN   TestNetworkInspectNotFoundError
    --- PASS: TestNetworkInspectNotFoundError (0.00s)
    === RUN   TestNetworkInspectWithEmptyID
    --- PASS: TestNetworkInspectWithEmptyID (0.00s)
    === RUN   TestNetworkInspect
    --- PASS: TestNetworkInspect (0.00s)
    PASS
    ok  	github.com/docker/docker/client	0.010s

With this change:

    go test -v -run TestNetworkInspect ./client/
    === RUN   TestNetworkInspect
    === RUN   TestNetworkInspect/empty_ID
    === RUN   TestNetworkInspect/no_options
    === RUN   TestNetworkInspect/verbose
    === RUN   TestNetworkInspect/global_scope
    === RUN   TestNetworkInspect/unknown_network
    === RUN   TestNetworkInspect/server_error
    --- PASS: TestNetworkInspect (0.00s)
        --- PASS: TestNetworkInspect/empty_ID (0.00s)
        --- PASS: TestNetworkInspect/no_options (0.00s)
        --- PASS: TestNetworkInspect/verbose (0.00s)
        --- PASS: TestNetworkInspect/global_scope (0.00s)
        --- PASS: TestNetworkInspect/unknown_network (0.00s)
        --- PASS: TestNetworkInspect/server_error (0.00s)
    PASS
    ok  	github.com/docker/docker/client	0.012s

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-08-27 16:56:11 +02:00
Eng Zer Jun
c55a4ac779
refactor: move from io/ioutil to io and os package
The io/ioutil package has been deprecated in Go 1.16. This commit
replaces the existing io/ioutil functions with their new definitions in
io and os packages.

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2021-08-27 14:56:57 +08:00
Sebastiaan van Stijn
686be57d0a
Update to Go 1.17.0, and gofmt with Go 1.17
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-08-24 23:33:27 +02:00
Sebastiaan van Stijn
247f4796d2
api/types/events: add "Type" type for event-type enum
Currently just an alias for string, but we can change it to be  an
actual type.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-08-23 21:14:55 +02:00
Sebastiaan van Stijn
a6dd341ca2
client: remove deprecated SetCustomHTTPHeaders(), CustomHTTPHeaders()
Both of these function were added in a754d89b40.

The CustomHTTPHeaders() was not used, except for a unit test in docker/cli (this
test has already been updated to not depend on this function);
https://grep.app/search?q=.CustomHTTPHeaders%28%29&filter[lang][0]=Go

Commit a68ae4a2d9 deprecated SetCustomHTTPHeaders(),
and looks to be unused; https://grep.app/search?q=.SetCustomHTTPHeaders%28&filter[lang][0]=Go

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-08-06 19:33:44 +02:00
Sebastiaan van Stijn
8afb57e633
client: deprecate client.CustomHTTPHeaders()
This function was added in a754d89b40, but not
used. Currently, the only consumer of this function I could find was docker/cli,
which used it in a unit-test (this test has already been updated to not depend
on this function); https://grep.app/search?q=.CustomHTTPHeaders%28%29&filter[lang][0]=Go

Given that commit a68ae4a2d9 deprecated the
corresponding client.SetCustomHTTPHeaders() function, and because there is no
active use for this function, it should be ok to deprecate.

We can include this in a patch-release (to be sure nobody else is depending on
it, and (if someone is) to notify them of the deprecation.

As a follow-up to this commit, I'll remove both functions.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-08-06 19:33:41 +02:00
Sebastiaan van Stijn
656a5e2bdf
Merge pull request #42559 from rvolosatovs/system_df_types
Add `type` parameter to `/system/df`
2021-08-02 21:03:05 +02:00
Sebastiaan van Stijn
5f0703c549
client: remove containerd "platform" dependency
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-07-29 23:32:46 +02:00
Sebastiaan van Stijn
b33f3c7802
client: remove unused Platform field from configWrapper
This field was added in 7a9cb29fb9,
but appears to be unused, so removing it.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-07-29 23:28:12 +02:00
Roman Volosatovs
47ad2f3dd6
API,daemon: support type URL parameter to /system/df
Let clients choose object types to compute disk usage of.

Signed-off-by: Roman Volosatovs <roman.volosatovs@docker.com>
Co-authored-by: Sebastiaan van Stijn <github@gone.nl>
2021-07-27 12:17:45 +02:00
Akihiro Suda
b9ad7b96bd
Merge pull request #41778 from kplachkov/feature/fix_err_canceled
Fix converting status code to error canceled
2021-06-17 17:26:14 +09:00
Sebastiaan van Stijn
b92be7e297
client: S1031: unnecessary nil check around range (gosimple)
client/request.go:245:2: S1031: unnecessary nil check around range (gosimple)
        if headers != nil {
        ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-06-10 13:03:23 +02:00