Skip to content

Commit 7bf32ab

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 <[email protected]> Signed-off-by: Austin Vazquez <[email protected]>
1 parent 30ec4c0 commit 7bf32ab

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

+1227
-777
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: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +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"
14-
networktypes "github.com/moby/moby/api/types/network"
15+
"github.com/moby/moby/api/types/network"
1516
"github.com/spf13/pflag"
1617
"gotest.tools/v3/assert"
1718
is "gotest.tools/v3/assert/cmp"
@@ -42,7 +43,7 @@ func TestValidateAttach(t *testing.T) {
4243
}
4344
}
4445

45-
func parseRun(args []string) (*container.Config, *container.HostConfig, *networktypes.NetworkingConfig, error) {
46+
func parseRun(args []string) (*container.Config, *container.HostConfig, *network.NetworkingConfig, error) {
4647
flags, copts := setupRunFlags()
4748
if err := flags.Parse(args); err != nil {
4849
return nil, nil, nil, err
@@ -63,7 +64,7 @@ func setupRunFlags() (*pflag.FlagSet, *containerOptions) {
6364
return flags, copts
6465
}
6566

66-
func mustParse(t *testing.T, args string) (*container.Config, *container.HostConfig, *networktypes.NetworkingConfig) {
67+
func mustParse(t *testing.T, args string) (*container.Config, *container.HostConfig, *network.NetworkingConfig) {
6768
t.Helper()
6869
config, hostConfig, nwConfig, err := parseRun(append(strings.Split(args, " "), "ubuntu", "bash"))
6970
assert.NilError(t, err)
@@ -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][]network.Port{
443+
"8080/tcp": {network.MustParsePort("8080/tcp")},
444+
"8080/udp": {network.MustParsePort("8080/udp")},
445+
"8080/ncp": {network.MustParsePort("8080/ncp")},
446+
"8080-8080/udp": {network.MustParsePort("8080/udp")},
447+
"8080-8082/tcp": {network.MustParsePort("8080/tcp"), network.MustParsePort("8081/tcp"), network.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 := []network.Port{network.MustParsePort("80/tcp"), network.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)
@@ -574,21 +575,21 @@ func TestParseNetworkConfig(t *testing.T) {
574575
tests := []struct {
575576
name string
576577
flags []string
577-
expected map[string]*networktypes.EndpointSettings
578+
expected map[string]*network.EndpointSettings
578579
expectedCfg container.Config
579580
expectedHostCfg container.HostConfig
580581
expectedErr string
581582
}{
582583
{
583584
name: "single-network-legacy",
584585
flags: []string{"--network", "net1"},
585-
expected: map[string]*networktypes.EndpointSettings{},
586+
expected: map[string]*network.EndpointSettings{},
586587
expectedHostCfg: container.HostConfig{NetworkMode: "net1"},
587588
},
588589
{
589590
name: "single-network-advanced",
590591
flags: []string{"--network", "name=net1"},
591-
expected: map[string]*networktypes.EndpointSettings{},
592+
expected: map[string]*network.EndpointSettings{},
592593
expectedHostCfg: container.HostConfig{NetworkMode: "net1"},
593594
},
594595
{
@@ -604,12 +605,12 @@ func TestParseNetworkConfig(t *testing.T) {
604605
"--network-alias", "web1",
605606
"--network-alias", "web2",
606607
},
607-
expected: map[string]*networktypes.EndpointSettings{
608+
expected: map[string]*network.EndpointSettings{
608609
"net1": {
609-
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"},
610+
IPAMConfig: &network.EndpointIPAMConfig{
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"},
@@ -633,30 +634,30 @@ func TestParseNetworkConfig(t *testing.T) {
633634
"--network", "name=net3,alias=web3,driver-opt=field3=value3,ip=172.20.88.22,ip6=2001:db8::8822",
634635
"--network", "name=net4,mac-address=02:32:1c:23:00:04,link-local-ip=169.254.169.254",
635636
},
636-
expected: map[string]*networktypes.EndpointSettings{
637+
expected: map[string]*network.EndpointSettings{
637638
"net1": {
638639
DriverOpts: map[string]string{"field1": "value1"},
639-
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"},
640+
IPAMConfig: &network.EndpointIPAMConfig{
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"},
646647
},
647648
"net2": {},
648649
"net3": {
649650
DriverOpts: map[string]string{"field3": "value3"},
650-
IPAMConfig: &networktypes.EndpointIPAMConfig{
651-
IPv4Address: "172.20.88.22",
652-
IPv6Address: "2001:db8::8822",
651+
IPAMConfig: &network.EndpointIPAMConfig{
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",
658-
IPAMConfig: &networktypes.EndpointIPAMConfig{
659-
LinkLocalIPs: []string{"169.254.169.254"},
659+
IPAMConfig: &network.EndpointIPAMConfig{
660+
LinkLocalIPs: []netip.Addr{netip.MustParseAddr("169.254.169.254")},
660661
},
661662
},
662663
},
@@ -665,15 +666,15 @@ func TestParseNetworkConfig(t *testing.T) {
665666
{
666667
name: "single-network-advanced-with-options",
667668
flags: []string{"--network", "name=net1,alias=web1,alias=web2,driver-opt=field1=value1,driver-opt=field2=value2,ip=172.20.88.22,ip6=2001:db8::8822,mac-address=02:32:1c:23:00:04"},
668-
expected: map[string]*networktypes.EndpointSettings{
669+
expected: map[string]*network.EndpointSettings{
669670
"net1": {
670671
DriverOpts: map[string]string{
671672
"field1": "value1",
672673
"field2": "value2",
673674
},
674-
IPAMConfig: &networktypes.EndpointIPAMConfig{
675-
IPv4Address: "172.20.88.22",
676-
IPv6Address: "2001:db8::8822",
675+
IPAMConfig: &network.EndpointIPAMConfig{
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",
@@ -685,13 +686,13 @@ func TestParseNetworkConfig(t *testing.T) {
685686
{
686687
name: "multiple-networks",
687688
flags: []string{"--network", "net1", "--network", "name=net2"},
688-
expected: map[string]*networktypes.EndpointSettings{"net1": {}, "net2": {}},
689+
expected: map[string]*network.EndpointSettings{"net1": {}, "net2": {}},
689690
expectedHostCfg: container.HostConfig{NetworkMode: "net1"},
690691
},
691692
{
692693
name: "advanced-options-with-standalone-mac-address-flag",
693694
flags: []string{"--network=name=net1,alias=foobar", "--mac-address", "52:0f:f3:dc:50:10"},
694-
expected: map[string]*networktypes.EndpointSettings{
695+
expected: map[string]*network.EndpointSettings{
695696
"net1": {
696697
Aliases: []string{"foobar"},
697698
MacAddress: "52:0f:f3:dc:50:10",

0 commit comments

Comments
 (0)