Skip to content

Commit 47e215c

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 41432ad commit 47e215c

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

+1232
-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: 61 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"errors"
77
"fmt"
88
"net"
9+
"net/netip"
910
"os"
1011
"path"
1112
"path/filepath"
@@ -431,11 +432,42 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
431432
return nil, err
432433
}
433434

434-
ports, portBindings, err := nat.ParsePortSpecs(convertedOpts)
435+
ports, natPortBindings, err := nat.ParsePortSpecs(convertedOpts)
435436
if err != nil {
436437
return nil, err
437438
}
438439

440+
portBindings := make(map[network.Port][]network.PortBinding)
441+
for port, bindings := range natPortBindings {
442+
p, err := network.ParsePort(port.String())
443+
if err != nil {
444+
return nil, err
445+
}
446+
portBindings[p] = []network.PortBinding{}
447+
for _, b := range bindings {
448+
var hostIP netip.Addr
449+
if b.HostIP.String() != "" {
450+
hostIP, err = netip.ParseAddr(b.HostIP.String())
451+
if err != nil {
452+
return nil, err
453+
}
454+
}
455+
portBindings[p] = append(portBindings[p], network.PortBinding{
456+
HostIP: hostIP,
457+
HostPort: b.HostPort,
458+
})
459+
}
460+
}
461+
462+
exposedPorts := network.PortSet{}
463+
for port := range ports {
464+
p, err := network.ParsePort(port.String())
465+
if err != nil {
466+
return nil, err
467+
}
468+
exposedPorts[p] = struct{}{}
469+
}
470+
439471
// Merge in exposed ports to the map of published ports
440472
for _, e := range copts.expose.GetSlice() {
441473
if strings.Contains(e, ":") {
@@ -626,7 +658,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
626658
config := &container.Config{
627659
Hostname: copts.hostname,
628660
Domainname: copts.domainname,
629-
ExposedPorts: ports,
661+
ExposedPorts: exposedPorts,
630662
User: copts.user,
631663
Tty: copts.tty,
632664
OpenStdin: copts.stdin,
@@ -662,7 +694,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con
662694
// but pre created containers can still have those nil values.
663695
// See https://github.com/docker/docker/pull/17779
664696
// for a more detailed explanation on why we don't want that.
665-
DNS: copts.dns.GetAllOrEmpty(),
697+
DNS: toNetipAddrSlice(copts.dns.GetAllOrEmpty()),
666698
DNSSearch: copts.dnsSearch.GetAllOrEmpty(),
667699
DNSOptions: copts.dnsOptions.GetAllOrEmpty(),
668700
ExtraHosts: copts.extraHosts.GetSlice(),
@@ -805,10 +837,10 @@ func applyContainerOptions(n *opts.NetworkAttachmentOpts, copts *containerOption
805837
if len(n.Links) > 0 && copts.links.Len() > 0 {
806838
return invalidParameter(errors.New("conflicting options: cannot specify both --link and per-network links"))
807839
}
808-
if n.IPv4Address != "" && copts.ipv4Address != "" {
840+
if n.IPv4Address.IsValid() && copts.ipv4Address != "" {
809841
return invalidParameter(errors.New("conflicting options: cannot specify both --ip and per-network IPv4 address"))
810842
}
811-
if n.IPv6Address != "" && copts.ipv6Address != "" {
843+
if n.IPv6Address.IsValid() && copts.ipv6Address != "" {
812844
return invalidParameter(errors.New("conflicting options: cannot specify both --ip6 and per-network IPv6 address"))
813845
}
814846
if n.MacAddress != "" && copts.macAddress != "" {
@@ -828,17 +860,24 @@ func applyContainerOptions(n *opts.NetworkAttachmentOpts, copts *containerOption
828860
copy(n.Links, copts.links.GetSlice())
829861
}
830862
if copts.ipv4Address != "" {
831-
n.IPv4Address = copts.ipv4Address
863+
var err error
864+
n.IPv4Address, err = netip.ParseAddr(copts.ipv4Address)
865+
if err != nil {
866+
return err
867+
}
832868
}
833869
if copts.ipv6Address != "" {
834-
n.IPv6Address = copts.ipv6Address
870+
var err error
871+
n.IPv6Address, err = netip.ParseAddr(copts.ipv6Address)
872+
if err != nil {
873+
return err
874+
}
835875
}
836876
if copts.macAddress != "" {
837877
n.MacAddress = copts.macAddress
838878
}
839879
if copts.linkLocalIPs.Len() > 0 {
840-
n.LinkLocalIPs = make([]string, copts.linkLocalIPs.Len())
841-
copy(n.LinkLocalIPs, copts.linkLocalIPs.GetSlice())
880+
n.LinkLocalIPs = toNetipAddrSlice(copts.linkLocalIPs.GetSlice())
842881
}
843882
return nil
844883
}
@@ -867,7 +906,7 @@ func parseNetworkAttachmentOpt(ep opts.NetworkAttachmentOpts) (*network.Endpoint
867906
if len(ep.Links) > 0 {
868907
epConfig.Links = ep.Links
869908
}
870-
if ep.IPv4Address != "" || ep.IPv6Address != "" || len(ep.LinkLocalIPs) > 0 {
909+
if ep.IPv4Address.IsValid() || ep.IPv6Address.IsValid() || len(ep.LinkLocalIPs) > 0 {
871910
epConfig.IPAMConfig = &network.EndpointIPAMConfig{
872911
IPv4Address: ep.IPv4Address,
873912
IPv6Address: ep.IPv6Address,
@@ -1131,3 +1170,15 @@ func validateAttach(val string) (string, error) {
11311170
}
11321171
return val, errors.New("valid streams are STDIN, STDOUT and STDERR")
11331172
}
1173+
1174+
func toNetipAddrSlice(ips []string) []netip.Addr {
1175+
netips := make([]netip.Addr, 0, len(ips))
1176+
for _, ip := range ips {
1177+
addr, err := netip.ParseAddr(ip)
1178+
if err != nil {
1179+
continue
1180+
}
1181+
netips = append(netips, addr)
1182+
}
1183+
return netips
1184+
}

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)
@@ -447,12 +448,12 @@ func TestParseWithExpose(t *testing.T) {
447448
}
448449
})
449450
t.Run("valid", func(t *testing.T) {
450-
tests := map[string][]container.PortRangeProto{
451-
"8080/tcp": {"8080/tcp"},
452-
"8080/udp": {"8080/udp"},
453-
"8080/ncp": {"8080/ncp"},
454-
"8080-8080/udp": {"8080/udp"},
455-
"8080-8082/tcp": {"8080/tcp", "8081/tcp", "8082/tcp"},
451+
tests := map[string][]network.Port{
452+
"8080/tcp": {network.MustParsePort("8080/tcp")},
453+
"8080/udp": {network.MustParsePort("8080/udp")},
454+
"8080/ncp": {network.MustParsePort("8080/ncp")},
455+
"8080-8080/udp": {network.MustParsePort("8080/udp")},
456+
"8080-8082/tcp": {network.MustParsePort("8080/tcp"), network.MustParsePort("8081/tcp"), network.MustParsePort("8082/tcp")},
456457
}
457458
for expose, exposedPorts := range tests {
458459
t.Run(expose, func(t *testing.T) {
@@ -471,7 +472,7 @@ func TestParseWithExpose(t *testing.T) {
471472
config, _, _, err := parseRun([]string{"--publish=80", "--expose=80-81/tcp", "img", "cmd"})
472473
assert.NilError(t, err)
473474
assert.Check(t, is.Len(config.ExposedPorts, 2))
474-
ports := []container.PortRangeProto{"80/tcp", "81/tcp"}
475+
ports := []network.Port{network.MustParsePort("80/tcp"), network.MustParsePort("81/tcp")}
475476
for _, port := range ports {
476477
_, ok := config.ExposedPorts[port]
477478
assert.Check(t, ok, "missing port %q in exposed ports", port)
@@ -573,21 +574,21 @@ func TestParseNetworkConfig(t *testing.T) {
573574
tests := []struct {
574575
name string
575576
flags []string
576-
expected map[string]*networktypes.EndpointSettings
577+
expected map[string]*network.EndpointSettings
577578
expectedCfg container.Config
578579
expectedHostCfg container.HostConfig
579580
expectedErr string
580581
}{
581582
{
582583
name: "single-network-legacy",
583584
flags: []string{"--network", "net1"},
584-
expected: map[string]*networktypes.EndpointSettings{},
585+
expected: map[string]*network.EndpointSettings{},
585586
expectedHostCfg: container.HostConfig{NetworkMode: "net1"},
586587
},
587588
{
588589
name: "single-network-advanced",
589590
flags: []string{"--network", "name=net1"},
590-
expected: map[string]*networktypes.EndpointSettings{},
591+
expected: map[string]*network.EndpointSettings{},
591592
expectedHostCfg: container.HostConfig{NetworkMode: "net1"},
592593
},
593594
{
@@ -603,12 +604,12 @@ func TestParseNetworkConfig(t *testing.T) {
603604
"--network-alias", "web1",
604605
"--network-alias", "web2",
605606
},
606-
expected: map[string]*networktypes.EndpointSettings{
607+
expected: map[string]*network.EndpointSettings{
607608
"net1": {
608-
IPAMConfig: &networktypes.EndpointIPAMConfig{
609-
IPv4Address: "172.20.88.22",
610-
IPv6Address: "2001:db8::8822",
611-
LinkLocalIPs: []string{"169.254.2.2", "fe80::169:254:2:2"},
609+
IPAMConfig: &network.EndpointIPAMConfig{
610+
IPv4Address: netip.MustParseAddr("172.20.88.22"),
611+
IPv6Address: netip.MustParseAddr("2001:db8::8822"),
612+
LinkLocalIPs: []netip.Addr{netip.MustParseAddr("169.254.2.2"), netip.MustParseAddr("fe80::169:254:2:2")},
612613
},
613614
Links: []string{"foo:bar", "bar:baz"},
614615
Aliases: []string{"web1", "web2"},
@@ -632,30 +633,30 @@ func TestParseNetworkConfig(t *testing.T) {
632633
"--network", "name=net3,alias=web3,driver-opt=field3=value3,ip=172.20.88.22,ip6=2001:db8::8822",
633634
"--network", "name=net4,mac-address=02:32:1c:23:00:04,link-local-ip=169.254.169.254",
634635
},
635-
expected: map[string]*networktypes.EndpointSettings{
636+
expected: map[string]*network.EndpointSettings{
636637
"net1": {
637638
DriverOpts: map[string]string{"field1": "value1"},
638-
IPAMConfig: &networktypes.EndpointIPAMConfig{
639-
IPv4Address: "172.20.88.22",
640-
IPv6Address: "2001:db8::8822",
641-
LinkLocalIPs: []string{"169.254.2.2", "fe80::169:254:2:2"},
639+
IPAMConfig: &network.EndpointIPAMConfig{
640+
IPv4Address: netip.MustParseAddr("172.20.88.22"),
641+
IPv6Address: netip.MustParseAddr("2001:db8::8822"),
642+
LinkLocalIPs: []netip.Addr{netip.MustParseAddr("169.254.2.2"), netip.MustParseAddr("fe80::169:254:2:2")},
642643
},
643644
Links: []string{"foo:bar", "bar:baz"},
644645
Aliases: []string{"web1", "web2"},
645646
},
646647
"net2": {},
647648
"net3": {
648649
DriverOpts: map[string]string{"field3": "value3"},
649-
IPAMConfig: &networktypes.EndpointIPAMConfig{
650-
IPv4Address: "172.20.88.22",
651-
IPv6Address: "2001:db8::8822",
650+
IPAMConfig: &network.EndpointIPAMConfig{
651+
IPv4Address: netip.MustParseAddr("172.20.88.22"),
652+
IPv6Address: netip.MustParseAddr("2001:db8::8822"),
652653
},
653654
Aliases: []string{"web3"},
654655
},
655656
"net4": {
656657
MacAddress: "02:32:1c:23:00:04",
657-
IPAMConfig: &networktypes.EndpointIPAMConfig{
658-
LinkLocalIPs: []string{"169.254.169.254"},
658+
IPAMConfig: &network.EndpointIPAMConfig{
659+
LinkLocalIPs: []netip.Addr{netip.MustParseAddr("169.254.169.254")},
659660
},
660661
},
661662
},
@@ -664,15 +665,15 @@ func TestParseNetworkConfig(t *testing.T) {
664665
{
665666
name: "single-network-advanced-with-options",
666667
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"},
667-
expected: map[string]*networktypes.EndpointSettings{
668+
expected: map[string]*network.EndpointSettings{
668669
"net1": {
669670
DriverOpts: map[string]string{
670671
"field1": "value1",
671672
"field2": "value2",
672673
},
673-
IPAMConfig: &networktypes.EndpointIPAMConfig{
674-
IPv4Address: "172.20.88.22",
675-
IPv6Address: "2001:db8::8822",
674+
IPAMConfig: &network.EndpointIPAMConfig{
675+
IPv4Address: netip.MustParseAddr("172.20.88.22"),
676+
IPv6Address: netip.MustParseAddr("2001:db8::8822"),
676677
},
677678
Aliases: []string{"web1", "web2"},
678679
MacAddress: "02:32:1c:23:00:04",
@@ -684,13 +685,13 @@ func TestParseNetworkConfig(t *testing.T) {
684685
{
685686
name: "multiple-networks",
686687
flags: []string{"--network", "net1", "--network", "name=net2"},
687-
expected: map[string]*networktypes.EndpointSettings{"net1": {}, "net2": {}},
688+
expected: map[string]*network.EndpointSettings{"net1": {}, "net2": {}},
688689
expectedHostCfg: container.HostConfig{NetworkMode: "net1"},
689690
},
690691
{
691692
name: "advanced-options-with-standalone-mac-address-flag",
692693
flags: []string{"--network=name=net1,alias=foobar", "--mac-address", "52:0f:f3:dc:50:10"},
693-
expected: map[string]*networktypes.EndpointSettings{
694+
expected: map[string]*network.EndpointSettings{
694695
"net1": {
695696
Aliases: []string{"foobar"},
696697
MacAddress: "52:0f:f3:dc:50:10",

0 commit comments

Comments
 (0)