Browse code

Swarm-mode overlay networking support for windows

Signed-off-by: msabansal <sabansal@microsoft.com>

msabansal authored on 2016/11/10 10:54:15
Showing 2 changed files
... ...
@@ -20,6 +20,7 @@ import (
20 20
 	"github.com/docker/docker/runconfig"
21 21
 	"github.com/docker/libnetwork"
22 22
 	nwconfig "github.com/docker/libnetwork/config"
23
+	"github.com/docker/libnetwork/datastore"
23 24
 	winlibnetwork "github.com/docker/libnetwork/drivers/windows"
24 25
 	"github.com/docker/libnetwork/netlabel"
25 26
 	"github.com/docker/libnetwork/options"
... ...
@@ -261,9 +262,12 @@ func (daemon *Daemon) initNetworkController(config *Config, activeSandboxes map[
261 261
 		}
262 262
 
263 263
 		if !found {
264
-			err = v.Delete()
265
-			if err != nil {
266
-				return nil, err
264
+			// global networks should not be deleted by local HNS
265
+			if v.Info().Scope() != datastore.GlobalScope {
266
+				err = v.Delete()
267
+				if err != nil {
268
+					logrus.Errorf("Error occurred when removing network %v", err)
269
+				}
267 270
 			}
268 271
 		}
269 272
 	}
... ...
@@ -300,6 +304,10 @@ func (daemon *Daemon) initNetworkController(config *Config, activeSandboxes map[
300 300
 
301 301
 		controller.WalkNetworks(s)
302 302
 		if n != nil {
303
+			// global networks should not be deleted by local HNS
304
+			if n.Info().Scope() == datastore.GlobalScope {
305
+				continue
306
+			}
303 307
 			v.Name = n.Name()
304 308
 			// This will not cause network delete from HNS as the network
305 309
 			// is not yet populated in the libnetwork windows driver
... ...
@@ -62,6 +62,7 @@ func (daemon *Daemon) getLibcontainerdCreateOptions(container *container.Contain
62 62
 	// Get endpoints for the libnetwork allocated networks to the container
63 63
 	var epList []string
64 64
 	AllowUnqualifiedDNSQuery := false
65
+	gwHNSID := ""
65 66
 	if container.NetworkSettings != nil {
66 67
 		for n := range container.NetworkSettings.Networks {
67 68
 			sn, err := daemon.FindNetwork(n)
... ...
@@ -78,6 +79,14 @@ func (daemon *Daemon) getLibcontainerdCreateOptions(container *container.Contain
78 78
 			if err != nil {
79 79
 				continue
80 80
 			}
81
+
82
+			if data["GW_INFO"] != nil {
83
+				gwInfo := data["GW_INFO"].(map[string]interface{})
84
+				if gwInfo["hnsid"] != nil {
85
+					gwHNSID = gwInfo["hnsid"].(string)
86
+				}
87
+			}
88
+
81 89
 			if data["hnsid"] != nil {
82 90
 				epList = append(epList, data["hnsid"].(string))
83 91
 			}
... ...
@@ -88,6 +97,10 @@ func (daemon *Daemon) getLibcontainerdCreateOptions(container *container.Contain
88 88
 		}
89 89
 	}
90 90
 
91
+	if gwHNSID != "" {
92
+		epList = append(epList, gwHNSID)
93
+	}
94
+
91 95
 	// Read and add credentials from the security options if a credential spec has been provided.
92 96
 	if container.HostConfig.SecurityOpt != nil {
93 97
 		for _, sOpt := range container.HostConfig.SecurityOpt {