Commit Graph

1205 Commits

Author SHA1 Message Date
Cory Snider
9ebbf652bd client: do not modify user-provided HTTP client
The http.Client passed into client.WithHTTPClient() is modified by the
constructor in-place: the value of its Transport field is mutated and
wrapped in an OpenTelemetry decorator. This can lead to very surprising
behaviour when a second client is constructed reusing the same
http.Client value. If the http.Client is configured for TLS, the second
client will fail to detect that and will incorrectly dial the Engine API
socket as cleartext HTTP. Copy the provided http.Client so our
modifications don't leak out to unexpected places.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2026-01-06 18:14:13 -05:00
Michael Smithhisler
06704ef904 client: use stop function to deregister context.AfterFunc
Signed-off-by: Michael Smithhisler <smithhisler.mike@gmail.com>
2026-01-05 08:24:48 -05:00
Sebastiaan van Stijn
7b74376ff1 client: testRoundTripper: remove unused skipConfigureTransport method
This was added in a315437e1c, likely because
I tried to do some interface matching, but currently it doesn't look to
be implementing one, so we can remove it.

    client/client_options.go:136:25: func testRoundTripper.skipConfigureTransport is unused (unused)
    func (testRoundTripper) skipConfigureTransport() bool { return true }
                            ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-12-18 17:11:23 +01:00
Sebastiaan van Stijn
34ee29ceaa client: use errors.New (revive)
client/container_exec_test.go:152:19: use-errors-new: replace fmt.Errorf by errors.New (revive)
                            return nil, fmt.Errorf("should not have made API request")
                                        ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-12-18 17:11:23 +01:00
