1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Correctly clean up --config-only networks

The endpoint count for --config-only networks
was being incremented even when the respective --config-from
inherited network failed to create a network

This was due to a variable shadowing problem with err causing
the deferred function to not execute correctly.

Using the same err variable across the entire function fixes
the issue

Fixes: moby/moby#35101

Signed-off-by: Arko Dasgupta <arko.dasgupta@docker.com>
This commit is contained in:
Arko Dasgupta 2019-05-07 15:36:32 -07:00
parent 60b2a582d4
commit ee574c1b7d

View file

@ -706,11 +706,17 @@ const overlayDSROptionString = "dsr"
// NewNetwork creates a new network of the specified network type. The options // NewNetwork creates a new network of the specified network type. The options
// are network specific and modeled in a generic way. // are network specific and modeled in a generic way.
func (c *controller) NewNetwork(networkType, name string, id string, options ...NetworkOption) (Network, error) { func (c *controller) NewNetwork(networkType, name string, id string, options ...NetworkOption) (Network, error) {
var (
cap *driverapi.Capability
err error
t *network
)
if id != "" { if id != "" {
c.networkLocker.Lock(id) c.networkLocker.Lock(id)
defer c.networkLocker.Unlock(id) defer c.networkLocker.Unlock(id)
if _, err := c.NetworkByID(id); err == nil { if _, err = c.NetworkByID(id); err == nil {
return nil, NetworkNameError(id) return nil, NetworkNameError(id)
} }
} }
@ -739,15 +745,10 @@ func (c *controller) NewNetwork(networkType, name string, id string, options ...
} }
network.processOptions(options...) network.processOptions(options...)
if err := network.validateConfiguration(); err != nil { if err = network.validateConfiguration(); err != nil {
return nil, err return nil, err
} }
var (
cap *driverapi.Capability
err error
)
// Reset network types, force local scope and skip allocation and // Reset network types, force local scope and skip allocation and
// plumbing for configuration networks. Reset of the config-only // plumbing for configuration networks. Reset of the config-only
// network drivers is needed so that this special network is not // network drivers is needed so that this special network is not
@ -794,11 +795,11 @@ func (c *controller) NewNetwork(networkType, name string, id string, options ...
// From this point on, we need the network specific configuration, // From this point on, we need the network specific configuration,
// which may come from a configuration-only network // which may come from a configuration-only network
if network.configFrom != "" { if network.configFrom != "" {
t, err := c.getConfigNetwork(network.configFrom) t, err = c.getConfigNetwork(network.configFrom)
if err != nil { if err != nil {
return nil, types.NotFoundErrorf("configuration network %q does not exist", network.configFrom) return nil, types.NotFoundErrorf("configuration network %q does not exist", network.configFrom)
} }
if err := t.applyConfigurationTo(network); err != nil { if err = t.applyConfigurationTo(network); err != nil {
return nil, types.InternalErrorf("Failed to apply configuration: %v", err) return nil, types.InternalErrorf("Failed to apply configuration: %v", err)
} }
defer func() { defer func() {