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:
parent
6e86aa6ca6
commit
fc9b204f39
2 changed files with 16 additions and 16 deletions
|
@ -8,6 +8,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
log "github.com/Sirupsen/logrus"
|
||||||
"github.com/docker/docker/pkg/ioutils"
|
"github.com/docker/docker/pkg/ioutils"
|
||||||
"github.com/docker/libnetwork/etchosts"
|
"github.com/docker/libnetwork/etchosts"
|
||||||
"github.com/docker/libnetwork/netlabel"
|
"github.com/docker/libnetwork/netlabel"
|
||||||
|
@ -342,8 +343,6 @@ func (ep *endpoint) Leave(containerID string, options ...EndpointOption) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ep *endpoint) Delete() error {
|
func (ep *endpoint) Delete() error {
|
||||||
var err error
|
|
||||||
|
|
||||||
ep.Lock()
|
ep.Lock()
|
||||||
epid := ep.id
|
epid := ep.id
|
||||||
name := ep.name
|
name := ep.name
|
||||||
|
@ -366,16 +365,17 @@ func (ep *endpoint) Delete() error {
|
||||||
driver := n.driver
|
driver := n.driver
|
||||||
delete(n.endpoints, epid)
|
delete(n.endpoints, epid)
|
||||||
n.Unlock()
|
n.Unlock()
|
||||||
defer func() {
|
|
||||||
if err != nil {
|
if err := driver.DeleteEndpoint(nid, epid); err != nil {
|
||||||
|
if _, ok := err.(types.ForbiddenError); ok {
|
||||||
n.Lock()
|
n.Lock()
|
||||||
n.endpoints[epid] = ep
|
n.endpoints[epid] = ep
|
||||||
n.Unlock()
|
n.Unlock()
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
}()
|
log.Warnf("driver error deleting endpoint %s : %v", name, err)
|
||||||
|
}
|
||||||
err = driver.DeleteEndpoint(nid, epid)
|
return nil
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ep *endpoint) buildHostsFiles() error {
|
func (ep *endpoint) buildHostsFiles() error {
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
log "github.com/Sirupsen/logrus"
|
||||||
"github.com/docker/docker/pkg/stringid"
|
"github.com/docker/docker/pkg/stringid"
|
||||||
"github.com/docker/libnetwork/datastore"
|
"github.com/docker/libnetwork/datastore"
|
||||||
"github.com/docker/libnetwork/driverapi"
|
"github.com/docker/libnetwork/driverapi"
|
||||||
|
@ -160,8 +161,6 @@ func (n *network) processOptions(options ...NetworkOption) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *network) Delete() error {
|
func (n *network) Delete() error {
|
||||||
var err error
|
|
||||||
|
|
||||||
n.ctrlr.Lock()
|
n.ctrlr.Lock()
|
||||||
_, ok := n.ctrlr.networks[n.id]
|
_, ok := n.ctrlr.networks[n.id]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -179,16 +178,17 @@ func (n *network) Delete() error {
|
||||||
|
|
||||||
delete(n.ctrlr.networks, n.id)
|
delete(n.ctrlr.networks, n.id)
|
||||||
n.ctrlr.Unlock()
|
n.ctrlr.Unlock()
|
||||||
defer func() {
|
if err := n.driver.DeleteNetwork(n.id); err != nil {
|
||||||
if err != nil {
|
// Forbidden Errors should be honored
|
||||||
|
if _, ok := err.(types.ForbiddenError); ok {
|
||||||
n.ctrlr.Lock()
|
n.ctrlr.Lock()
|
||||||
n.ctrlr.networks[n.id] = n
|
n.ctrlr.networks[n.id] = n
|
||||||
n.ctrlr.Unlock()
|
n.ctrlr.Unlock()
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
}()
|
log.Warnf("driver error deleting network %s : %v", n.name, err)
|
||||||
|
}
|
||||||
err = n.driver.DeleteNetwork(n.id)
|
return nil
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *network) CreateEndpoint(name string, options ...EndpointOption) (Endpoint, error) {
|
func (n *network) CreateEndpoint(name string, options ...EndpointOption) (Endpoint, error) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue