Skip to content

Commit

Permalink
Remove driver endpoints on network deleting
Browse files Browse the repository at this point in the history
Signed-off-by: Lei Jitang <leijitang@huawei.com>
  • Loading branch information
coolljt0725 committed Oct 14, 2016
1 parent 393afa7 commit b757f57
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
14 changes: 14 additions & 0 deletions drivers/bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,20 @@ func (d *driver) DeleteNetwork(nid string) error {
config := n.config
n.Unlock()

// delele endpoints belong to this network
for _, ep := range n.endpoints {
if err := n.releasePorts(ep); err != nil {
logrus.Warn(err)
}
if link, err := d.nlh.LinkByName(ep.srcName); err == nil {
d.nlh.LinkDel(link)
}

if err := d.storeDelete(ep); err != nil {
logrus.Warnf("Failed to remove bridge endpoint %s from store: %v", ep.id[0:7], err)
}
}

d.Lock()
delete(d.networks, nid)
d.Unlock()
Expand Down
10 changes: 10 additions & 0 deletions drivers/ipvlan/ipvlan_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/docker/docker/pkg/stringid"
"github.com/docker/libnetwork/driverapi"
"github.com/docker/libnetwork/netlabel"
"github.com/docker/libnetwork/ns"
"github.com/docker/libnetwork/options"
"github.com/docker/libnetwork/osl"
"github.com/docker/libnetwork/types"
Expand Down Expand Up @@ -147,6 +148,15 @@ func (d *driver) DeleteNetwork(nid string) error {
}
}
}
for _, ep := range n.endpoints {
if link, err := ns.NlHandle().LinkByName(ep.srcName); err == nil {
ns.NlHandle().LinkDel(link)
}

if err := d.storeDelete(ep); err != nil {
logrus.Warnf("Failed to remove ipvlan endpoint %s from store: %v", ep.id[0:7], err)
}
}
// delete the *network
d.deleteNetwork(nid)
// delete the network record from persistent cache
Expand Down
10 changes: 10 additions & 0 deletions drivers/macvlan/macvlan_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/docker/docker/pkg/stringid"
"github.com/docker/libnetwork/driverapi"
"github.com/docker/libnetwork/netlabel"
"github.com/docker/libnetwork/ns"
"github.com/docker/libnetwork/options"
"github.com/docker/libnetwork/osl"
"github.com/docker/libnetwork/types"
Expand Down Expand Up @@ -151,6 +152,15 @@ func (d *driver) DeleteNetwork(nid string) error {
}
}
}
for _, ep := range n.endpoints {
if link, err := ns.NlHandle().LinkByName(ep.srcName); err == nil {
ns.NlHandle().LinkDel(link)
}

if err := d.storeDelete(ep); err != nil {
logrus.Warnf("Failed to remove macvlan endpoint %s from store: %v", ep.id[0:7], err)
}
}
// delete the *network
d.deleteNetwork(nid)
// delete the network record from persistent cache
Expand Down
12 changes: 12 additions & 0 deletions drivers/overlay/ov_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,18 @@ func (d *driver) DeleteNetwork(nid string) error {
return fmt.Errorf("could not find network with id %s", nid)
}

for _, ep := range n.endpoints {
if ep.ifName != "" {
if link, err := ns.NlHandle().LinkByName(ep.ifName); err != nil {
ns.NlHandle().LinkDel(link)
}
}

if err := d.deleteEndpointFromStore(ep); err != nil {
logrus.Warnf("Failed to delete overlay endpoint %s from local store: %v", ep.id[0:7], err)
}

}
d.deleteNetwork(nid)

vnis, err := n.releaseVxlanID()
Expand Down

0 comments on commit b757f57

Please sign in to comment.