daemon: buildCreateEndpointOptions: minor nits

- store network.Name() in a variable to reduce repeatedly locking/unlocking
  of the network (although this is very, very minimal in the grand scheme
  of things).
- un-wrap long conditions
- ever so slightly optimise some conditions by changeing the order of checks.

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

View file

@ -800,10 +800,9 @@ func (daemon *Daemon) clearAttachableNetworks() {
func buildCreateEndpointOptions(c *container.Container, n *libnetwork.Network, epConfig *network.EndpointSettings, sb *libnetwork.Sandbox, daemonDNS []string) ([]libnetwork.EndpointOption, error) {
var createOptions []libnetwork.EndpointOption
nwName := n.Name()
defaultNetName := runconfig.DefaultDaemonNetworkMode().NetworkName()
if (!serviceDiscoveryOnDefaultNetwork() && n.Name() == defaultNetName) ||
c.NetworkSettings.IsAnonymousEndpoint {
if c.NetworkSettings.IsAnonymousEndpoint || (nwName == defaultNetName && !serviceDiscoveryOnDefaultNetwork()) {
createOptions = append(createOptions, libnetwork.CreateOptionAnonymous())
}
@ -860,7 +859,7 @@ func buildCreateEndpointOptions(c *container.Container, n *libnetwork.Network, e
createOptions = append(createOptions, libnetwork.CreateOptionService(svcCfg.Name, svcCfg.ID, vip, portConfigs, svcCfg.Aliases[nwID]))
}
if !containertypes.NetworkMode(n.Name()).IsUserDefined() {
if !containertypes.NetworkMode(nwName).IsUserDefined() {
createOptions = append(createOptions, libnetwork.CreateOptionDisableResolution())
}
@ -868,8 +867,7 @@ func buildCreateEndpointOptions(c *container.Container, n *libnetwork.Network, e
// to which container was connected to on docker run.
// Ideally all these network-specific endpoint configurations must be moved under
// container.NetworkSettings.Networks[n.Name()]
if n.Name() == c.HostConfig.NetworkMode.NetworkName() ||
(n.Name() == defaultNetName && c.HostConfig.NetworkMode.IsDefault()) {
if nwName == c.HostConfig.NetworkMode.NetworkName() || (nwName == defaultNetName && c.HostConfig.NetworkMode.IsDefault()) {
if c.Config.MacAddress != "" {
mac, err := net.ParseMAC(c.Config.MacAddress)
if err != nil {