Skip to content

Commit 68f1039

Browse files
authored
Merge pull request #1964 from pradipd/hotadd
Enable Hotadd support for windows
2 parents 6c51292 + f3afa07 commit 68f1039

2 files changed

Lines changed: 29 additions & 14 deletions

File tree

drivers/windows/windows.go

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,17 @@ type EndpointConnectivity struct {
6262
}
6363

6464
type hnsEndpoint struct {
65-
id string
66-
nid string
67-
profileID string
68-
Type string
65+
id string
66+
nid string
67+
profileID string
68+
Type string
69+
//Note: Currently, the sandboxID is the same as the containerID since windows does
70+
//not expose the sandboxID.
71+
//In the future, windows will support a proper sandboxID that is different
72+
//than the containerID.
73+
//Therefore, we are using sandboxID now, so that we won't have to change this code
74+
//when windows properly supports a sandboxID.
75+
sandboxID string
6976
macAddress net.HardwareAddr
7077
epOption *endpointOption // User specified parameters
7178
epConnectivity *EndpointConnectivity // User specified parameters
@@ -730,7 +737,15 @@ func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo,
730737
return err
731738
}
732739

733-
// This is just a stub for now
740+
endpoint.sandboxID = sboxKey
741+
742+
err = hcsshim.HotAttachEndpoint(endpoint.sandboxID, endpoint.profileID)
743+
if err != nil {
744+
// If container doesn't exists in hcs, do not throw error for hot add/remove
745+
if err != hcsshim.ErrComputeSystemDoesNotExist {
746+
return err
747+
}
748+
}
734749

735750
jinfo.DisableGatewayService()
736751
return nil
@@ -744,13 +759,18 @@ func (d *driver) Leave(nid, eid string) error {
744759
}
745760

746761
// Ensure that the endpoint exists
747-
_, err = network.getEndpoint(eid)
762+
endpoint, err := network.getEndpoint(eid)
748763
if err != nil {
749764
return err
750765
}
751766

752-
// This is just a stub for now
753-
767+
err = hcsshim.HotDetachEndpoint(endpoint.sandboxID, endpoint.profileID)
768+
if err != nil {
769+
// If container doesn't exists in hcs, do not throw error for hot add/remove
770+
if err != hcsshim.ErrComputeSystemDoesNotExist {
771+
return err
772+
}
773+
}
754774
return nil
755775
}
756776

osl/namespace_windows.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@ import "testing"
55
// GenerateKey generates a sandbox key based on the passed
66
// container id.
77
func GenerateKey(containerID string) string {
8-
maxLen := 12
9-
if len(containerID) < maxLen {
10-
maxLen = len(containerID)
11-
}
12-
13-
return containerID[:maxLen]
8+
return containerID
149
}
1510

1611
// NewSandbox provides a new sandbox instance created in an os specific way

0 commit comments

Comments
 (0)