Skip to content

Commit eb88048

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 02f6cf5 commit eb88048

File tree

13 files changed

+22
-101
lines changed

13 files changed

+22
-101
lines changed

cli/command/builder/prune.go

Lines changed: 0 additions & 5 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
)
@@ -119,10 +118,6 @@ func (errNotImplemented) NotImplemented() {}
119118
// pruneFn prunes the build cache for use in "docker system prune" and
120119
// returns the amount of space reclaimed and a detailed output string.
121120
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-
}
126121
if !options.Confirmed {
127122
// Dry-run: perform validation and produce confirmation before pruning.
128123
var confirmMsg string

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/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: 1 addition & 2 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"
@@ -174,7 +173,7 @@ func TestServiceListServiceStatus(t *testing.T) {
174173
}
175174
cli := test.NewFakeCli(&fakeClient{
176175
serviceListFunc: func(ctx context.Context, options client.ServiceListOptions) ([]swarm.Service, error) {
177-
if !options.Status || versions.LessThan(tc.opts.apiVersion, "1.41") {
176+
if !options.Status {
178177
// Don't return "ServiceStatus" if not requested, or on older API versions
179178
for i := range tc.cluster.services {
180179
tc.cluster.services[i].ServiceStatus = nil

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/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))

cli/command/service/update.go

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"github.com/moby/moby/api/types/mount"
2323
"github.com/moby/moby/api/types/network"
2424
"github.com/moby/moby/api/types/swarm"
25-
"github.com/moby/moby/api/types/versions"
2625
"github.com/moby/moby/client"
2726
"github.com/moby/swarmkit/v2/api/defaults"
2827
"github.com/spf13/cobra"
@@ -165,14 +164,6 @@ func runUpdate(ctx context.Context, dockerCLI command.Cli, flags *pflag.FlagSet,
165164
return err
166165
}
167166

168-
// There are two ways to do user-requested rollback. The old way is
169-
// client-side, but with a sufficiently recent daemon we prefer
170-
// server-side, because it will honor the rollback parameters.
171-
var (
172-
clientSideRollback bool
173-
serverSideRollback bool
174-
)
175-
176167
spec := &service.Spec
177168
if rollback {
178169
// Rollback can't be combined with other flags.
@@ -188,20 +179,10 @@ func runUpdate(ctx context.Context, dockerCLI command.Cli, flags *pflag.FlagSet,
188179
if otherFlagsPassed {
189180
return errors.New("other flags may not be combined with --rollback")
190181
}
191-
192-
if versions.LessThan(apiClient.ClientVersion(), "1.28") {
193-
clientSideRollback = true
194-
spec = service.PreviousSpec
195-
if spec == nil {
196-
return errors.New("service does not have a previous specification to roll back to")
197-
}
198-
} else {
199-
serverSideRollback = true
200-
}
201182
}
202183

203184
updateOpts := client.ServiceUpdateOptions{}
204-
if serverSideRollback {
185+
if rollback {
205186
updateOpts.Rollback = "previous"
206187
}
207188

@@ -214,9 +195,7 @@ func runUpdate(ctx context.Context, dockerCLI command.Cli, flags *pflag.FlagSet,
214195
if err := resolveServiceImageDigestContentTrust(dockerCLI, spec); err != nil {
215196
return err
216197
}
217-
if !options.noResolveImage && versions.GreaterThanOrEqualTo(apiClient.ClientVersion(), "1.30") {
218-
updateOpts.QueryRegistry = true
219-
}
198+
updateOpts.QueryRegistry = !options.noResolveImage
220199
}
221200

222201
updatedSecrets, err := getUpdatedSecrets(ctx, apiClient, flags, spec.TaskTemplate.ContainerSpec.Secrets)
@@ -243,8 +222,7 @@ func runUpdate(ctx context.Context, dockerCLI command.Cli, flags *pflag.FlagSet,
243222
if err != nil {
244223
return err
245224
}
246-
switch {
247-
case sendAuth:
225+
if sendAuth {
248226
// Retrieve encoded auth token from the image reference
249227
// This would be the old image if it didn't change in this update
250228
image := spec.TaskTemplate.ContainerSpec.Image
@@ -253,9 +231,7 @@ func runUpdate(ctx context.Context, dockerCLI command.Cli, flags *pflag.FlagSet,
253231
return err
254232
}
255233
updateOpts.EncodedRegistryAuth = encodedAuth
256-
case clientSideRollback:
257-
updateOpts.RegistryAuthFrom = swarm.RegistryAuthFromPreviousSpec
258-
default:
234+
} else {
259235
updateOpts.RegistryAuthFrom = swarm.RegistryAuthFromSpec
260236
}
261237

@@ -270,7 +246,7 @@ func runUpdate(ctx context.Context, dockerCLI command.Cli, flags *pflag.FlagSet,
270246

271247
_, _ = fmt.Fprintln(dockerCLI.Out(), serviceID)
272248

273-
if options.detach || versions.LessThan(apiClient.ClientVersion(), "1.29") {
249+
if options.detach {
274250
return nil
275251
}
276252

cli/command/stack/deploy.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/docker/cli/cli/compose/convert"
1111
composetypes "github.com/docker/cli/cli/compose/types"
1212
"github.com/moby/moby/api/types/swarm"
13-
"github.com/moby/moby/api/types/versions"
1413
"github.com/spf13/cobra"
1514
"github.com/spf13/pflag"
1615
)
@@ -81,13 +80,6 @@ func runDeploy(ctx context.Context, dockerCLI command.Cli, flags *pflag.FlagSet,
8180
return fmt.Errorf("invalid option %s for flag --resolve-image", opts.resolveImage)
8281
}
8382

84-
// client side image resolution should not be done when the supported
85-
// server version is older than 1.30
86-
if versions.LessThan(dockerCLI.Client().ClientVersion(), "1.30") {
87-
// TODO(thaJeztah): should this error if "opts.ResolveImage" is already other (unsupported) values?
88-
opts.resolveImage = resolveImageNever
89-
}
90-
9183
if opts.detach && !flags.Changed("detach") {
9284
_, _ = fmt.Fprintln(dockerCLI.Err(), "Since --detach=false was not specified, tasks will be created in the background.\n"+
9385
"In a future release, --detach=false will become the default.")

cli/command/stack/remove.go

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/docker/cli/cli/command"
1111
"github.com/moby/moby/api/types/network"
1212
"github.com/moby/moby/api/types/swarm"
13-
"github.com/moby/moby/api/types/versions"
1413
"github.com/moby/moby/client"
1514
"github.com/spf13/cobra"
1615
)
@@ -61,20 +60,14 @@ func runRemove(ctx context.Context, dockerCli command.Cli, opts removeOptions) e
6160
return err
6261
}
6362

64-
var secrets []swarm.Secret
65-
if versions.GreaterThanOrEqualTo(apiClient.ClientVersion(), "1.25") {
66-
secrets, err = getStackSecrets(ctx, apiClient, namespace)
67-
if err != nil {
68-
return err
69-
}
63+
secrets, err := getStackSecrets(ctx, apiClient, namespace)
64+
if err != nil {
65+
return err
7066
}
7167

72-
var configs []swarm.Config
73-
if versions.GreaterThanOrEqualTo(apiClient.ClientVersion(), "1.30") {
74-
configs, err = getStackConfigs(ctx, apiClient, namespace)
75-
if err != nil {
76-
return err
77-
}
68+
configs, err := getStackConfigs(ctx, apiClient, namespace)
69+
if err != nil {
70+
return err
7871
}
7972

8073
if len(services)+len(networks)+len(secrets)+len(configs) == 0 {

cli/command/volume/prune.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/docker/cli/internal/prompt"
1212
"github.com/docker/cli/opts"
1313
"github.com/docker/go-units"
14-
"github.com/moby/moby/api/types/versions"
1514
"github.com/spf13/cobra"
1615
)
1716

@@ -72,16 +71,11 @@ func runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions)
7271
pruneFilters := command.PruneFilters(dockerCli, options.filter.Value())
7372

7473
warning := unusedVolumesWarning
75-
if versions.GreaterThanOrEqualTo(dockerCli.CurrentVersion(), "1.42") {
76-
if options.all {
77-
if _, ok := pruneFilters["all"]; ok {
78-
return 0, "", invalidParamErr{errors.New("conflicting options: cannot specify both --all and --filter all=1")}
79-
}
80-
pruneFilters.Add("all", "true")
81-
warning = allVolumesWarning
74+
if options.all {
75+
if _, ok := pruneFilters["all"]; ok {
76+
return 0, "", invalidParamErr{errors.New("conflicting options: cannot specify both --all and --filter all=1")}
8277
}
83-
} else {
84-
// API < v1.42 removes all volumes (anonymous and named) by default.
78+
pruneFilters.Add("all", "true")
8579
warning = allVolumesWarning
8680
}
8781
if !options.force {

0 commit comments

Comments
 (0)