Skip to content

Commit c8a3950

Browse files
committed
Delete stale HNS endpoints when creating a network
Signed-off-by: John Stephens <johnstep@docker.com>
1 parent 9bade4d commit c8a3950

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

libnetwork/drivers/windows/windows.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,22 @@ func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo d
365365

366366
config.HnsID = hnsresponse.Id
367367
genData[HNSID] = config.HnsID
368+
369+
} else {
370+
// Delete any stale HNS endpoints for this network.
371+
if endpoints, err := hcsshim.HNSListEndpointRequest(); err == nil {
372+
for _, ep := range endpoints {
373+
if ep.VirtualNetwork == config.HnsID {
374+
logrus.Infof("Removing stale HNS endpoint %s", ep.Id)
375+
_, err = hcsshim.HNSEndpointRequest("DELETE", ep.Id, "")
376+
if err != nil {
377+
logrus.Warnf("Error removing HNS endpoint %s", ep.Id)
378+
}
379+
}
380+
}
381+
} else {
382+
logrus.Warnf("Error listing HNS endpoints for network %s", config.HnsID)
383+
}
368384
}
369385

370386
n, err := d.getNetwork(id)

0 commit comments

Comments
 (0)