daemon: buildCreateEndpointOptions: skip getPortMapInfo() if not needed

`getPortMapInfo` does many things; it creates a copy of all the sandbox
endpoints, gets the driver, endpoints, and network from store, and creates
port-bindings for all exposed and mapped ports.

We should look if we can create a more minimal implementation for this
purpose, but in the meantime, let's prevent it being called if we don't
need it by making it the second condition in the check.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-07-23 15:04:17 +02:00
parent 9e9a17950a
commit 6ce92aa523
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -893,9 +893,10 @@ func buildCreateEndpointOptions(c *container.Container, n *libnetwork.Network, e
}
}
// Port-mapping rules belong to the container & applicable only to non-internal networks
portmaps := getPortMapInfo(sb)
if n.Info().Internal() || len(portmaps) > 0 {
// Port-mapping rules belong to the container & applicable only to non-internal networks.
//
// TODO(thaJeztah): Look if we can provide a more minimal function for getPortMapInfo, as it does a lot, and we only need the "length".
if n.Info().Internal() || len(getPortMapInfo(sb)) > 0 {
return createOptions, nil
}