Skip to content

Commit 2351a29

Browse files
committed
vendor: github.com/moby/moby/api, github.com/moby/moby/client master
full diff: moby/moby@4ca8aed...694e30a Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 3754fe3 commit 2351a29

Some content is hidden

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

64 files changed

+984
-592
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: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"fmt"
66
"io"
7+
"net/netip"
78
"os"
89
"runtime"
910
"strings"
@@ -438,12 +439,12 @@ func TestParseWithExpose(t *testing.T) {
438439
"8080-NaN/tcp": `invalid range format for --expose: 8080-NaN/tcp, error: strconv.ParseUint: parsing "NaN": invalid syntax`,
439440
"1234567890-8080/tcp": `invalid range format for --expose: 1234567890-8080/tcp, error: strconv.ParseUint: parsing "1234567890": value out of range`,
440441
}
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"},
442+
valids := map[string][]networktypes.Port{
443+
"8080/tcp": {networktypes.MustParsePort("8080/tcp")},
444+
"8080/udp": {networktypes.MustParsePort("8080/udp")},
445+
"8080/ncp": {networktypes.MustParsePort("8080/ncp")},
446+
"8080-8080/udp": {networktypes.MustParsePort("8080/udp")},
447+
"8080-8082/tcp": {networktypes.MustParsePort("8080/tcp"), networktypes.MustParsePort("8081/tcp"), networktypes.MustParsePort("8082/tcp")},
447448
}
448449
for expose, expectedError := range invalids {
449450
if _, _, _, err := parseRun([]string{fmt.Sprintf("--expose=%v", expose), "img", "cmd"}); err == nil || err.Error() != expectedError {
@@ -472,7 +473,7 @@ func TestParseWithExpose(t *testing.T) {
472473
if len(config.ExposedPorts) != 2 {
473474
t.Fatalf("Expected 2 exposed ports, got %v", config.ExposedPorts)
474475
}
475-
ports := []container.PortRangeProto{"80/tcp", "81/tcp"}
476+
ports := []networktypes.Port{networktypes.MustParsePort("80/tcp"), networktypes.MustParsePort("81/tcp")}
476477
for _, port := range ports {
477478
if _, ok := config.ExposedPorts[port]; !ok {
478479
t.Fatalf("Expected %v, got %v", ports, config.ExposedPorts)
@@ -607,9 +608,9 @@ func TestParseNetworkConfig(t *testing.T) {
607608
expected: map[string]*networktypes.EndpointSettings{
608609
"net1": {
609610
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"},
611+
IPv4Address: netip.MustParseAddr("172.20.88.22"),
612+
IPv6Address: netip.MustParseAddr("2001:db8::8822"),
613+
LinkLocalIPs: []netip.Addr{netip.MustParseAddr("169.254.2.2"), netip.MustParseAddr("fe80::169:254:2:2")},
613614
},
614615
Links: []string{"foo:bar", "bar:baz"},
615616
Aliases: []string{"web1", "web2"},
@@ -637,9 +638,9 @@ func TestParseNetworkConfig(t *testing.T) {
637638
"net1": {
638639
DriverOpts: map[string]string{"field1": "value1"},
639640
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"},
641+
IPv4Address: netip.MustParseAddr("172.20.88.22"),
642+
IPv6Address: netip.MustParseAddr("2001:db8::8822"),
643+
LinkLocalIPs: []netip.Addr{netip.MustParseAddr("169.254.2.2"), netip.MustParseAddr("fe80::169:254:2:2")},
643644
},
644645
Links: []string{"foo:bar", "bar:baz"},
645646
Aliases: []string{"web1", "web2"},
@@ -648,15 +649,15 @@ func TestParseNetworkConfig(t *testing.T) {
648649
"net3": {
649650
DriverOpts: map[string]string{"field3": "value3"},
650651
IPAMConfig: &networktypes.EndpointIPAMConfig{
651-
IPv4Address: "172.20.88.22",
652-
IPv6Address: "2001:db8::8822",
652+
IPv4Address: netip.MustParseAddr("172.20.88.22"),
653+
IPv6Address: netip.MustParseAddr("2001:db8::8822"),
653654
},
654655
Aliases: []string{"web3"},
655656
},
656657
"net4": {
657658
MacAddress: "02:32:1c:23:00:04",
658659
IPAMConfig: &networktypes.EndpointIPAMConfig{
659-
LinkLocalIPs: []string{"169.254.169.254"},
660+
LinkLocalIPs: []netip.Addr{netip.MustParseAddr("169.254.169.254")},
660661
},
661662
},
662663
},
@@ -672,8 +673,8 @@ func TestParseNetworkConfig(t *testing.T) {
672673
"field2": "value2",
673674
},
674675
IPAMConfig: &networktypes.EndpointIPAMConfig{
675-
IPv4Address: "172.20.88.22",
676-
IPv6Address: "2001:db8::8822",
676+
IPv4Address: netip.MustParseAddr("172.20.88.22"),
677+
IPv6Address: netip.MustParseAddr("2001:db8::8822"),
677678
},
678679
Aliases: []string{"web1", "web2"},
679680
MacAddress: "02:32:1c:23:00:04",

cli/command/container/port.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@ import (
55
"fmt"
66
"net"
77
"sort"
8-
"strconv"
98
"strings"
109

1110
"github.com/docker/cli/cli"
1211
"github.com/docker/cli/cli/command"
1312
"github.com/docker/cli/cli/command/completion"
1413
"github.com/fvbommel/sortorder"
15-
"github.com/moby/moby/api/types/container"
14+
"github.com/moby/moby/api/types/network"
1615
"github.com/spf13/cobra"
1716
)
1817

@@ -60,24 +59,21 @@ func runPort(ctx context.Context, dockerCli command.Cli, opts *portOptions) erro
6059

6160
var out []string
6261
if opts.port != "" {
63-
port, proto, _ := strings.Cut(opts.port, "/")
64-
if proto == "" {
65-
proto = "tcp"
62+
port, err := network.ParsePort(opts.port)
63+
if err != nil {
64+
return err
6665
}
67-
if _, err = strconv.ParseUint(port, 10, 16); err != nil {
68-
return fmt.Errorf("invalid port (%s): %w", port, err)
69-
}
70-
frontends, exists := c.NetworkSettings.Ports[container.PortRangeProto(port+"/"+proto)]
66+
frontends, exists := c.NetworkSettings.Ports[port]
7167
if !exists || len(frontends) == 0 {
7268
return fmt.Errorf("no public port '%s' published for %s", opts.port, opts.container)
7369
}
7470
for _, frontend := range frontends {
75-
out = append(out, net.JoinHostPort(frontend.HostIP, frontend.HostPort))
71+
out = append(out, net.JoinHostPort(frontend.HostIP.String(), frontend.HostPort))
7672
}
7773
} else {
7874
for from, frontends := range c.NetworkSettings.Ports {
7975
for _, frontend := range frontends {
80-
out = append(out, fmt.Sprintf("%s -> %s", from, net.JoinHostPort(frontend.HostIP, frontend.HostPort)))
76+
out = append(out, fmt.Sprintf("%s -> %s", from, net.JoinHostPort(frontend.HostIP.String(), frontend.HostPort)))
8177
}
8278
}
8379
}

0 commit comments

Comments
 (0)