Skip to content

Commit bb014d8

Browse files
committed
vendor: github.com/moby/moby/api, github.com/moby/moby/client master
full diff: moby/moby@4ca8aed...ad72822 Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent b1ea4fe commit bb014d8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1083
-728
lines changed

cli/command/builder/client_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@ package builder
33
import (
44
"context"
55

6-
"github.com/moby/moby/api/types/build"
76
"github.com/moby/moby/client"
87
)
98

109
type fakeClient struct {
1110
client.Client
12-
builderPruneFunc func(ctx context.Context, opts client.BuildCachePruneOptions) (*build.CachePruneReport, error)
11+
builderPruneFunc func(ctx context.Context, opts client.BuildCachePruneOptions) (client.BuildCachePruneResult, error)
1312
}
1413

15-
func (c *fakeClient) BuildCachePrune(ctx context.Context, opts client.BuildCachePruneOptions) (*build.CachePruneReport, error) {
14+
func (c *fakeClient) BuildCachePrune(ctx context.Context, opts client.BuildCachePruneOptions) (client.BuildCachePruneResult, error) {
1615
if c.builderPruneFunc != nil {
1716
return c.builderPruneFunc(ctx, opts)
1817
}
19-
return nil, nil
18+
return client.BuildCachePruneResult{}, nil
2019
}

cli/command/builder/prune.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,15 @@ func runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions)
8787
}
8888
}
8989

