Przeglądaj źródła

daemon: buildCreateEndpointOptions: don't use PortBinding.GetCopy()

This code was initializing a new PortBinding, and creating a deep copy
for each binding. It's unclear what the intent was here, but at least
PortBinding.GetCopy() wasn't adding much value, as it created a new
PortBinding, [copying all values from the original][1], which includes
a [copy of IPAddresses in it][2]. Our original "template" did not have any
of that, so let's forego that, and just create new PortBindings as we go.

[1]: https://github.com/moby/moby/blob/454b6a7cf5187d1153159e5fe07f4b25c7a95e7f/libnetwork/types/types.go#L110-L120
[2]: https://github.com/moby/moby/blob/454b6a7cf5187d1153159e5fe07f4b25c7a95e7f/libnetwork/types/types.go#L236-L244

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 1 rok temu
rodzic
commit
1c6dae1291
1 zmienionych plików z 11 dodań i 7 usunięć
  1. 11 7
      daemon/network.go

+ 11 - 7
daemon/network.go

@@ -920,10 +920,8 @@ func buildCreateEndpointOptions(c *container.Container, n *libnetwork.Network, e
 			Port:  portNum,
 		})
 
-		pb := networktypes.PortBinding{Port: portNum, Proto: portProto}
 		binding := bindings[port]
 		for i := 0; i < len(binding); i++ {
-			pbCopy := pb.GetCopy()
 			newP, err := nat.NewPort(nat.SplitProtoPort(binding[i].HostPort))
 			var portStart, portEnd int
 			if err == nil {
@@ -932,14 +930,20 @@ func buildCreateEndpointOptions(c *container.Container, n *libnetwork.Network, e
 			if err != nil {
 				return nil, errors.Wrapf(err, "Error parsing HostPort value (%s)", binding[i].HostPort)
 			}
-			pbCopy.HostPort = uint16(portStart)
-			pbCopy.HostPortEnd = uint16(portEnd)
-			pbCopy.HostIP = net.ParseIP(binding[i].HostIP)
-			publishedPorts = append(publishedPorts, pbCopy)
+			publishedPorts = append(publishedPorts, networktypes.PortBinding{
+				Proto:       portProto,
+				Port:        portNum,
+				HostIP:      net.ParseIP(binding[i].HostIP),
+				HostPort:    uint16(portStart),
+				HostPortEnd: uint16(portEnd),
+			})
 		}
 
 		if c.HostConfig.PublishAllPorts && len(binding) == 0 {
-			publishedPorts = append(publishedPorts, pb)
+			publishedPorts = append(publishedPorts, networktypes.PortBinding{
+				Proto: portProto,
+				Port:  portNum,
+			})
 		}
 	}