Skip to content

Commit 67c36d5

Browse files
committed
Windows: Re-create custom NAT networks after restart if missing from HNS
Signed-off-by: Olli Janatuinen <[email protected]>
1 parent 2fbc307 commit 67c36d5

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

daemon/daemon_windows.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,35 @@ func (daemon *Daemon) initNetworkController(activeSandboxes map[string]interface
264264
}
265265

266266
if !found {
267+
// non-default nat networks should be re-created if missing from HNS
268+
if v.Type() == "nat" && v.Name() != "nat" {
269+
_, _, v4Conf, v6Conf := v.Info().IpamConfig()
270+
netOption := map[string]string{}
271+
for k, v := range v.Info().DriverOptions() {
272+
if k != winlibnetwork.NetworkName && k != winlibnetwork.HNSID {
273+
netOption[k] = v
274+
}
275+
}
276+
name := v.Name()
277+
id := v.ID()
278+
279+
err = v.Delete()
280+
if err != nil {
281+
logrus.Errorf("Error occurred when removing network %v", err)
282+
}
283+
284+
_, err := daemon.netController.NewNetwork("nat", name, id,
285+
libnetwork.NetworkOptionGeneric(options.Generic{
286+
netlabel.GenericData: netOption,
287+
}),
288+
libnetwork.NetworkOptionIpam("default", "", v4Conf, v6Conf, nil),
289+
)
290+
if err != nil {
291+
logrus.Errorf("Error occurred when creating network %v", err)
292+
}
293+
continue
294+
}
295+
267296
// global networks should not be deleted by local HNS
268297
if v.Info().Scope() != datastore.GlobalScope {
269298
err = v.Delete()

0 commit comments

Comments
 (0)