Skip to content

Commit 7652f38

Browse files
committed
client: remove API-version compatibility for API < v1.44
Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 6bbb92d commit 7652f38

23 files changed

Lines changed: 80 additions & 419 deletions

client/container_create.go

Lines changed: 17 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package client
33
import (
44
"context"
55
"encoding/json"
6-
"errors"
76
"net/url"
87
"path"
98
"sort"
@@ -25,54 +24,28 @@ func (cli *Client) ContainerCreate(ctx context.Context, config *container.Config
2524

2625
var response container.CreateResponse
2726

28-
// Make sure we negotiated (if the client is configured to do so),
29-
// as code below contains API-version specific handling of options.
30-
//
31-
// Normally, version-negotiation (if enabled) would not happen until
32-
// the API request is made.
33-
if err := cli.checkVersion(ctx); err != nil {
34-
return response, err
35-
}
36-
37-
if err := cli.NewVersionError(ctx, "1.25", "stop timeout"); config.StopTimeout != nil && err != nil {
38-
return response, err
39-
}
40-
if err := cli.NewVersionError(ctx, "1.41", "specify container image platform"); platform != nil && err != nil {
41-
return response, err
42-
}
43-
if err := cli.NewVersionError(ctx, "1.44", "specify health-check start interval"); config.Healthcheck != nil && config.Healthcheck.StartInterval != 0 && err != nil {
44-
return response, err
45-
}
46-
if err := cli.NewVersionError(ctx, "1.44", "specify mac-address per network"); hasEndpointSpecificMacAddress(networkingConfig) && err != nil {
47-
return response, err
48-
}
49-
5027
if hostConfig != nil {
51-
if platform != nil && platform.OS == "linux" && versions.LessThan(cli.ClientVersion(), "1.42") {
52-
// When using API under 1.42, the Linux daemon doesn't respect the ConsoleSize
53-
hostConfig.ConsoleSize = [2]uint{0, 0}
54-
}
55-
if versions.LessThan(cli.ClientVersion(), "1.44") {
56-
for _, m := range hostConfig.Mounts {
57-
if m.BindOptions != nil {
58-
// ReadOnlyNonRecursive can be safely ignored when API < 1.44
59-
if m.BindOptions.ReadOnlyForceRecursive {
60-
return response, errors.New("bind-recursive=readonly requires API v1.44 or later")
61-
}
62-
if m.BindOptions.NonRecursive && versions.LessThan(cli.ClientVersion(), "1.40") {
63-
return response, errors.New("bind-recursive=disabled requires API v1.40 or later")
64-
}
65-
}
66-
}
67-
}
68-
6928
hostConfig.CapAdd = normalizeCapabilities(hostConfig.CapAdd)
7029
hostConfig.CapDrop = normalizeCapabilities(hostConfig.CapDrop)
7130
}
7231

73-
// Since API 1.44, the container-wide MacAddress is deprecated and triggers a WARNING if it's specified.
74-
if versions.GreaterThanOrEqualTo(cli.ClientVersion(), "1.44") {
75-
config.MacAddress = "" //nolint:staticcheck // ignore SA1019: field is deprecated, but still used on API < v1.44.
32+
// FIXME(thaJeztah): remove this once we updated our (integration) tests;
33+
// some integration tests depend on this to test old API versions; see https://github.com/moby/moby/pull/51120#issuecomment-3376224865
34+
if config.MacAddress != "" { //nolint:staticcheck // ignore SA1019: field is deprecated, but still used on API < v1.44.
35+
// Make sure we negotiated (if the client is configured to do so),
36+
// as code below contains API-version specific handling of options.
37+
//
38+
// Normally, version-negotiation (if enabled) would not happen until
39+
// the API request is made.
40+
if err := cli.checkVersion(ctx); err != nil {
41+
return response, err
42+
}
43+
if versions.GreaterThanOrEqualTo(cli.ClientVersion(), "1.44") {
44+
// Since API 1.44, the container-wide MacAddress is deprecated and triggers a WARNING if it's specified.
45+
//
46+
// FIXME(thaJeztah): remove the field from the API
47+
config.MacAddress = "" //nolint:staticcheck // ignore SA1019: field is deprecated, but still used on API < v1.44.
48+
}
7649
}
7750

7851
query := url.Values{}

client/container_exec.go

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"net/http"
77

88
"github.com/moby/moby/api/types/container"
9-
"github.com/moby/moby/api/types/versions"
109
)
1110

1211
// ExecCreateOptions is a small subset of the Config struct that holds the configuration
@@ -32,22 +31,6 @@ func (cli *Client) ContainerExecCreate(ctx context.Context, containerID string,
3231
return container.ExecCreateResponse{}, err
3332
}
3433

35-
// Make sure we negotiated (if the client is configured to do so),
36-
// as code below contains API-version specific handling of options.
37-
//
38-
// Normally, version-negotiation (if enabled) would not happen until
39-
// the API request is made.
40-
if err := cli.checkVersion(ctx); err != nil {
41-
return container.ExecCreateResponse{}, err
42-
}
43-
44-
if err := cli.NewVersionError(ctx, "1.25", "env"); len(options.Env) != 0 && err != nil {
45-
return container.ExecCreateResponse{}, err
46-
}
47-
if versions.LessThan(cli.ClientVersion(), "1.42") {
48-
options.ConsoleSize = nil
49-
}
50-
5134
req := container.ExecCreateRequest{
5235
User: options.User,
5336
Privileged: options.Privileged,
@@ -86,19 +69,6 @@ type ExecStartOptions struct {
8669

8770
// ContainerExecStart starts an exec process already created in the docker host.
8871
func (cli *Client) ContainerExecStart(ctx context.Context, execID string, config ExecStartOptions) error {
89-
// Make sure we negotiated (if the client is configured to do so),
90-
// as code below contains API-version specific handling of options.
91-
//
92-
// Normally, version-negotiation (if enabled) would not happen until
93-
// the API request is made.
94-
if err := cli.checkVersion(ctx); err != nil {
95-
return err
96-
}
97-
98-
if versions.LessThan(cli.ClientVersion(), "1.42") {
99-
config.ConsoleSize = nil
100-
}
101-
10272
req := container.ExecStartRequest{
10373
Detach: config.Detach,
10474
Tty: config.Tty,
@@ -133,9 +103,6 @@ type ExecAttachOptions = ExecStartOptions
133103
//
134104
// [stdcopy.StdCopy]: https://pkg.go.dev/github.com/moby/moby/api/pkg/stdcopy#StdCopy
135105
func (cli *Client) ContainerExecAttach(ctx context.Context, execID string, config ExecAttachOptions) (HijackedResponse, error) {
136-
if versions.LessThan(cli.ClientVersion(), "1.42") {
137-
config.ConsoleSize = nil
138-
}
139106
req := container.ExecStartRequest{
140107
Detach: config.Detach,
141108
Tty: config.Tty,

client/container_restart.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"context"
55
"net/url"
66
"strconv"
7-
8-
"github.com/moby/moby/api/types/versions"
97
)
108

119
// ContainerRestart stops, and starts a container again.
@@ -22,17 +20,7 @@ func (cli *Client) ContainerRestart(ctx context.Context, containerID string, opt
2220
query.Set("t", strconv.Itoa(*options.Timeout))
2321
}
2422
if options.Signal != "" {
25-
// Make sure we negotiated (if the client is configured to do so),
26-
// as code below contains API-version specific handling of options.
27-
//
28-
// Normally, version-negotiation (if enabled) would not happen until
29-
// the API request is made.
30-
if err := cli.checkVersion(ctx); err != nil {
31-
return err
32-
}
33-
if versions.GreaterThanOrEqualTo(cli.version, "1.42") {
34-
query.Set("signal", options.Signal)
35-
}
23+
query.Set("signal", options.Signal)
3624
}
3725
resp, err := cli.post(ctx, "/containers/"+containerID+"/restart", query, nil, nil)
3826
defer ensureReaderClosed(resp)

client/container_stop.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"context"
55
"net/url"
66
"strconv"
7-
8-
"github.com/moby/moby/api/types/versions"
97
)
108

119
// ContainerStopOptions holds the options to stop or restart a container.
@@ -44,17 +42,7 @@ func (cli *Client) ContainerStop(ctx context.Context, containerID string, option
4442
query.Set("t", strconv.Itoa(*options.Timeout))
4543
}
4644
if options.Signal != "" {
47-
// Make sure we negotiated (if the client is configured to do so),
48-
// as code below contains API-version specific handling of options.
49-
//
50-
// Normally, version-negotiation (if enabled) would not happen until
51-
// the API request is made.
52-
if err := cli.checkVersion(ctx); err != nil {
53-
return err
54-
}
55-
if versions.GreaterThanOrEqualTo(cli.version, "1.42") {
56-
query.Set("signal", options.Signal)
57-
}
45+
query.Set("signal", options.Signal)
5846
}
5947
resp, err := cli.post(ctx, "/containers/"+containerID+"/stop", query, nil, nil)
6048
defer ensureReaderClosed(resp)

client/container_wait.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"net/url"
1010

1111
"github.com/moby/moby/api/types/container"
12-
"github.com/moby/moby/api/types/versions"
1312
)
1413

1514
const containerWaitErrorMsgLimit = 2 * 1024 /* Max: 2KiB */
@@ -41,19 +40,6 @@ func (cli *Client) ContainerWait(ctx context.Context, containerID string, condit
4140
return resultC, errC
4241
}
4342

44-
// Make sure we negotiated (if the client is configured to do so),
45-
// as code below contains API-version specific handling of options.
46-
//
47-
// Normally, version-negotiation (if enabled) would not happen until
48-
// the API request is made.
49-
if err := cli.checkVersion(ctx); err != nil {
50-
errC <- err
51-
return resultC, errC
52-
}
53-
if versions.LessThan(cli.ClientVersion(), "1.30") {
54-
return cli.legacyContainerWait(ctx, containerID)
55-
}
56-
5743
query := url.Values{}
5844
if condition != "" {
5945
query.Set("condition", string(condition))

client/hijack.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"net/url"
1010
"time"
1111

12-
"github.com/moby/moby/api/types/versions"
1312
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
1413
)
1514

@@ -28,11 +27,6 @@ func (cli *Client) postHijacked(ctx context.Context, path string, query url.Valu
2827
return HijackedResponse{}, err
2928
}
3029

31-
if versions.LessThan(cli.ClientVersion(), "1.42") {
32-
// Prior to 1.42, Content-Type is always set to raw-stream and not relevant
33-
mediaType = ""
34-
}
35-
3630
return NewHijackedResponse(conn, mediaType), nil
3731
}
3832

client/image_build.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (cli *Client) ImageBuild(ctx context.Context, buildContext io.Reader, optio
4242
}, nil
4343
}
4444

45-
func (cli *Client) imageBuildOptionsToQuery(ctx context.Context, options ImageBuildOptions) (url.Values, error) {
45+
func (cli *Client) imageBuildOptionsToQuery(_ context.Context, options ImageBuildOptions) (url.Values, error) {
4646
query := url.Values{}
4747
if len(options.Tags) > 0 {
4848
query["t"] = options.Tags
@@ -79,9 +79,7 @@ func (cli *Client) imageBuildOptionsToQuery(ctx context.Context, options ImageBu
7979
}
8080

8181
if options.Squash {
82-
if err := cli.NewVersionError(ctx, "1.25", "squash"); err != nil {
83-
return query, err
84-
}
82+
// TODO(thaJeztah): squash is experimental, and deprecated when using BuildKit?
8583
query.Set("squash", "1")
8684
}
8785

@@ -157,9 +155,6 @@ func (cli *Client) imageBuildOptionsToQuery(ctx context.Context, options ImageBu
157155
query.Set("session", options.SessionID)
158156
}
159157
if options.Platform != "" {
160-
if err := cli.NewVersionError(ctx, "1.32", "platform"); err != nil {
161-
return query, err
162-
}
163158
query.Set("platform", strings.ToLower(options.Platform))
164159
}
165160
if options.BuildID != "" {

client/image_list.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,28 @@ import (
1818
func (cli *Client) ImageList(ctx context.Context, options ImageListOptions) ([]image.Summary, error) {
1919
var images []image.Summary
2020

21-
// Make sure we negotiated (if the client is configured to do so),
22-
// as code below contains API-version specific handling of options.
23-
//
24-
// Normally, version-negotiation (if enabled) would not happen until
25-
// the API request is made.
26-
if err := cli.checkVersion(ctx); err != nil {
27-
return images, err
28-
}
29-
3021
query := url.Values{}
3122

3223
options.Filters.updateURLValues(query)
3324
if options.All {
3425
query.Set("all", "1")
3526
}
36-
if options.SharedSize && versions.GreaterThanOrEqualTo(cli.version, "1.42") {
27+
if options.SharedSize {
3728
query.Set("shared-size", "1")
3829
}
39-
if options.Manifests && versions.GreaterThanOrEqualTo(cli.version, "1.47") {
40-
query.Set("manifests", "1")
30+
if options.Manifests {
31+
// Make sure we negotiated (if the client is configured to do so),
32+
// as code below contains API-version specific handling of options.
33+
//
34+
// Normally, version-negotiation (if enabled) would not happen until
35+
// the API request is made.
36+
if err := cli.checkVersion(ctx); err != nil {
37+
return images, err
38+
}
39+
40+
if versions.GreaterThanOrEqualTo(cli.version, "1.47") {
41+
query.Set("manifests", "1")
42+
}
4143
}
4244

4345
resp, err := cli.get(ctx, "/images/json", query, nil)

client/image_list_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,8 @@ func TestImageListWithSharedSize(t *testing.T) {
123123
options ImageListOptions
124124
sharedSize string // expected value for the shared-size query param, or empty if it should not be set.
125125
}{
126-
{name: "unset after 1.42, no options set", version: "1.42"},
127-
{name: "set after 1.42, if requested", version: "1.42", options: ImageListOptions{SharedSize: true}, sharedSize: "1"},
128-
{name: "unset before 1.42, even if requested", version: "1.41", options: ImageListOptions{SharedSize: true}},
126+
{name: "unset, no options set"},
127+
{name: "set", options: ImageListOptions{SharedSize: true}, sharedSize: "1"},
129128
} {
130129
t.Run(tc.name, func(t *testing.T) {
131130
t.Parallel()

client/network_create.go

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,11 @@ import (
55
"encoding/json"
66

77
"github.com/moby/moby/api/types/network"
8-
"github.com/moby/moby/api/types/versions"
98
)
109

1110
// NetworkCreate creates a new network in the docker host.
1211
func (cli *Client) NetworkCreate(ctx context.Context, name string, options NetworkCreateOptions) (network.CreateResponse, error) {
13-
// Make sure we negotiated (if the client is configured to do so),
14-
// as code below contains API-version specific handling of options.
15-
//
16-
// Normally, version-negotiation (if enabled) would not happen until
17-
// the API request is made.
18-
if err := cli.checkVersion(ctx); err != nil {
19-
return network.CreateResponse{}, err
20-
}
21-
22-
networkCreateRequest := network.CreateRequest{
12+
req := network.CreateRequest{
2313
Name: name,
2414
Driver: options.Driver,
2515
Scope: options.Scope,
@@ -35,27 +25,6 @@ func (cli *Client) NetworkCreate(ctx context.Context, name string, options Netwo
3525
Labels: options.Labels,
3626
}
3727

38-
var req any
39-
if versions.LessThan(cli.version, "1.44") {
40-
// CheckDuplicate is removed in API v1.44, and no longer used by
41-
// daemons supporting that API version (v25.0.0-beta.1 and up)
42-
// regardless of the API version used, but it must be set to true
43-
// when sent to older daemons.
44-
//
45-
// TODO(thaJeztah) remove this once daemon versions v24.0 and lower are no
46-
// longer expected to be used (when Mirantis Container Runtime v23
47-
// is EOL); https://github.com/moby/moby/blob/v2.0.0-beta.0/project/BRANCHES-AND-TAGS.md
48-
req = struct {
49-
network.CreateRequest
50-
CheckDuplicate bool
51-
}{
52-
CreateRequest: networkCreateRequest,
53-
CheckDuplicate: true,
54-
}
55-
} else {
56-
req = networkCreateRequest
57-
}
58-
5928
resp, err := cli.post(ctx, "/networks/create", nil, req, nil)
6029
defer ensureReaderClosed(resp)
6130
if err != nil {

0 commit comments

Comments
 (0)