From 83cbfb8948f9ef8b9985d70261f3aec9b83bb1bb Mon Sep 17 00:00:00 2001 From: Madhan Raj Mookkandy Date: Thu, 30 Mar 2017 20:31:34 -0700 Subject: [PATCH 1/2] Enable Hot Add/Remove of Network Endpoints for Windows Signed-off-by: Madhan Raj Mookkandy --- drivers/windows/windows.go | 22 ++++++++++++++++++---- osl/namespace_windows.go | 7 +------ sandbox.go | 7 ------- sandbox_others.go | 12 ++++++++++++ sandbox_windows.go | 12 ++++++++++++ 5 files changed, 43 insertions(+), 17 deletions(-) create mode 100644 sandbox_others.go create mode 100644 sandbox_windows.go diff --git a/drivers/windows/windows.go b/drivers/windows/windows.go index 0b15b2aa49..0a4d9b9666 100644 --- a/drivers/windows/windows.go +++ b/drivers/windows/windows.go @@ -66,6 +66,7 @@ type hnsEndpoint struct { nid string profileID string Type string + containerID string macAddress net.HardwareAddr epOption *endpointOption // User specified parameters epConnectivity *EndpointConnectivity // User specified parameters @@ -730,7 +731,15 @@ func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, return err } - // This is just a stub for now + endpoint.containerID = sboxKey + + err = hcsshim.HotAttachEndpoint(endpoint.containerID, endpoint.profileID) + if err != nil { + // If container doesn't exists in hcs, do not throw error for hot add/remove + if err != hcsshim.ErrComputeSystemDoesNotExist { + return err + } + } jinfo.DisableGatewayService() return nil @@ -744,13 +753,18 @@ func (d *driver) Leave(nid, eid string) error { } // Ensure that the endpoint exists - _, err = network.getEndpoint(eid) + endpoint, err := network.getEndpoint(eid) if err != nil { return err } - // This is just a stub for now - + err = hcsshim.HotDetachEndpoint(endpoint.containerID, endpoint.profileID) + if err != nil { + // If container doesn't exists in hcs, do not throw error for hot add/remove + if err != hcsshim.ErrComputeSystemDoesNotExist { + return err + } + } return nil } diff --git a/osl/namespace_windows.go b/osl/namespace_windows.go index bfdca30bcb..49503c00ff 100644 --- a/osl/namespace_windows.go +++ b/osl/namespace_windows.go @@ -5,12 +5,7 @@ import "testing" // GenerateKey generates a sandbox key based on the passed // container id. func GenerateKey(containerID string) string { - maxLen := 12 - if len(containerID) < maxLen { - maxLen = len(containerID) - } - - return containerID[:maxLen] + return containerID } // NewSandbox provides a new sandbox instance created in an os specific way diff --git a/sandbox.go b/sandbox.go index 315195ebb8..db0ffb0d1d 100644 --- a/sandbox.go +++ b/sandbox.go @@ -144,13 +144,6 @@ func (sb *sandbox) ContainerID() string { return sb.containerID } -func (sb *sandbox) Key() string { - if sb.config.useDefaultSandBox { - return osl.GenerateKey("default") - } - return osl.GenerateKey(sb.id) -} - func (sb *sandbox) Labels() map[string]interface{} { sb.Lock() defer sb.Unlock() diff --git a/sandbox_others.go b/sandbox_others.go new file mode 100644 index 0000000000..89232415de --- /dev/null +++ b/sandbox_others.go @@ -0,0 +1,12 @@ +// +build !windows + +package libnetwork + +import "github.com/docker/libnetwork/osl" + +func (sb *sandbox) Key() string { + if sb.config.useDefaultSandBox { + return osl.GenerateKey("default") + } + return osl.GenerateKey(sb.id) +} diff --git a/sandbox_windows.go b/sandbox_windows.go new file mode 100644 index 0000000000..e2ce30e675 --- /dev/null +++ b/sandbox_windows.go @@ -0,0 +1,12 @@ +// +build windows + +package libnetwork + +import "github.com/docker/libnetwork/osl" + +func (sb *sandbox) Key() string { + if sb.config.useDefaultSandBox { + return osl.GenerateKey("default") + } + return osl.GenerateKey(sb.containerID) +} From f3afa07751466203e71a888aaf1acc49c49330a9 Mon Sep 17 00:00:00 2001 From: Pradip Dhara Date: Mon, 2 Oct 2017 16:08:59 -0700 Subject: [PATCH 2/2] Changing containerID to sandboxID based off feedback/conversation with Madhu. Signed-off-by: Pradip Dhara --- drivers/windows/windows.go | 22 ++++++++++++++-------- sandbox.go | 7 +++++++ sandbox_others.go | 12 ------------ sandbox_windows.go | 12 ------------ 4 files changed, 21 insertions(+), 32 deletions(-) delete mode 100644 sandbox_others.go delete mode 100644 sandbox_windows.go diff --git a/drivers/windows/windows.go b/drivers/windows/windows.go index 0a4d9b9666..16d1ca2cb9 100644 --- a/drivers/windows/windows.go +++ b/drivers/windows/windows.go @@ -62,11 +62,17 @@ type EndpointConnectivity struct { } type hnsEndpoint struct { - id string - nid string - profileID string - Type string - containerID string + id string + nid string + profileID string + Type string + //Note: Currently, the sandboxID is the same as the containerID since windows does + //not expose the sandboxID. + //In the future, windows will support a proper sandboxID that is different + //than the containerID. + //Therefore, we are using sandboxID now, so that we won't have to change this code + //when windows properly supports a sandboxID. + sandboxID string macAddress net.HardwareAddr epOption *endpointOption // User specified parameters epConnectivity *EndpointConnectivity // User specified parameters @@ -731,9 +737,9 @@ func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo, return err } - endpoint.containerID = sboxKey + endpoint.sandboxID = sboxKey - err = hcsshim.HotAttachEndpoint(endpoint.containerID, endpoint.profileID) + err = hcsshim.HotAttachEndpoint(endpoint.sandboxID, endpoint.profileID) if err != nil { // If container doesn't exists in hcs, do not throw error for hot add/remove if err != hcsshim.ErrComputeSystemDoesNotExist { @@ -758,7 +764,7 @@ func (d *driver) Leave(nid, eid string) error { return err } - err = hcsshim.HotDetachEndpoint(endpoint.containerID, endpoint.profileID) + err = hcsshim.HotDetachEndpoint(endpoint.sandboxID, endpoint.profileID) if err != nil { // If container doesn't exists in hcs, do not throw error for hot add/remove if err != hcsshim.ErrComputeSystemDoesNotExist { diff --git a/sandbox.go b/sandbox.go index db0ffb0d1d..315195ebb8 100644 --- a/sandbox.go +++ b/sandbox.go @@ -144,6 +144,13 @@ func (sb *sandbox) ContainerID() string { return sb.containerID } +func (sb *sandbox) Key() string { + if sb.config.useDefaultSandBox { + return osl.GenerateKey("default") + } + return osl.GenerateKey(sb.id) +} + func (sb *sandbox) Labels() map[string]interface{} { sb.Lock() defer sb.Unlock() diff --git a/sandbox_others.go b/sandbox_others.go deleted file mode 100644 index 89232415de..0000000000 --- a/sandbox_others.go +++ /dev/null @@ -1,12 +0,0 @@ -// +build !windows - -package libnetwork - -import "github.com/docker/libnetwork/osl" - -func (sb *sandbox) Key() string { - if sb.config.useDefaultSandBox { - return osl.GenerateKey("default") - } - return osl.GenerateKey(sb.id) -} diff --git a/sandbox_windows.go b/sandbox_windows.go deleted file mode 100644 index e2ce30e675..0000000000 --- a/sandbox_windows.go +++ /dev/null @@ -1,12 +0,0 @@ -// +build windows - -package libnetwork - -import "github.com/docker/libnetwork/osl" - -func (sb *sandbox) Key() string { - if sb.config.useDefaultSandBox { - return osl.GenerateKey("default") - } - return osl.GenerateKey(sb.containerID) -}