Sebastiaan van Stijn
e254a9f0f1 client: containerDiskUsageFromLegacyAPI: make switch exhaustive
client/system_disk_usage.go:275:3: missing cases in switch of type container.ContainerState: container.StateCreated, container.StateRemoving, container.StateExited, container.StateDead (exhaustive)
            switch c.State {
            ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-12-18 17:11:23 +01:00
Sebastiaan van Stijn
f39912a30e client: fix some missing error checks in tests (ineffassign)
client/client_test.go:367:5: ineffectual assignment to err (ineffassign)
        _, err = client.Ping(t.Context(), PingOptions{
           ^
    client/client_test.go:381:5: ineffectual assignment to err (ineffassign)
        _, err = client.Ping(t.Context(), PingOptions{
           ^
    client/client_test.go:425:5: ineffectual assignment to err (ineffassign)
        _, err = client.Ping(t.Context(), PingOptions{
           ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-12-18 17:11:15 +01:00
Sebastiaan van Stijn
8f3bfa3f34 client: fix missing import aliases (importas)
client/container_exec.go:8:2: import "github.com/containerd/errdefs" imported without alias but must be with alias "cerrdefs" according to config (importas)
        "github.com/containerd/errdefs"
        ^
    client/container_exec_test.go:9:2: import "github.com/containerd/errdefs" imported without alias but must be with alias "cerrdefs" according to config (importas)
        "github.com/containerd/errdefs"
        ^
    client/container_rename.go:8:2: import "github.com/containerd/errdefs" imported without alias but must be with alias "cerrdefs" according to config (importas)
        "github.com/containerd/errdefs"
        ^
    client/pkg/security/security_opts_test.go:8:2: import "gotest.tools/v3/assert/cmp" imported without alias but must be with alias "is" according to config (importas)
        "gotest.tools/v3/assert/cmp"
        ^
    client/volume_prune.go:9:2: import "github.com/containerd/errdefs" imported without alias but must be with alias "cerrdefs" according to config (importas)
        "github.com/containerd/errdefs"
        ^
    client/volume_prune_test.go:8:2: import "github.com/containerd/errdefs" imported without alias but must be with alias "cerrdefs" according to config (importas)
        "github.com/containerd/errdefs"
        ^
    client/container_exec_test.go:10:2: ST1019(related information): other import of "github.com/containerd/errdefs" (staticcheck)
        cerrdefs "github.com/containerd/errdefs"
        ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-12-18 15:27:34 +01:00
Paweł Gronowski
4b9e56156d Re-add replace rules
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-12-17 16:34:13 +01:00
Paweł Gronowski
3cee1aad22 vendor: github.com/moby/moby/api v1.53.0-rc.1
full diff: https://github.com/moby/moby/api/compare/8b3dd2d280d7...v1.53.0-rc.1

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-12-17 16:05:16 +01:00
Paweł Gronowski
5070ad8dc1 Drop replace rules
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-12-17 15:45:55 +01:00
Nicolas De Loof
aef5d996ce use mime-type application/jsonl to align with openapi 3.2
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-12-17 11:37:48 +01:00
Rob Murray
54a6ec374a Update client MaxAPIVersion to 1.53
The daemon's MaxAPIVersion was updated in commit f6b1488.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-12-16 11:03:58 +00:00
Sebastiaan van Stijn
29560eacda go.mod: add back replace rules
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-12-05 16:10:28 +01:00
Sebastiaan van Stijn
773aca9f5d api, client: add separate LICENSE file
In a multi-module repository, the top-level LICENSE file is used for
all modules in the repository. However, when using a "replace" rule,
the vendored file is removed, but added back when removing the replace
rule.

This patch adds copies of the license to each of the modules to reduce
code-churn; these are vanilla copies downloaded from;
https://www.apache.org/licenses/LICENSE-2.0.txt

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-12-05 15:57:55 +01:00
Rob Murray
ea539d267d client - use tagged api module
Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-11-27 15:33:52 +00:00
Rob Murray
a60bea5412 Drop replace rules
Prepare v29.1.0

Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-11-27 13:15:03 +00:00
Sebastiaan van Stijn
04ab3d562c client: don't downgrade when failing to negotiate
Historically, the client would downgrade to API v1.24 when failing
to negotiate as this was the API version from before API-version
negotiation was introduced.

Given that those daemons are EOL and those API versions no longer
supported, we should not fall back to an older API version, and
just continue using the latest / current version.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-11-27 13:52:27 +01:00
Sebastiaan van Stijn
189942570a client: enable API-version negotiation by default
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-11-27 13:52:27 +01:00
Sebastiaan van Stijn
e752ec0f8e client: fix typo in comment
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-11-27 13:52:24 +01:00
Sebastiaan van Stijn
bec7ab7f62 client: TestTLSCloseWriter: test with version negotiation enabled
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-11-27 12:05:27 +01:00
Sebastiaan van Stijn
701f2fdade client: improve mocking responses
Make the mocked responses match the API closer;

- Add headers as returned by the daemon's VersionMiddleware
- By default handle "/_ping" requests to allow the client to
  perform API-version negotiation as part of tests.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-11-27 12:05:27 +01:00
Sebastiaan van Stijn
ef588715b6 client: add mockPingResponse utility
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-11-27 12:05:26 +01:00
Sebastiaan van Stijn
acb5c5a390 client: mockResponse: prevent sharing body reader
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-11-27 12:05:26 +01:00
Sebastiaan van Stijn
45c9f460b8 client: checkResponseErr: don't read body for HEAD requests
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-11-27 12:05:26 +01:00
Sebastiaan van Stijn
77858fab6e client: ensureBody: also ensure the request is preserved
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-11-27 12:05:26 +01:00
Sebastiaan van Stijn
e51a4306e2 client: ensureReaderClosed: small optimizations
Skip draining for HEAD requests and empty responses.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-11-27 12:05:26 +01:00
Sebastiaan van Stijn
89bd3150e1 client: client.ping(): use fresh request for HEAD -> GET
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-11-27 12:05:25 +01:00
Sebastiaan van Stijn
75520d1f5b client: resolveContainerSpecImage, resolvePluginSpecRemote: early returns
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-11-26 19:24:27 +01:00
Sebastiaan van Stijn
366ea9e9af client: ServiceCreate,ServiceUpdate: don't add empty warnings
This code was refactored in cd08b79c02, which
forgot to add a check for empty warnings.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-11-26 19:20:45 +01:00
Paweł Gronowski
931784650d Merge pull request #51533 from thaJeztah/client_refactor_negotiate
client: simplify logic for manual vs auto API versions
2025-11-17 16:39:11 +00:00
Paweł Gronowski
46e28a284a Merge pull request #51539 from thaJeztah/fix_content_type
client: Client.buildRequest: fix content-type handling
2025-11-17 16:14:49 +00:00
Sebastiaan van Stijn
9ab033cc8a client: TestTLSCloseWriter: assorted cleanups / fixes
- close idle connections after test
- don't discard failures to write upgrade response
- ignore errors in defer to make the linters happy

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-11-16 20:56:12 +01:00
Sebastiaan van Stijn
4622dd0ccc client: Client.buildRequest, jsonEncode improve handling of content
- add early returns for `nil` body, `http.NoBody`, and `json.RawMessage`
- use `http.NoBody` instead of `nil` for empty bodies; it's more clear
  on intent.
- use json.Encode instead of json.Encoder.Encode(), as we're marshaling
  a single JSON document; this also avoid adding a trailing newline.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-11-15 00:39:59 +01:00
Sebastiaan van Stijn
20d65620f9 client: Client.buildRequest: don't set content-header if not set
This function was setting `text/plain` as default content-type for any
request that had a non-nil body.

However, this would also set the content-type if (e.g.) `http.NoBody` was set,
or if an empty reader was used, which would result in the daemon potentialy
rejecting the request, as it validates request to be using `application/json`;
d9ee22d1ab/daemon/server/httputils/httputils.go (L47-L58)

    === RUN   TestCommitInheritsEnv
        commit_test.go:30: assertion failed: error is not nil: Error response from daemon: unsupported Content-Type header (text/plain): must be 'application/json'
    --- FAIL: TestCommitInheritsEnv (0.02s)

This patch removes setting the default content-type.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-11-15 00:39:59 +01:00
Sebastiaan van Stijn
4e2e2cde7e client: simplify logic for manual vs auto API versions
When manually setting the API version to use, automatic API version
negotiation should no longer be performed. Instead of keeping track
of these options individually, we can mark negotiation to have happend
if either the version was set manually, or if API version negotiation
took place.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-11-14 20:30:49 +01:00
Sebastiaan van Stijn
d9ee22d1ab Merge pull request #51530 from thaJeztah/allow_renegotiate
client: client.Ping: allow ForceNegotiate with manual override
2025-11-14 20:07:27 +01:00
Sebastiaan van Stijn
6857132911 client: client.Ping: allow ForceNegotiate with manual override
While a manual overridden version shouldn't perform automatic version
negotiation, the "ForceNegotiate" option could still be used to (re)
negotiate a version. This allows a client to be configured with an
initial API version, then triggered to perform API-version negotiation.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-11-14 17:41:56 +01:00
Sebastiaan van Stijn
53764de815 client: make WithAPIVersion, WithAPIVersionFromEnv order-independent
Environment-variables are expected to override config / defaults, so
make sure that the DOCKER_API_VERSION env-var always takes priority.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-11-14 13:54:32 +01:00
Sebastiaan van Stijn
a5c7f3f9c8 client: don't negotiate malformed responses
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-11-14 13:54:31 +01:00
Sebastiaan van Stijn
bcc1db1ce5 client: WithAPIVersion, WithAPIVersionFromEnv: validate well-formedness
Make these options more strict to not allow arbitrary values. Historically,
the `DOCKER_API_VERSION` env-var did not perform any validation as it was
intended for testing-purposes, but given the wider use of this env-var,
we should perform some amount of validation.

Both `WithAPIVersion` and `WithAPIVersionFromEnv` still allow specifying
API versions that are not supported by the client for testing purposes
(e.g. to use API versions beyond `MinAPIVersion` and `MaxAPIVersion`),
but must be well-formed.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-11-14 13:54:31 +01:00
Sebastiaan van Stijn
83ad5c92f7 client: Client.ping() fix duplicate ping
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-11-14 13:54:27 +01:00
Sebastiaan van Stijn
611c7dce43 client: export fallbackAPIVersion as MinAPIVersion
Export the const and rename it to better reflect its intent.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-11-14 10:26:37 +01:00
Sebastiaan van Stijn
94e83af71a client: TestImageListWithSharedSize: merge with TestImageList
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-11-13 15:57:24 +01:00
Sebastiaan van Stijn
62589a6961 client: TestTLSCloseWriter: cancel context after test
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-11-13 15:46:54 +01:00
Sebastiaan van Stijn
a5dec0a779 client: make sure context is canceled for ContainerWait tests
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-11-13 15:44:09 +01:00
Sebastiaan van Stijn
76a4381d45 client: TestImageListWithSharedSize slight reformat
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-11-13 15:43:13 +01:00
Sebastiaan van Stijn
9af7fbff2a client: TestImageList: use subtests
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-11-13 15:43:13 +01:00
Sebastiaan van Stijn
dae3650dcc client: rename/deprecate WithVersion, WithVersionFromEnv
Add WithAPIVersion and WithAPIVersionFromEnv to be more clear on
the intent, and to align with other related options and fields.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-11-12 22:39:05 +01:00
Sebastiaan van Stijn
e5db2380f5 client: rename options.go to client_options.go
Make sure the options are next to the client.go file, which use the
consumer of these options.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-11-12 22:39:02 +01:00
Sebastiaan van Stijn
2729703967 client: fix example in README (align with ExampleNew())
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-11-12 20:31:04 +01:00