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

handling error condition for network and endpoint deletes

Unless it is a forbidden error, libnetwork should not fail a forced
delete of a network and endpoint if the driver throws an error.

Signed-off-by: Madhu Venugopal <madhu@docker.com>
This commit is contained in:
Madhu Venugopal 2015-06-10 13:27:23 -07:00
parent 6e86aa6ca6
commit fc9b204f39
2 changed files with 16 additions and 16 deletions

View file

@ -8,6 +8,7 @@ import (
"path/filepath"
"sync"
log "github.com/Sirupsen/logrus"
"github.com/docker/docker/pkg/ioutils"
"github.com/docker/libnetwork/etchosts"
"github.com/docker/libnetwork/netlabel"
@ -342,8 +343,6 @@ func (ep *endpoint) Leave(containerID string, options ...EndpointOption) error {
}
func (ep *endpoint) Delete() error {
var err error
ep.Lock()
epid := ep.id
name := ep.name
@ -366,16 +365,17 @@ func (ep *endpoint) Delete() error {
driver := n.driver
delete(n.endpoints, epid)
n.Unlock()
defer func() {
if err != nil {
if err := driver.DeleteEndpoint(nid, epid); err != nil {
if _, ok := err.(types.ForbiddenError); ok {
n.Lock()
n.endpoints[epid] = ep
n.Unlock()
return err
}
}()
err = driver.DeleteEndpoint(nid, epid)
return err
log.Warnf("driver error deleting endpoint %s : %v", name, err)
}
return nil
}
func (ep *endpoint) buildHostsFiles() error {

View file

@ -5,6 +5,7 @@ import (
"strings"
"sync"
log "github.com/Sirupsen/logrus"
"github.com/docker/docker/pkg/stringid"
"github.com/docker/libnetwork/datastore"
"github.com/docker/libnetwork/driverapi"
@ -160,8 +161,6 @@ func (n *network) processOptions(options ...NetworkOption) {
}
func (n *network) Delete() error {
var err error
n.ctrlr.Lock()
_, ok := n.ctrlr.networks[n.id]
if !ok {
@ -179,16 +178,17 @@ func (n *network) Delete() error {
delete(n.ctrlr.networks, n.id)
n.ctrlr.Unlock()
defer func() {
if err != nil {
if err := n.driver.DeleteNetwork(n.id); err != nil {
// Forbidden Errors should be honored
if _, ok := err.(types.ForbiddenError); ok {
n.ctrlr.Lock()
n.ctrlr.networks[n.id] = n
n.ctrlr.Unlock()
return err
}
}()
err = n.driver.DeleteNetwork(n.id)
return err
log.Warnf("driver error deleting network %s : %v", n.name, err)
}
return nil
}
func (n *network) CreateEndpoint(name string, options ...EndpointOption) (Endpoint, error) {