@@ -4,20 +4,18 @@ import (
44 "errors"
55 "fmt"
66 "net"
7+ "net/netip"
78 "strconv"
89 "strings"
910 "time"
1011
11- "github.com/docker/docker/api/types"
12- enginecontainer "github.com/docker/docker/api/types/container"
13- "github.com/docker/docker/api/types/events"
14- "github.com/docker/docker/api/types/filters"
15- enginemount "github.com/docker/docker/api/types/mount"
16- "github.com/docker/docker/api/types/network"
17- "github.com/docker/docker/api/types/volume"
18- "github.com/docker/go-connections/nat"
1912 "github.com/docker/go-units"
2013 gogotypes "github.com/gogo/protobuf/types"
14+ enginecontainer "github.com/moby/moby/api/types/container"
15+ "github.com/moby/moby/api/types/events"
16+ enginemount "github.com/moby/moby/api/types/mount"
17+ "github.com/moby/moby/api/types/network"
18+ engineapi "github.com/moby/moby/client"
2119 "github.com/moby/swarmkit/v2/agent/exec"
2220 "github.com/moby/swarmkit/v2/api"
2321 "github.com/moby/swarmkit/v2/api/genericresource"
@@ -93,12 +91,13 @@ func (c *containerConfig) image() string {
9391 return c .spec ().Image
9492}
9593
96- func portSpec (port uint32 , protocol api.PortConfig_Protocol ) nat.Port {
97- return nat .Port (fmt .Sprintf ("%d/%s" , port , strings .ToLower (protocol .String ())))
94+ func portSpec (port uint32 , protocol api.PortConfig_Protocol ) network.Port {
95+ p , _ := network .ParsePort (fmt .Sprintf ("%d/%s" , port , strings .ToLower (protocol .String ())))
96+ return p
9897}
9998
100- func (c * containerConfig ) portBindings () nat .PortMap {
101- portBindings := nat .PortMap {}
99+ func (c * containerConfig ) portBindings () network .PortMap {
100+ portBindings := network .PortMap {}
102101 if c .task .Endpoint == nil {
103102 return portBindings
104103 }
@@ -109,7 +108,7 @@ func (c *containerConfig) portBindings() nat.PortMap {
109108 }
110109
111110 port := portSpec (portConfig .TargetPort , portConfig .Protocol )
112- binding := []nat .PortBinding {
111+ binding := []network .PortBinding {
113112 {},
114113 }
115114
@@ -125,17 +124,18 @@ func (c *containerConfig) portBindings() nat.PortMap {
125124func (c * containerConfig ) isolation () enginecontainer.Isolation {
126125 switch c .spec ().Isolation {
127126 case api .ContainerIsolationDefault :
128- return enginecontainer . Isolation ( "default" )
127+ return "default"
129128 case api .ContainerIsolationHyperV :
130- return enginecontainer . Isolation ( "hyperv" )
129+ return "hyperv"
131130 case api .ContainerIsolationProcess :
132- return enginecontainer .Isolation ("process" )
131+ return "process"
132+ default :
133+ return ""
133134 }
134- return enginecontainer .Isolation ("" )
135135}
136136
137- func (c * containerConfig ) exposedPorts () map [nat. Port ] struct {} {
138- exposedPorts := make (map [nat. Port ] struct {} )
137+ func (c * containerConfig ) exposedPorts () network. PortSet {
138+ exposedPorts := make (network. PortSet )
139139 if c .task .Endpoint == nil {
140140 return exposedPorts
141141 }
@@ -427,7 +427,7 @@ func getMountMask(m *api.Mount) string {
427427}
428428
429429// This handles the case of volumes that are defined inside a service Mount
430- func (c * containerConfig ) volumeCreateRequest (mount * api.Mount ) * volume. CreateOptions {
430+ func (c * containerConfig ) volumeCreateRequest (mount * api.Mount ) * engineapi. VolumeCreateOptions {
431431 var (
432432 driverName string
433433 driverOpts map [string ]string
@@ -441,7 +441,7 @@ func (c *containerConfig) volumeCreateRequest(mount *api.Mount) *volume.CreateOp
441441 }
442442
443443 // FIXME: do we need the ClusterVolumeSpec here?
444- return & volume. CreateOptions {
444+ return & engineapi. VolumeCreateOptions {
445445 Name : mount .Source ,
446446 Driver : driverName ,
447447 DriverOpts : driverOpts ,
@@ -513,20 +513,20 @@ func (c *containerConfig) virtualIP(networkID string) string {
513513func (c * containerConfig ) networkingConfig () * network.NetworkingConfig {
514514 epConfig := make (map [string ]* network.EndpointSettings )
515515 for _ , na := range c .task .Networks {
516- var ipv4 , ipv6 string
516+ var ipv4 , ipv6 netip. Addr
517517 for _ , addr := range na .Addresses {
518- ip , _ , err := net . ParseCIDR (addr )
518+ prefix , err := netip . ParsePrefix (addr )
519519 if err != nil {
520520 continue
521521 }
522522
523- if ip .To4 () != nil {
524- ipv4 = ip .String ()
523+ ip := prefix .Addr ()
524+ if ip .Is4 () {
525+ ipv4 = ip
525526 continue
526527 }
527-
528- if ip .To16 () != nil {
529- ipv6 = ip .String ()
528+ if ip .Is6 () {
529+ ipv6 = ip
530530 }
531531 }
532532
@@ -556,39 +556,48 @@ func (c *containerConfig) networks() []string {
556556 return networks
557557}
558558
559- func (c * containerConfig ) networkCreateOptions (name string ) (types. NetworkCreate , error ) {
559+ func (c * containerConfig ) networkCreateOptions (name string ) (engineapi. NetworkCreateOptions , error ) {
560560 na , ok := c .networksAttachments [name ]
561561 if ! ok {
562- return types. NetworkCreate {}, errors .New ("container: unknown network referenced" )
562+ return engineapi. NetworkCreateOptions {}, errors .New ("container: unknown network referenced" )
563563 }
564564
565- options := types. NetworkCreate {
565+ options := engineapi. NetworkCreateOptions {
566566 Driver : na .Network .DriverState .Name ,
567567 IPAM : & network.IPAM {
568568 Driver : na .Network .IPAM .Driver .Name ,
569569 },
570- Options : na .Network .DriverState .Options ,
571- CheckDuplicate : true ,
570+ Options : na .Network .DriverState .Options ,
572571 }
573572
574573 for _ , ic := range na .Network .IPAM .Configs {
575- c := network.IPAMConfig {
576- Subnet : ic .Subnet ,
577- IPRange : ic .Range ,
578- Gateway : ic .Gateway ,
574+ sn , err := netip .ParsePrefix (ic .Subnet )
575+ if err != nil {
576+ continue
577+ }
578+ r , err := netip .ParsePrefix (ic .Range )
579+ if err != nil {
580+ continue
581+ }
582+ gw , err := netip .ParseAddr (ic .Gateway )
583+ if err != nil {
584+ continue
579585 }
580- options .IPAM .Config = append (options .IPAM .Config , c )
586+ options .IPAM .Config = append (options .IPAM .Config , network.IPAMConfig {
587+ Subnet : sn ,
588+ IPRange : r ,
589+ Gateway : gw ,
590+ })
581591 }
582592
583593 return options , nil
584594}
585595
586- func (c containerConfig ) eventFilter () filters.Args {
587- filter := filters .NewArgs ()
588- filter .Add ("type" , string (events .ContainerEventType ))
589- filter .Add ("name" , c .name ())
590- filter .Add ("label" , fmt .Sprintf ("%v.task.id=%v" , systemLabelPrefix , c .task .ID ))
591- return filter
596+ func (c containerConfig ) eventFilter () engineapi.Filters {
597+ return make (engineapi.Filters ).
598+ Add ("type" , string (events .ContainerEventType )).
599+ Add ("name" , c .name ()).
600+ Add ("label" , fmt .Sprintf ("%v.task.id=%v" , systemLabelPrefix , c .task .ID ))
592601}
593602
594603func (c * containerConfig ) init () * bool {
0 commit comments