90-
report, err := dockerCli.Client().BuildCachePrune(ctx, client.BuildCachePruneOptions{
90+
resp, err := dockerCli.Client().BuildCachePrune(ctx, client.BuildCachePruneOptions{
9191
All: options.all,
9292
ReservedSpace: options.reservedSpace.Value(),
9393
Filters: pruneFilters,
9494
})
9595
if err != nil {
9696
return 0, "", err
9797
}
98-
98+
report := resp.Report
9999
if len(report.CachesDeleted) > 0 {
100100
var sb strings.Builder
101101
sb.WriteString("Deleted build cache objects:\n")

cli/command/builder/prune_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"testing"
88

99
"github.com/docker/cli/internal/test"
10-
"github.com/moby/moby/api/types/build"
1110
"github.com/moby/moby/client"
1211
)
1312

@@ -16,8 +15,8 @@ func TestBuilderPromptTermination(t *testing.T) {
1615
t.Cleanup(cancel)
1716

1817
cli := test.NewFakeCli(&fakeClient{
19-
builderPruneFunc: func(ctx context.Context, opts client.BuildCachePruneOptions) (*build.CachePruneReport, error) {
20-
return nil, errors.New("fakeClient builderPruneFunc should not be called")
18+
builderPruneFunc: func(ctx context.Context, opts client.BuildCachePruneOptions) (client.BuildCachePruneResult, error) {
19+
return client.BuildCachePruneResult{}, errors.New("fakeClient builderPruneFunc should not be called")
2120
},
2221
})
2322
cmd := newPruneCommand(cli)

cli/command/container/opts.go

Lines changed: 61 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8+
"net/netip"
89
"os"
910
"path"
1011
"path/filepath"
@@ -425,15 +426,46 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
425426
entrypoint = []string{""}
426427
}
427428

429+
// TODO(thaJeztah): remove uses of go-connections/nat here.
428430
convertedOpts, err := convertToStandardNotation(copts.publish.GetSlice())
429431
if err != nil {
430432
return nil, err
431433
}
432434

433-
ports, portBindings, err := nat.ParsePortSpecs(convertedOpts)
435+
ports, natPortBindings, err := nat.ParsePortSpecs(convertedOpts)
434436
if err != nil {
435437
return nil, err
436438
}
439+
portBindings := network.PortMap{}
440+
for port, bindings := range natPortBindings {
441+
p, err := network.ParsePort(string(port))
442+
if err != nil {
443+
return nil, err
444+
}
445+
portBindings[p] = []network.PortBinding{}
446+
for _, b := range bindings {
447+
var hostIP netip.Addr
448+
if b.HostIP != "" {
449+
hostIP, err = netip.ParseAddr(b.HostIP)
450+
if err != nil {
451+
return nil, err
452+
}
453+
}
454+
portBindings[p] = append(portBindings[p], network.PortBinding{
455+
HostIP: hostIP,
456+
HostPort: b.HostPort,
457+
})
458+
}
459+
}
460+
461+
exposedPorts := network.PortSet{}
462+
for port := range ports {
463+
p, err := network.ParsePort(string(port))
464+
if err != nil {
465+
return nil, err
466+
}
467+
exposedPorts[p] = struct{}{}
468+
}
437469

438470
// Merge in exposed ports to the map of published ports
439471
for _, e := range copts.expose.GetSlice() {
@@ -625,7 +657,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
625657
config := &container.Config{
626658
Hostname: copts.hostname,
627659
Domainname: copts.domainname,
628-
ExposedPorts: ports,
660+
ExposedPorts: exposedPorts,
629661
User: copts.user,
630662
Tty: copts.tty,
631663
OpenStdin: copts.stdin,
@@ -661,7 +693,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
661693
// but pre created containers can still have those nil values.
662694
// See https://github.com/docker/docker/pull/17779
663695
// for a more detailed explanation on why we don't want that.
664-
DNS: copts.dns.GetAllOrEmpty(),
696+
DNS: toNetipAddrSlice(copts.dns.GetAllOrEmpty()),
665697
DNSSearch: copts.dnsSearch.GetAllOrEmpty(),
666698
DNSOptions: copts.dnsOptions.GetAllOrEmpty(),
667699
ExtraHosts: copts.extraHosts.GetSlice(),
@@ -804,10 +836,10 @@ func applyContainerOptions(n *opts.NetworkAttachmentOpts, copts *containerOption
804836
if len(n.Links) > 0 && copts.links.Len() > 0 {
805837
return invalidParameter(errors.New("conflicting options: cannot specify both --link and per-network links"))
806838
}
807-
if n.IPv4Address != "" && copts.ipv4Address != "" {
839+
if n.IPv4Address.IsValid() && copts.ipv4Address != "" {
808840
return invalidParameter(errors.New("conflicting options: cannot specify both --ip and per-network IPv4 address"))
809841
}
810-
if n.IPv6Address != "" && copts.ipv6Address != "" {
842+
if n.IPv6Address.IsValid() && copts.ipv6Address != "" {
811843
return invalidParameter(errors.New("conflicting options: cannot specify both --ip6 and per-network IPv6 address"))
812844
}
813845
if n.MacAddress != "" && copts.macAddress != "" {
@@ -827,17 +859,24 @@ func applyContainerOptions(n *opts.NetworkAttachmentOpts, copts *containerOption
827859
copy(n.Links, copts.links.GetSlice())
828860
}
829861
if copts.ipv4Address != "" {
830-
n.IPv4Address = copts.ipv4Address
862+
var err error
863+
n.IPv4Address, err = netip.ParseAddr(copts.ipv4Address)
864+
if err != nil {
865+
return err
866+
}
831867
}
832868
if copts.ipv6Address != "" {
833-
n.IPv6Address = copts.ipv6Address
869+
var err error
870+
n.IPv6Address, err = netip.ParseAddr(copts.ipv6Address)
871+
if err != nil {
872+
return err
873+
}
834874
}
835875
if copts.macAddress != "" {
836876
n.MacAddress = copts.macAddress
837877
}
838878
if copts.linkLocalIPs.Len() > 0 {
839-
n.LinkLocalIPs = make([]string, copts.linkLocalIPs.Len())
840-
copy(n.LinkLocalIPs, copts.linkLocalIPs.GetSlice())
879+
n.LinkLocalIPs = toNetipAddrSlice(copts.linkLocalIPs.GetSlice())
841880
}
842881
return nil
843882
}
@@ -866,7 +905,7 @@ func parseNetworkAttachmentOpt(ep opts.NetworkAttachmentOpts) (*network.Endpoint
866905
if len(ep.Links) > 0 {
867906
epConfig.Links = ep.Links
868907
}
869-
if ep.IPv4Address != "" || ep.IPv6Address != "" || len(ep.LinkLocalIPs) > 0 {
908+
if ep.IPv4Address.IsValid() || ep.IPv6Address.IsValid() || len(ep.LinkLocalIPs) > 0 {
870909
epConfig.IPAMConfig = &network.EndpointIPAMConfig{
871910
IPv4Address: ep.IPv4Address,
872911
IPv6Address: ep.IPv6Address,
@@ -1130,3 +1169,15 @@ func validateAttach(val string) (string, error) {
11301169
}
11311170
return val, errors.New("valid streams are STDIN, STDOUT and STDERR")
11321171
}
1172+
1173+
func toNetipAddrSlice(ips []string) []netip.Addr {
1174+
netips := make([]netip.Addr, 0, len(ips))
1175+
for _, ip := range ips {
1176+
addr, err := netip.ParseAddr(ip)
1177+
if err != nil {
1178+
continue
1179+
}
1180+
netips = append(netips, addr)
1181+
}
1182+
return netips
1183+
}

cli/command/container/opts_test.go

Lines changed: 49 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import (
44
"errors"
55
"fmt"
66
"io"
7+
"net/netip"
78
"os"
89
"runtime"
910
"strings"
1011
"testing"
1112
"time"
1213

14+
"github.com/google/go-cmp/cmp/cmpopts"
1315
"github.com/moby/moby/api/types/container"
1416
networktypes "github.com/moby/moby/api/types/network"
1517
"github.com/spf13/pflag"
@@ -438,46 +440,52 @@ func TestParseWithExpose(t *testing.T) {
438440
"8080-NaN/tcp": `invalid range format for --expose: 8080-NaN/tcp, error: strconv.ParseUint: parsing "NaN": invalid syntax`,
439441
"1234567890-8080/tcp": `invalid range format for --expose: 1234567890-8080/tcp, error: strconv.ParseUint: parsing "1234567890": value out of range`,
440442
}
441-
valids := map[string][]container.PortRangeProto{
442-
"8080/tcp": {"8080/tcp"},
443-
"8080/udp": {"8080/udp"},
444-
"8080/ncp": {"8080/ncp"},
445-
"8080-8080/udp": {"8080/udp"},
446-
"8080-8082/tcp": {"8080/tcp", "8081/tcp", "8082/tcp"},
443+
valids := map[string][]networktypes.Port{
444+
"8080/tcp": {networktypes.MustParsePort("8080/tcp")},
445+
"8080/udp": {networktypes.MustParsePort("8080/udp")},
446+
"8080/ncp": {networktypes.MustParsePort("8080/ncp")},
447+
"8080-8080/udp": {networktypes.MustParsePort("8080/udp")},
448+
"8080-8082/tcp": {networktypes.MustParsePort("8080/tcp"), networktypes.MustParsePort("8081/tcp"), networktypes.MustParsePort("8082/tcp")},
447449
}
448450
for expose, expectedError := range invalids {
449-
if _, _, _, err := parseRun([]string{fmt.Sprintf("--expose=%v", expose), "img", "cmd"}); err == nil || err.Error() != expectedError {
450-
t.Fatalf("Expected error '%v' with '--expose=%v', got '%v'", expectedError, expose, err)
451-
}
451+
t.Run("invalid/"+expose, func(t *testing.T) {
452+
if _, _, _, err := parseRun([]string{fmt.Sprintf("--expose=%v", expose), "img", "cmd"}); err == nil || err.Error() != expectedError {
453+
t.Fatalf("Expected error '%v' with '--expose=%v', got '%v'", expectedError, expose, err)
454+
}
455+
})
452456
}
453457
for expose, exposedPorts := range valids {
454-
config, _, _, err := parseRun([]string{fmt.Sprintf("--expose=%v", expose), "img", "cmd"})
458+
t.Run("valid/"+expose, func(t *testing.T) {
459+
config, _, _, err := parseRun([]string{fmt.Sprintf("--expose=%v", expose), "img", "cmd"})
460+
if err != nil {
461+
t.Fatal(err)
462+
}
463+
if len(config.ExposedPorts) != len(exposedPorts) {
464+
t.Fatalf("Expected %v exposed port, got %v", len(exposedPorts), len(config.ExposedPorts))
465+
}
466+
for _, port := range exposedPorts {
467+
if _, ok := config.ExposedPorts[port]; !ok {
468+
t.Fatalf("Expected %v, got %v", exposedPorts, config.ExposedPorts)
469+
}
470+
}
471+
})
472+
}
473+
t.Run("merge with published", func(t *testing.T) {
474+
// Merge with actual published port
475+
config, _, _, err := parseRun([]string{"--publish=80", "--expose=80-81/tcp", "img", "cmd"})
455476
if err != nil {
456477
t.Fatal(err)
457478
}
458-
if len(config.ExposedPorts) != len(exposedPorts) {
459-
t.Fatalf("Expected %v exposed port, got %v", len(exposedPorts), len(config.ExposedPorts))
479+
if len(config.ExposedPorts) != 2 {
480+
t.Fatalf("Expected 2 exposed ports, got %v", config.ExposedPorts)
460481
}
461-
for _, port := range exposedPorts {
482+
ports := []networktypes.Port{networktypes.MustParsePort("80/tcp"), networktypes.MustParsePort("81/tcp")}
483+
for _, port := range ports {
462484
if _, ok := config.ExposedPorts[port]; !ok {
463-
t.Fatalf("Expected %v, got %v", exposedPorts, config.ExposedPorts)
485+
t.Fatalf("Expected %v, got %v", ports, config.ExposedPorts)
464486
}
465487
}
466-
}
467-
// Merge with actual published port
468-
config, _, _, err := parseRun([]string{"--publish=80", "--expose=80-81/tcp", "img", "cmd"})
469-
if err != nil {
470-
t.Fatal(err)
471-
}
472-
if len(config.ExposedPorts) != 2 {
473-
t.Fatalf("Expected 2 exposed ports, got %v", config.ExposedPorts)
474-
}
475-
ports := []container.PortRangeProto{"80/tcp", "81/tcp"}
476-
for _, port := range ports {
477-
if _, ok := config.ExposedPorts[port]; !ok {
478-
t.Fatalf("Expected %v, got %v", ports, config.ExposedPorts)
479-
}
480-
}
488+
})
481489
}
482490

483491
func TestParseDevice(t *testing.T) {
@@ -607,9 +615,9 @@ func TestParseNetworkConfig(t *testing.T) {
607615
expected: map[string]*networktypes.EndpointSettings{
608616
"net1": {
609617
IPAMConfig: &networktypes.EndpointIPAMConfig{
610-
IPv4Address: "172.20.88.22",
611-
IPv6Address: "2001:db8::8822",
612-
LinkLocalIPs: []string{"169.254.2.2", "fe80::169:254:2:2"},
618+
IPv4Address: netip.MustParseAddr("172.20.88.22"),
619+
IPv6Address: netip.MustParseAddr("2001:db8::8822"),
620+
LinkLocalIPs: []netip.Addr{netip.MustParseAddr("169.254.2.2"), netip.MustParseAddr("fe80::169:254:2:2")},
613621
},
614622
Links: []string{"foo:bar", "bar:baz"},
615623
Aliases: []string{"web1", "web2"},
@@ -637,9 +645,9 @@ func TestParseNetworkConfig(t *testing.T) {
637645
"net1": {
638646
DriverOpts: map[string]string{"field1": "value1"},
639647
IPAMConfig: &networktypes.EndpointIPAMConfig{
640-
IPv4Address: "172.20.88.22",
641-
IPv6Address: "2001:db8::8822",
642-
LinkLocalIPs: []string{"169.254.2.2", "fe80::169:254:2:2"},
648+
IPv4Address: netip.MustParseAddr("172.20.88.22"),
649+
IPv6Address: netip.MustParseAddr("2001:db8::8822"),
650+
LinkLocalIPs: []netip.Addr{netip.MustParseAddr("169.254.2.2"), netip.MustParseAddr("fe80::169:254:2:2")},
643651
},
644652
Links: []string{"foo:bar", "bar:baz"},
645653
Aliases: []string{"web1", "web2"},
@@ -648,15 +656,15 @@ func TestParseNetworkConfig(t *testing.T) {
648656
"net3": {
649657
DriverOpts: map[string]string{"field3": "value3"},
650658
IPAMConfig: &networktypes.EndpointIPAMConfig{
651-
IPv4Address: "172.20.88.22",
652-
IPv6Address: "2001:db8::8822",
659+
IPv4Address: netip.MustParseAddr("172.20.88.22"),
660+
IPv6Address: netip.MustParseAddr("2001:db8::8822"),
653661
},
654662
Aliases: []string{"web3"},
655663
},
656664
"net4": {
657665
MacAddress: "02:32:1c:23:00:04",
658666
IPAMConfig: &networktypes.EndpointIPAMConfig{
659-
LinkLocalIPs: []string{"169.254.169.254"},
667+
LinkLocalIPs: []netip.Addr{netip.MustParseAddr("169.254.169.254")},
660668
},
661669
},
662670
},
@@ -672,8 +680,8 @@ func TestParseNetworkConfig(t *testing.T) {
672680
"field2": "value2",
673681
},
674682
IPAMConfig: &networktypes.EndpointIPAMConfig{
675-
IPv4Address: "172.20.88.22",
676-
IPv6Address: "2001:db8::8822",
683+
IPv4Address: netip.MustParseAddr("172.20.88.22"),
684+
IPv6Address: netip.MustParseAddr("2001:db8::8822"),
677685
},
678686
Aliases: []string{"web1", "web2"},
679687
MacAddress: "02:32:1c:23:00:04",
@@ -754,7 +762,7 @@ func TestParseNetworkConfig(t *testing.T) {
754762
assert.NilError(t, err)
755763
assert.DeepEqual(t, config.MacAddress, tc.expectedCfg.MacAddress) //nolint:staticcheck // ignore SA1019: field is deprecated, but still used on API < v1.44.
756764
assert.DeepEqual(t, hConfig.NetworkMode, tc.expectedHostCfg.NetworkMode)
757-
assert.DeepEqual(t, nwConfig.EndpointsConfig, tc.expected)
765+
assert.DeepEqual(t, nwConfig.EndpointsConfig, tc.expected, cmpopts.IgnoreUnexported(netip.Addr{}))
758766
})
759767
}
760768
}

0 commit comments

Comments
 (0)