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

Merge pull request #43858 from olljanat/22.06_backport_restore-custom-nat-networks

[22.06 backport] Windows: Re-create custom NAT networks after restart if missing from HNS
This commit is contained in:
Sebastiaan van Stijn 2022-07-25 12:23:14 +02:00 committed by GitHub
commit dcbd68a1d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -264,6 +264,35 @@ func (daemon *Daemon) initNetworkController(activeSandboxes map[string]interface
}
if !found {
// non-default nat networks should be re-created if missing from HNS
if v.Type() == "nat" && v.Name() != "nat" {
_, _, v4Conf, v6Conf := v.Info().IpamConfig()
netOption := map[string]string{}
for k, v := range v.Info().DriverOptions() {
if k != winlibnetwork.NetworkName && k != winlibnetwork.HNSID {
netOption[k] = v
}
}
name := v.Name()
id := v.ID()
err = v.Delete()
if err != nil {
logrus.Errorf("Error occurred when removing network %v", err)
}
_, err := daemon.netController.NewNetwork("nat", name, id,
libnetwork.NetworkOptionGeneric(options.Generic{
netlabel.GenericData: netOption,
}),
libnetwork.NetworkOptionIpam("default", "", v4Conf, v6Conf, nil),
)
if err != nil {
logrus.Errorf("Error occurred when creating network %v", err)
}
continue
}
// global networks should not be deleted by local HNS
if v.Info().Scope() != datastore.GlobalScope {
err = v.Delete()