Skip to content

Commit a51c3be

Browse files
committed
cli/command/container: rm use of deprecated MacAddress field
This field is no longer in use since API v1.44. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent a4ffe62 commit a51c3be

File tree

2 files changed

+8
-25
lines changed

2 files changed

+8
-25
lines changed

cli/command/container/opts.go

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,6 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
659659
Cmd: runCmd,
660660
Image: copts.Image,
661661
Volumes: volumes,
662-
MacAddress: copts.macAddress,
663662
Entrypoint: entrypoint,
664663
WorkingDir: copts.workingDir,
665664
Labels: opts.ConvertKVStringsToMap(labels),
@@ -730,25 +729,17 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
730729
config.StdinOnce = true
731730
}
732731

733-
networkingConfig := &network.NetworkingConfig{
734-
EndpointsConfig: make(map[string]*network.EndpointSettings),
735-
}
736-
737-
networkingConfig.EndpointsConfig, err = parseNetworkOpts(copts)
732+
epCfg, err := parseNetworkOpts(copts)
738733
if err != nil {
739734
return nil, err
740735
}
741736

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-
748737
return &containerConfig{
749-
Config: config,
750-
HostConfig: hostConfig,
751-
NetworkingConfig: networkingConfig,
738+
Config: config,
739+
HostConfig: hostConfig,
740+
NetworkingConfig: &network.NetworkingConfig{
741+
EndpointsConfig: epCfg,
742+
},
752743
}, nil
753744
}
754745

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

0 commit comments

Comments
 (0)