Skip to content

Commit a4ffe62

Browse files
committed
remove API-version compatibility for API < v1.44
Support for API versions < v1.44 was removed in the client in [moby@96b29f5] and [moby@7652f38], so we can remove fallback-code from the CLI as well, as it won't be able to use those versions. [moby@96b29f5]: moby/moby@96b29f5 [moby@7652f38]: moby/moby@7652f38 Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent a3e9545 commit a4ffe62

File tree

21 files changed

+48
-227
lines changed

21 files changed

+48
-227
lines changed

cli/command/builder/prune.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"github.com/docker/cli/internal/prompt"
1313
"github.com/docker/cli/opts"
1414
"github.com/docker/go-units"
15-
"github.com/moby/moby/api/types/versions"
1615
"github.com/moby/moby/client"
1716
"github.com/spf13/cobra"
1817
)
@@ -112,17 +111,9 @@ type cancelledErr struct{ error }
112111

113112
func (cancelledErr) Cancelled() {}
114113

115-
type errNotImplemented struct{ error }
116-
117-
func (errNotImplemented) NotImplemented() {}
118-
119114
// pruneFn prunes the build cache for use in "docker system prune" and
120115
// returns the amount of space reclaimed and a detailed output string.
121116
func pruneFn(ctx context.Context, dockerCLI command.Cli, options pruner.PruneOptions) (uint64, string, error) {
122-
if ver := dockerCLI.Client().ClientVersion(); ver != "" && versions.LessThan(ver, "1.31") {
123-
// Not supported on older daemons.
124-
return 0, "", errNotImplemented{errors.New("builder prune requires API version 1.31 or greater")}
125-
}
126117
if !options.Confirmed {
127118
// Dry-run: perform validation and produce confirmation before pruning.
128119
var confirmMsg string

cli/command/cli_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func TestInitializeFromClient(t *testing.T) {
164164
{
165165
doc: "successful ping",
166166
pingFunc: func() (types.Ping, error) {
167-
return types.Ping{Experimental: true, OSType: "linux", APIVersion: "v1.30"}, nil
167+
return types.Ping{Experimental: true, OSType: "linux", APIVersion: "v1.44"}, nil
168168
},
169169
expectedServer: ServerInfo{HasExperimental: true, OSType: "linux"},
170170
negotiated: true,
@@ -179,7 +179,7 @@ func TestInitializeFromClient(t *testing.T) {
179179
{
180180
doc: "failed ping, with API version",
181181
pingFunc: func() (types.Ping, error) {
182-
return types.Ping{APIVersion: "v1.33"}, errors.New("failed")
182+
return types.Ping{APIVersion: "v1.44"}, errors.New("failed")
183183
},
184184
expectedServer: ServerInfo{HasExperimental: true},
185185
negotiated: true,

cli/command/container/create.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"github.com/docker/cli/internal/jsonstream"
2626
"github.com/docker/cli/opts"
2727
"github.com/moby/moby/api/types/mount"
28-
"github.com/moby/moby/api/types/versions"
2928
"github.com/moby/moby/client"
3029
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
3130
"github.com/spf13/cobra"
@@ -306,11 +305,7 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c
306305
}
307306

308307
var platform *ocispec.Platform
309-
// Engine API version 1.41 first introduced the option to specify platform on
310-
// create. It will produce an error if you try to set a platform on older API
311-
// versions, so check the API version here to maintain backwards
312-
// compatibility for CLI users.
313-
if options.platform != "" && versions.GreaterThanOrEqualTo(dockerCli.Client().ClientVersion(), "1.41") {
308+
if options.platform != "" {
314309
p, err := platforms.Parse(options.platform)
315310
if err != nil {
316311
return "", invalidParameter(fmt.Errorf("error parsing specified platform: %w", err))

cli/command/container/run_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func TestRunLabel(t *testing.T) {
6161
ID: "id",
6262
}, nil
6363
},
64-
Version: "1.36",
64+
Version: client.MaxAPIVersion,
6565
})
6666
cmd := newRunCommand(fakeCLI)
6767
cmd.SetArgs([]string{"--detach=true", "--label", "foo", "busybox"})
@@ -103,8 +103,8 @@ func TestRunAttach(t *testing.T) {
103103
return responseChan, errChan
104104
},
105105
// use new (non-legacy) wait API
106-
// see: 38591f20d07795aaef45d400df89ca12f29c603b
107-
Version: "1.30",
106+
// see: https://github.com/docker/cli/commit/38591f20d07795aaef45d400df89ca12f29c603b
107+
Version: client.MaxAPIVersion,
108108
}, func(fc *test.FakeCli) {
109109
fc.SetOut(streams.NewOut(tty))
110110
fc.SetIn(streams.NewIn(tty))
@@ -180,8 +180,8 @@ func TestRunAttachTermination(t *testing.T) {
180180
return responseChan, errChan
181181
},
182182
// use new (non-legacy) wait API
183-
// see: 38591f20d07795aaef45d400df89ca12f29c603b
184-
Version: "1.30",
183+
// see: https://github.com/docker/cli/commit/38591f20d07795aaef45d400df89ca12f29c603b
184+
Version: client.MaxAPIVersion,
185185
}, func(fc *test.FakeCli) {
186186
fc.SetOut(streams.NewOut(tty))
187187
fc.SetIn(streams.NewIn(tty))
@@ -262,7 +262,7 @@ func TestRunPullTermination(t *testing.T) {
262262
attachCh <- struct{}{}
263263
return respReader, nil
264264
},
265-
Version: "1.30",
265+
Version: client.MaxAPIVersion,
266266
})
267267

268268
cmd := newRunCommand(fakeCLI)

cli/command/formatter/buildcache.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,6 @@ func (c *buildCacheContext) Parent() string {
126126
var parent string
127127
if len(c.v.Parents) > 0 {
128128
parent = strings.Join(c.v.Parents, ", ")
129-
} else {
130-
parent = c.v.Parent //nolint:staticcheck // Ignore SA1019: Field was deprecated in API v1.42, but kept for backward compatibility
131129
}
132130
if c.trunc {
133131
return TruncateID(parent)

cli/command/service/create.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/docker/cli/cli/command/completion"
1010
cliopts "github.com/docker/cli/opts"
1111
"github.com/moby/moby/api/types/swarm"
12-
"github.com/moby/moby/api/types/versions"
1312
"github.com/moby/moby/client"
1413
"github.com/spf13/cobra"
1514
"github.com/spf13/pflag"
@@ -132,9 +131,7 @@ func runCreate(ctx context.Context, dockerCLI command.Cli, flags *pflag.FlagSet,
132131
}
133132

134133
// query registry if flag disabling it was not set
135-
if !opts.noResolveImage && versions.GreaterThanOrEqualTo(apiClient.ClientVersion(), "1.30") {
136-
createOpts.QueryRegistry = true
137-
}
134+
createOpts.QueryRegistry = !opts.noResolveImage
138135

139136
response, err := apiClient.ServiceCreate(ctx, service, createOpts)
140137
if err != nil {
@@ -147,7 +144,7 @@ func runCreate(ctx context.Context, dockerCLI command.Cli, flags *pflag.FlagSet,
147144

148145
_, _ = fmt.Fprintln(dockerCLI.Out(), response.ID)
149146

150-
if opts.detach || versions.LessThan(apiClient.ClientVersion(), "1.29") {
147+
if opts.detach {
151148
return nil
152149
}
153150

cli/command/service/list_test.go

Lines changed: 4 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/docker/cli/internal/test"
1111
"github.com/docker/cli/internal/test/builders"
1212
"github.com/moby/moby/api/types/swarm"
13-
"github.com/moby/moby/api/types/versions"
1413
"github.com/moby/moby/client"
1514
"gotest.tools/v3/assert"
1615
is "gotest.tools/v3/assert/cmp"
@@ -63,59 +62,12 @@ func TestServiceListServiceStatus(t *testing.T) {
6362
cluster: &cluster{}, // force an empty cluster
6463
expected: []listResponse{},
6564
},
66-
{
67-
// Services are running, but no active nodes were found. On API v1.40
68-
// and below, this will cause looking up the "running" tasks to fail,
69-
// as well as looking up "desired" tasks for global services.
70-
doc: "API v1.40 no active nodes",
71-
opts: clusterOpts{
72-
apiVersion: "1.40",
73-
activeNodes: 0,
74-
runningTasks: 2,
75-
desiredTasks: 4,
76-
},
77-
expected: []listResponse{
78-
{ID: "replicated", Replicas: "0/4"},
79-
{ID: "global", Replicas: "0/0"},
80-
{ID: "none-id", Replicas: "0/0"},
81-
},
82-
},
83-
{
84-
doc: "API v1.40 3 active nodes, 1 task running",
85-
opts: clusterOpts{
86-
apiVersion: "1.40",
87-
activeNodes: 3,
88-
runningTasks: 1,
89-
desiredTasks: 2,
90-
},
91-
expected: []listResponse{
92-
{ID: "replicated", Replicas: "1/2"},
93-
{ID: "global", Replicas: "1/3"},
94-
{ID: "none-id", Replicas: "0/0"},
95-
},
96-
},
97-
{
98-
doc: "API v1.40 3 active nodes, all tasks running",
99-
opts: clusterOpts{
100-
apiVersion: "1.40",
101-
activeNodes: 3,
102-
runningTasks: 3,
103-
desiredTasks: 3,
104-
},
105-
expected: []listResponse{
106-
{ID: "replicated", Replicas: "3/3"},
107-
{ID: "global", Replicas: "3/3"},
108-
{ID: "none-id", Replicas: "0/0"},
109-
},
110-
},
111-
11265
{
11366
// Services are running, but no active nodes were found. On API v1.41
11467
// and up, the ServiceStatus is sent by the daemon, so this should not
11568
// affect the results.
116-
doc: "API v1.41 no active nodes",
69+
doc: "no active nodes",
11770
opts: clusterOpts{
118-
apiVersion: "1.41",
11971
activeNodes: 0,
12072
runningTasks: 2,
12173
desiredTasks: 4,
@@ -127,9 +79,8 @@ func TestServiceListServiceStatus(t *testing.T) {
12779
},
12880
},
12981
{
130-
doc: "API v1.41 3 active nodes, 1 task running",
82+
doc: "active nodes, 1 task running",
13183
opts: clusterOpts{
132-
apiVersion: "1.41",
13384
activeNodes: 3,
13485
runningTasks: 1,
13586
desiredTasks: 2,
@@ -141,9 +92,8 @@ func TestServiceListServiceStatus(t *testing.T) {
14192
},
14293
},
14394
{
144-
doc: "API v1.41 3 active nodes, all tasks running",
95+
doc: "active nodes, all tasks running",
14596
opts: clusterOpts{
146-
apiVersion: "1.41",
14797
activeNodes: 3,
14898
runningTasks: 3,
14999
desiredTasks: 3,
@@ -174,7 +124,7 @@ func TestServiceListServiceStatus(t *testing.T) {
174124
}
175125
cli := test.NewFakeCli(&fakeClient{
176126
serviceListFunc: func(ctx context.Context, options client.ServiceListOptions) ([]swarm.Service, error) {
177-
if !options.Status || versions.LessThan(tc.opts.apiVersion, "1.41") {
127+
if !options.Status {
178128
// Don't return "ServiceStatus" if not requested, or on older API versions
179129
for i := range tc.cluster.services {
180130
tc.cluster.services[i].ServiceStatus = nil
@@ -214,7 +164,6 @@ func TestServiceListServiceStatus(t *testing.T) {
214164
}
215165

216166
type clusterOpts struct {
217-
apiVersion string
218167
activeNodes uint64
219168
desiredTasks uint64
220169
runningTasks uint64

cli/command/service/rollback.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66

77
"github.com/docker/cli/cli"
88
"github.com/docker/cli/cli/command"
9-
"github.com/moby/moby/api/types/versions"
109
"github.com/moby/moby/client"
1110
"github.com/spf13/cobra"
1211
)
@@ -54,7 +53,7 @@ func runRollback(ctx context.Context, dockerCLI command.Cli, options *serviceOpt
5453

5554
_, _ = fmt.Fprintln(dockerCLI.Out(), serviceID)
5655

57-
if options.detach || versions.LessThan(apiClient.ClientVersion(), "1.29") {
56+
if options.detach {
5857
return nil
5958
}
6059

cli/command/service/rollback_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ func TestRollback(t *testing.T) {
4848
})
4949
cmd := newRollbackCommand(cli)
5050
cmd.SetArgs(tc.args)
51-
cmd.Flags().Set("quiet", "true")
51+
assert.NilError(t, cmd.Flags().Set("quiet", "true"))
52+
assert.NilError(t, cmd.Flags().Set("detach", "true"))
5253
cmd.SetOut(io.Discard)
5354
assert.NilError(t, cmd.Execute())
5455
assert.Check(t, is.Equal(strings.TrimSpace(cli.ErrBuffer().String()), tc.expectedDockerCliErr))

cli/command/service/scale.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99

1010
"github.com/docker/cli/cli"
1111
"github.com/docker/cli/cli/command"
12-
"github.com/moby/moby/api/types/versions"
1312
"github.com/moby/moby/client"
1413
"github.com/spf13/cobra"
1514
)
@@ -83,7 +82,7 @@ func runScale(ctx context.Context, dockerCLI command.Cli, options *scaleOptions,
8382
serviceIDs = append(serviceIDs, serviceID)
8483
}
8584

86-
if len(serviceIDs) > 0 && !options.detach && versions.GreaterThanOrEqualTo(dockerCLI.Client().ClientVersion(), "1.29") {
85+
if len(serviceIDs) > 0 && !options.detach {
8786
for _, serviceID := range serviceIDs {
8887
if err := WaitOnService(ctx, dockerCLI, serviceID, false); err != nil {
8988
errs = append(errs, fmt.Errorf("%s: %v", serviceID, err))

0 commit comments

Comments
 (0)