Skip to content

Commit 01febbc

Browse files
authored
Merge pull request #6551 from thaJeztah/remove_legacy_api_versions
remove API-version compatibility for API < v1.44
2 parents 59d228c + 5ad9145 commit 01febbc

File tree

33 files changed

+150
-540
lines changed

33 files changed

+150
-540
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: 3 additions & 7 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"
@@ -85,7 +84,8 @@ func newCreateCommand(dockerCLI command.Cli) *cobra.Command {
8584
flags.Bool("help", false, "Print usage")
8685

8786
// TODO(thaJeztah): consider adding platform as "image create option" on containerOptions
88-
addPlatformFlag(flags, &options.platform)
87+
flags.StringVar(&options.platform, "platform", os.Getenv("DOCKER_DEFAULT_PLATFORM"), "Set platform if server is multi-platform capable")
88+
_ = flags.SetAnnotation("platform", "version", []string{"1.32"})
8989
_ = cmd.RegisterFlagCompletionFunc("platform", completion.Platforms())
9090

9191
flags.BoolVar(&options.untrusted, "disable-content-trust", !trust.Enabled(), "Skip image verification")
@@ -306,11 +306,7 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c
306306
}
307307

308308
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") {
309+
if options.platform != "" {
314310
p, err := platforms.Parse(options.platform)
315311
if err != nil {
316312
return "", invalidParameter(fmt.Errorf("error parsing specified platform: %w", err))

cli/command/container/opts.go

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,6 @@ type containerOptions struct {
141141
Args []string
142142
}
143143

144-
// addPlatformFlag adds "--platform" to a set of flags for API version 1.32 and
145-
// later, using the value of "DOCKER_DEFAULT_PLATFORM" (if set) as a default.
146-
//
147-
// It should not be used for new uses, which may have a different API version
148-
// requirement.
149-
func addPlatformFlag(flags *pflag.FlagSet, target *string) {
150-
flags.StringVar(target, "platform", os.Getenv("DOCKER_DEFAULT_PLATFORM"), "Set platform if server is multi-platform capable")
151-
_ = flags.SetAnnotation("platform", "version", []string{"1.32"})
152-
}
153-
154144
// addFlags adds all command line flags that will be used by parse to the FlagSet
155145
func addFlags(flags *pflag.FlagSet) *containerOptions {
156146
copts := &containerOptions{
@@ -659,7 +649,6 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
659649
Cmd: runCmd,
660650
Image: copts.Image,
661651
Volumes: volumes,
662-
MacAddress: copts.macAddress,
663652
Entrypoint: entrypoint,
664653
WorkingDir: copts.workingDir,
665654
Labels: opts.ConvertKVStringsToMap(labels),
@@ -730,25 +719,17 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
730719
config.StdinOnce = true
731720
}
732721

733-
networkingConfig := &network.NetworkingConfig{
734-
EndpointsConfig: make(map[string]*network.EndpointSettings),
735-
}
736-
737-
networkingConfig.EndpointsConfig, err = parseNetworkOpts(copts)
722+
epCfg, err := parseNetworkOpts(copts)
738723
if err != nil {
739724
return nil, err
740725
}
741726

742-
// Put the endpoint-specific MacAddress of the "main" network attachment into the container Config for backward
743-
// compatibility with older daemons.
744-
if nw, ok := networkingConfig.EndpointsConfig[hostConfig.NetworkMode.NetworkName()]; ok {
745-
config.MacAddress = nw.MacAddress //nolint:staticcheck // ignore SA1019: field is deprecated, but still used on API < v1.44.
746-
}
747-
748727
return &containerConfig{
749-
Config: config,
750-
HostConfig: hostConfig,
751-
NetworkingConfig: networkingConfig,
728+
Config: config,
729+
HostConfig: hostConfig,
730+
NetworkingConfig: &network.NetworkingConfig{
731+
EndpointsConfig: epCfg,
732+
},
752733
}, nil
753734
}
754735

cli/command/container/opts_test.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,7 @@ func TestParseWithMacAddress(t *testing.T) {
351351
if _, _, _, err := parseRun([]string{invalidMacAddress, "img", "cmd"}); err != nil && err.Error() != "invalidMacAddress is not a valid mac address" {
352352
t.Fatalf("Expected an error with %v mac-address, got %v", invalidMacAddress, err)
353353
}
354-
config, hostConfig, nwConfig := mustParse(t, validMacAddress)
355-
if config.MacAddress != "92:d0:c6:0a:29:33" { //nolint:staticcheck // ignore SA1019: field is deprecated, but still used on API < v1.44.
356-
t.Fatalf("Expected the config to have '92:d0:c6:0a:29:33' as container-wide MacAddress, got '%v'",
357-
config.MacAddress) //nolint:staticcheck // ignore SA1019: field is deprecated, but still used on API < v1.44.
358-
}
354+
_, hostConfig, nwConfig := mustParse(t, validMacAddress)
359355
defaultNw := hostConfig.NetworkMode.NetworkName()
360356
if nwConfig.EndpointsConfig[defaultNw].MacAddress != "92:d0:c6:0a:29:33" {
361357
t.Fatalf("Expected the default endpoint to have the MacAddress '92:d0:c6:0a:29:33' set, got '%v'", nwConfig.EndpointsConfig[defaultNw].MacAddress)
@@ -576,7 +572,6 @@ func TestParseNetworkConfig(t *testing.T) {
576572
name string
577573
flags []string
578574
expected map[string]*networktypes.EndpointSettings
579-
expectedCfg container.Config
580575
expectedHostCfg container.HostConfig
581576
expectedErr string
582577
}{
@@ -680,7 +675,6 @@ func TestParseNetworkConfig(t *testing.T) {
680675
MacAddress: "02:32:1c:23:00:04",
681676
},
682677
},
683-
expectedCfg: container.Config{MacAddress: "02:32:1c:23:00:04"},
684678
expectedHostCfg: container.HostConfig{NetworkMode: "net1"},
685679
},
686680
{
@@ -698,7 +692,6 @@ func TestParseNetworkConfig(t *testing.T) {
698692
MacAddress: "52:0f:f3:dc:50:10",
699693
},
700694
},
701-
expectedCfg: container.Config{MacAddress: "52:0f:f3:dc:50:10"},
702695
expectedHostCfg: container.HostConfig{NetworkMode: "net1"},
703696
},
704697
{
@@ -745,15 +738,14 @@ func TestParseNetworkConfig(t *testing.T) {
745738

746739
for _, tc := range tests {
747740
t.Run(tc.name, func(t *testing.T) {
748-
config, hConfig, nwConfig, err := parseRun(tc.flags)
741+
_, hConfig, nwConfig, err := parseRun(tc.flags)
749742

750743
if tc.expectedErr != "" {
751744
assert.Error(t, err, tc.expectedErr)
752745
return
753746
}
754747

755748
assert.NilError(t, err)
756-
assert.DeepEqual(t, config.MacAddress, tc.expectedCfg.MacAddress) //nolint:staticcheck // ignore SA1019: field is deprecated, but still used on API < v1.44.
757749
assert.DeepEqual(t, hConfig.NetworkMode, tc.expectedHostCfg.NetworkMode)
758750
assert.DeepEqual(t, nwConfig.EndpointsConfig, tc.expected, cmpopts.EquateComparable(netip.Addr{}))
759751
})

cli/command/container/run.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"fmt"
77
"io"
8+
"os"
89
"strings"
910
"syscall"
1011

@@ -70,7 +71,8 @@ func newRunCommand(dockerCLI command.Cli) *cobra.Command {
7071
flags.Bool("help", false, "Print usage")
7172

7273
// TODO(thaJeztah): consider adding platform as "image create option" on containerOptions
73-
addPlatformFlag(flags, &options.platform)
74+
flags.StringVar(&options.platform, "platform", os.Getenv("DOCKER_DEFAULT_PLATFORM"), "Set platform if server is multi-platform capable")
75+
_ = flags.SetAnnotation("platform", "version", []string{"1.32"})
7476
flags.BoolVar(&options.untrusted, "disable-content-trust", !trust.Enabled(), "Skip image verification")
7577
copts = addFlags(flags)
7678

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/image/import.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ func newImportCommand(dockerCLI command.Cli) *cobra.Command {
4848
options.changes = dockeropts.NewListOpts(nil)
4949
flags.VarP(&options.changes, "change", "c", "Apply Dockerfile instruction to the created image")
5050
flags.StringVarP(&options.message, "message", "m", "", "Set commit message for imported image")
51-
addPlatformFlag(flags, &options.platform)
51+
flags.StringVar(&options.platform, "platform", os.Getenv("DOCKER_DEFAULT_PLATFORM"), "Set platform if server is multi-platform capable")
52+
_ = flags.SetAnnotation("platform", "version", []string{"1.32"})
5253
_ = cmd.RegisterFlagCompletionFunc("platform", completion.Platforms())
5354

5455
return cmd

cli/command/image/opts.go

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)