vendor: github.com/moby/moby/api master, moby/client master

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-10-30 09:41:58 +01:00
parent b8b4f54a89
commit 8767904ae8
41 changed files with 369 additions and 204 deletions

View File

@ -135,9 +135,14 @@ func pullImage(ctx context.Context, dockerCli command.Cli, img string, options *
return err
}
var ociPlatforms []ocispec.Platform
if options.platform != "" {
// Already validated.
ociPlatforms = append(ociPlatforms, platforms.MustParse(options.platform))
}
resp, err := dockerCli.Client().ImageCreate(ctx, img, client.ImageCreateOptions{
RegistryAuth: encodedAuth,
Platform: options.platform,
Platforms: ociPlatforms,
})
if err != nil {
return err
@ -213,6 +218,14 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c
namedRef reference.Named
)
// TODO(thaJeztah): add a platform option-type / flag-type.
if options.platform != "" {
_, err = platforms.Parse(options.platform)
if err != nil {
return "", err
}
}
containerIDFile, err := newCIDFile(hostConfig.ContainerIDFile)
if err != nil {
return "", err

View File

@ -885,10 +885,11 @@ func parseNetworkAttachmentOpt(ep opts.NetworkAttachmentOpts) (*network.Endpoint
}
}
if ep.MacAddress != "" {
if _, err := net.ParseMAC(strings.TrimSpace(ep.MacAddress)); err != nil {
ma, err := net.ParseMAC(strings.TrimSpace(ep.MacAddress))
if err != nil {
return nil, fmt.Errorf("%s is not a valid mac address", ep.MacAddress)
}
epConfig.MacAddress = ep.MacAddress
epConfig.MacAddress = network.HardwareAddr(ma)
}
return epConfig, nil
}

View File

@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"io"
"net"
"net/netip"
"os"
"runtime"
@ -20,6 +21,14 @@ import (
"gotest.tools/v3/skip"
)
func mustParseMAC(s string) networktypes.HardwareAddr {
mac, err := net.ParseMAC(s)
if err != nil {
panic(err)
}
return networktypes.HardwareAddr(mac)
}
func TestValidateAttach(t *testing.T) {
valid := []string{
"stdin",
@ -353,7 +362,7 @@ func TestParseWithMacAddress(t *testing.T) {
}
_, hostConfig, nwConfig := mustParse(t, validMacAddress)
defaultNw := hostConfig.NetworkMode.NetworkName()
if nwConfig.EndpointsConfig[defaultNw].MacAddress != "92:d0:c6:0a:29:33" {
if nwConfig.EndpointsConfig[defaultNw].MacAddress.String() != "92:d0:c6:0a:29:33" {
t.Fatalf("Expected the default endpoint to have the MacAddress '92:d0:c6:0a:29:33' set, got '%v'", nwConfig.EndpointsConfig[defaultNw].MacAddress)
}
}
@ -650,7 +659,7 @@ func TestParseNetworkConfig(t *testing.T) {
Aliases: []string{"web3"},
},
"net4": {
MacAddress: "02:32:1c:23:00:04",
MacAddress: mustParseMAC("02:32:1c:23:00:04"),
IPAMConfig: &networktypes.EndpointIPAMConfig{
LinkLocalIPs: []netip.Addr{netip.MustParseAddr("169.254.169.254")},
},
@ -672,7 +681,7 @@ func TestParseNetworkConfig(t *testing.T) {
IPv6Address: netip.MustParseAddr("2001:db8::8822"),
},
Aliases: []string{"web1", "web2"},
MacAddress: "02:32:1c:23:00:04",
MacAddress: mustParseMAC("02:32:1c:23:00:04"),
},
},
expectedHostCfg: container.HostConfig{NetworkMode: "net1"},
@ -689,7 +698,7 @@ func TestParseNetworkConfig(t *testing.T) {
expected: map[string]*networktypes.EndpointSettings{
"net1": {
Aliases: []string{"foobar"},
MacAddress: "52:0f:f3:dc:50:10",
MacAddress: mustParseMAC("52:0f:f3:dc:50:10"),
},
},
expectedHostCfg: container.HostConfig{NetworkMode: "net1"},