Skip to content

Commit 25e53b0

Browse files
thaJeztahaustinvazquez
authored andcommitted
vendor: github.com/moby/moby/api, github.com/moby/moby/client master
full diff: moby/moby@4ca8aed...694e30a Signed-off-by: Sebastiaan van Stijn <github@gone.nl> Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
1 parent 30ec4c0 commit 25e53b0

Some content is hidden

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

70 files changed

+1212
-761
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: 58 additions & 11 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"
@@ -430,9 +431,36 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
430431
return nil, err
431432
}
432433

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

438466
// Merge in exposed ports to the map of published ports
@@ -625,7 +653,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
625653
config := &container.Config{
626654
Hostname: copts.hostname,
627655
Domainname: copts.domainname,
628-
ExposedPorts: ports,
656+
ExposedPorts: exposedPorts,
629657
User: copts.user,
630658
Tty: copts.tty,
631659
OpenStdin: copts.stdin,
@@ -661,7 +689,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
661689
// but pre created containers can still have those nil values.
662690
// See https://github.com/docker/docker/pull/17779
663691
// for a more detailed explanation on why we don't want that.
664-
DNS: copts.dns.GetAllOrEmpty(),
692+
DNS: toNetipAddrSlice(copts.dns.GetAllOrEmpty()),
665693
DNSSearch: copts.dnsSearch.GetAllOrEmpty(),
666694
DNSOptions: copts.dnsOptions.GetAllOrEmpty(),
667695
ExtraHosts: copts.extraHosts.GetSlice(),
@@ -804,10 +832,10 @@ func applyContainerOptions(n *opts.NetworkAttachmentOpts, copts *containerOption
804832
if len(n.Links) > 0 && copts.links.Len() > 0 {
805833
return invalidParameter(errors.New("conflicting options: cannot specify both --link and per-network links"))
806834
}
807-
if n.IPv4Address != "" && copts.ipv4Address != "" {
835+
if n.IPv4Address.IsValid() && copts.ipv4Address != "" {
808836
return invalidParameter(errors.New("conflicting options: cannot specify both --ip and per-network IPv4 address"))
809837
}
810-
if n.IPv6Address != "" && copts.ipv6Address != "" {
838+
if n.IPv6Address.IsValid() && copts.ipv6Address != "" {
811839
return invalidParameter(errors.New("conflicting options: cannot specify both --ip6 and per-network IPv6 address"))
812840
}
813841
if n.MacAddress != "" && copts.macAddress != "" {
@@ -827,17 +855,24 @@ func applyContainerOptions(n *opts.NetworkAttachmentOpts, copts *containerOption
827855
copy(n.Links, copts.links.GetSlice())
828856
}
829857
if copts.ipv4Address != "" {
830-
n.IPv4Address = copts.ipv4Address
858+
var err error
859+
n.IPv4Address, err = netip.ParseAddr(copts.ipv4Address)
860+
if err != nil {
861+
return err
862+
}
831863
}
832864
if copts.ipv6Address != "" {
833-
n.IPv6Address = copts.ipv6Address
865+
var err error
866+
n.IPv6Address, err = netip.ParseAddr(copts.ipv6Address)
867+
if err != nil {
868+
return err
869+
}
834870
}
835871
if copts.macAddress != "" {
836872
n.MacAddress = copts.macAddress
837873
}
838874
if copts.linkLocalIPs.Len() > 0 {
839-
n.LinkLocalIPs = make([]string, copts.linkLocalIPs.Len())
840-
copy(n.LinkLocalIPs, copts.linkLocalIPs.GetSlice())
875+
n.LinkLocalIPs = toNetipAddrSlice(copts.linkLocalIPs.GetSlice())
841876
}
842877
return nil
843878
}
@@ -866,7 +901,7 @@ func parseNetworkAttachmentOpt(ep opts.NetworkAttachmentOpts) (*network.Endpoint
866901
if len(ep.Links) > 0 {
867902
epConfig.Links = ep.Links
868903
}
869-
if ep.IPv4Address != "" || ep.IPv6Address != "" || len(ep.LinkLocalIPs) > 0 {
904+
if ep.IPv4Address.IsValid() || ep.IPv6Address.IsValid() || len(ep.LinkLocalIPs) > 0 {
870905
epConfig.IPAMConfig = &network.EndpointIPAMConfig{
871906
IPv4Address: ep.IPv4Address,
872907
IPv6Address: ep.IPv6Address,
@@ -1130,3 +1165,15 @@ func validateAttach(val string) (string, error) {
11301165
}
11311166
return val, errors.New("valid streams are STDIN, STDOUT and STDERR")
11321167
}
1168+
1169+
func toNetipAddrSlice(ips []string) []netip.Addr {
1170+
netips := make([]netip.Addr, 0, len(ips))
1171+
for _, ip := range ips {
1172+
addr, err := netip.ParseAddr(ip)
1173+
if err != nil {
1174+
continue
1175+
}
1176+
netips = append(netips, addr)
1177+
}
1178+
return netips
1179+
}

cli/command/container/opts_test.go

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

1314
"github.com/moby/moby/api/types/container"
15+
"github.com/moby/moby/api/types/network"
1416
networktypes "github.com/moby/moby/api/types/network"
1517
"github.com/spf13/pflag"
1618
"gotest.tools/v3/assert"
@@ -438,12 +440,12 @@ 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][]network.Port{
444+
"8080/tcp": {network.MustParsePort("8080/tcp")},
445+
"8080/udp": {network.MustParsePort("8080/udp")},
446+
"8080/ncp": {network.MustParsePort("8080/ncp")},
447+
"8080-8080/udp": {network.MustParsePort("8080/udp")},
448+
"8080-8082/tcp": {network.MustParsePort("8080/tcp"), network.MustParsePort("8081/tcp"), network.MustParsePort("8082/tcp")},
447449
}
448450
for expose, expectedError := range invalids {
449451
if _, _, _, err := parseRun([]string{fmt.Sprintf("--expose=%v", expose), "img", "cmd"}); err == nil || err.Error() != expectedError {
@@ -472,7 +474,7 @@ func TestParseWithExpose(t *testing.T) {
472474
if len(config.ExposedPorts) != 2 {
473475
t.Fatalf("Expected 2 exposed ports, got %v", config.ExposedPorts)
474476
}
475-
ports := []container.PortRangeProto{"80/tcp", "81/tcp"}
477+
ports := []network.Port{network.MustParsePort("80/tcp"), network.MustParsePort("81/tcp")}
476478
for _, port := range ports {
477479
if _, ok := config.ExposedPorts[port]; !ok {
478480
t.Fatalf("Expected %v, got %v", ports, config.ExposedPorts)
@@ -607,9 +609,9 @@ func TestParseNetworkConfig(t *testing.T) {
607609
expected: map[string]*networktypes.EndpointSettings{
608610
"net1": {
609611
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"},
612+
IPv4Address: netip.MustParseAddr("172.20.88.22"),
613+
IPv6Address: netip.MustParseAddr("2001:db8::8822"),
614+
LinkLocalIPs: []netip.Addr{netip.MustParseAddr("169.254.2.2"), netip.MustParseAddr("fe80::169:254:2:2")},
613615
},
614616
Links: []string{"foo:bar", "bar:baz"},
615617
Aliases: []string{"web1", "web2"},
@@ -637,9 +639,9 @@ func TestParseNetworkConfig(t *testing.T) {
637639
"net1": {
638640
DriverOpts: map[string]string{"field1": "value1"},
639641
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"},
642+
IPv4Address: netip.MustParseAddr("172.20.88.22"),
643+
IPv6Address: netip.MustParseAddr("2001:db8::8822"),
644+
LinkLocalIPs: []netip.Addr{netip.MustParseAddr("169.254.2.2"), netip.MustParseAddr("fe80::169:254:2:2")},
643645
},
644646
Links: []string{"foo:bar", "bar:baz"},
645647
Aliases: []string{"web1", "web2"},
@@ -648,15 +650,15 @@ func TestParseNetworkConfig(t *testing.T) {
648650
"net3": {
649651
DriverOpts: map[string]string{"field3": "value3"},
650652
IPAMConfig: &networktypes.EndpointIPAMConfig{
651-
IPv4Address: "172.20.88.22",
652-
IPv6Address: "2001:db8::8822",
653+
IPv4Address: netip.MustParseAddr("172.20.88.22"),
654+
IPv6Address: netip.MustParseAddr("2001:db8::8822"),
653655
},
654656
Aliases: []string{"web3"},
655657
},
656658
"net4": {
657659
MacAddress: "02:32:1c:23:00:04",
658660
IPAMConfig: &networktypes.EndpointIPAMConfig{
659-
LinkLocalIPs: []string{"169.254.169.254"},
661+
LinkLocalIPs: []netip.Addr{netip.MustParseAddr("169.254.169.254")},
660662
},
661663
},
662664
},
@@ -672,8 +674,8 @@ func TestParseNetworkConfig(t *testing.T) {
672674
"field2": "value2",
673675
},
674676
IPAMConfig: &networktypes.EndpointIPAMConfig{
675-
IPv4Address: "172.20.88.22",
676-
IPv6Address: "2001:db8::8822",
677+
IPv4Address: netip.MustParseAddr("172.20.88.22"),
678+
IPv6Address: netip.MustParseAddr("2001:db8::8822"),
677679
},
678680
Aliases: []string{"web1", "web2"},
679681
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
}

cli/command/container/port_test.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ package container
22

33
import (
44
"io"
5+
"net/netip"
56
"testing"
67

78
"github.com/docker/cli/internal/test"
89
"github.com/moby/moby/api/types/container"
10+
"github.com/moby/moby/api/types/network"
911
"gotest.tools/v3/assert"
1012
"gotest.tools/v3/golden"
1113
)
@@ -46,20 +48,20 @@ func TestNewPortCommandOutput(t *testing.T) {
4648
cli := test.NewFakeCli(&fakeClient{
4749
inspectFunc: func(string) (container.InspectResponse, error) {
4850
ci := container.InspectResponse{NetworkSettings: &container.NetworkSettings{}}
49-
ci.NetworkSettings.Ports = container.PortMap{
50-
"80/tcp": make([]container.PortBinding, len(tc.ips)),
51-
"443/tcp": make([]container.PortBinding, len(tc.ips)),
52-
"443/udp": make([]container.PortBinding, len(tc.ips)),
51+
ci.NetworkSettings.Ports = network.PortMap{
52+
network.MustParsePort("80/tcp"): make([]network.PortBinding, len(tc.ips)),
53+
network.MustParsePort("443/tcp"): make([]network.PortBinding, len(tc.ips)),
54+
network.MustParsePort("443/udp"): make([]network.PortBinding, len(tc.ips)),
5355
}
5456
for i, ip := range tc.ips {
55-
ci.NetworkSettings.Ports["80/tcp"][i] = container.PortBinding{
56-
HostIP: ip, HostPort: "3456",
57+
ci.NetworkSettings.Ports[network.MustParsePort("80/tcp")][i] = network.PortBinding{
58+
HostIP: netip.MustParseAddr(ip), HostPort: "3456",
5759
}
58-
ci.NetworkSettings.Ports["443/tcp"][i] = container.PortBinding{
59-
HostIP: ip, HostPort: "4567",
60+
ci.NetworkSettings.Ports[network.MustParsePort("443/tcp")][i] = network.PortBinding{
61+
HostIP: netip.MustParseAddr(ip), HostPort: "4567",
6062
}
61-
ci.NetworkSettings.Ports["443/udp"][i] = container.PortBinding{
62-
HostIP: ip, HostPort: "5678",
63+
ci.NetworkSettings.Ports[network.MustParsePort("443/udp")][i] = network.PortBinding{
64+
HostIP: netip.MustParseAddr(ip), HostPort: "5678",
6365
}
6466
}
6567
return ci, nil

0 commit comments

Comments
 (0)