-
Notifications
You must be signed in to change notification settings - Fork 883
Tasks connected to a swarm network will have 1 endpoint on windows RS3. #1900
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,11 @@ import ( | |
| "net" | ||
|
|
||
| "github.com/Microsoft/hcsshim" | ||
| "github.com/docker/docker/pkg/system" | ||
| "github.com/docker/libnetwork/driverapi" | ||
| "github.com/docker/libnetwork/drivers/windows" | ||
| "github.com/docker/libnetwork/netlabel" | ||
| "github.com/docker/libnetwork/types" | ||
| "github.com/sirupsen/logrus" | ||
| ) | ||
|
|
||
|
|
@@ -15,12 +19,14 @@ type endpointTable map[string]*endpoint | |
| const overlayEndpointPrefix = "overlay/endpoint" | ||
|
|
||
| type endpoint struct { | ||
| id string | ||
| nid string | ||
| profileId string | ||
| remote bool | ||
| mac net.HardwareAddr | ||
| addr *net.IPNet | ||
| id string | ||
| nid string | ||
| profileID string | ||
| remote bool | ||
| mac net.HardwareAddr | ||
| addr *net.IPNet | ||
| disablegateway bool | ||
| portMapping []types.PortBinding // Operation port bindings | ||
| } | ||
|
|
||
| func validateID(nid, eid string) error { | ||
|
|
@@ -71,7 +77,7 @@ func (n *network) removeEndpointWithAddress(addr *net.IPNet) { | |
|
|
||
| if networkEndpoint != nil { | ||
| logrus.Debugf("Removing stale endpoint from HNS") | ||
| _, err := hcsshim.HNSEndpointRequest("DELETE", networkEndpoint.profileId, "") | ||
| _, err := hcsshim.HNSEndpointRequest("DELETE", networkEndpoint.profileID, "") | ||
|
|
||
| if err != nil { | ||
| logrus.Debugf("Failed to delete stale overlay endpoint (%s) from hns", networkEndpoint.id[0:7]) | ||
|
|
@@ -96,7 +102,7 @@ func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo, | |
| logrus.Debugf("Deleting stale endpoint %s", eid) | ||
| n.deleteEndpoint(eid) | ||
|
|
||
| _, err := hcsshim.HNSEndpointRequest("DELETE", ep.profileId, "") | ||
| _, err := hcsshim.HNSEndpointRequest("DELETE", ep.profileID, "") | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
@@ -113,17 +119,19 @@ func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo, | |
| return fmt.Errorf("create endpoint was not passed interface IP address") | ||
| } | ||
|
|
||
| if s := n.getSubnetforIP(ep.addr); s == nil { | ||
| return fmt.Errorf("no matching subnet for IP %q in network %q\n", ep.addr, nid) | ||
| s := n.getSubnetforIP(ep.addr) | ||
| if s == nil { | ||
| return fmt.Errorf("no matching subnet for IP %q in network %q", ep.addr, nid) | ||
| } | ||
|
|
||
| // Todo: Add port bindings and qos policies here | ||
|
|
||
| hnsEndpoint := &hcsshim.HNSEndpoint{ | ||
| Name: eid, | ||
| VirtualNetwork: n.hnsId, | ||
| VirtualNetwork: n.hnsID, | ||
| IPAddress: ep.addr.IP, | ||
| EnableInternalDNS: true, | ||
| GatewayAddress: s.gwIP.String(), | ||
| } | ||
|
|
||
| if ep.mac != nil { | ||
|
|
@@ -141,6 +149,31 @@ func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo, | |
|
|
||
| hnsEndpoint.Policies = append(hnsEndpoint.Policies, paPolicy) | ||
|
|
||
| if system.GetOSVersion().Build > 16236 { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will move this check into hns.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lgtm |
||
| natPolicy, err := json.Marshal(hcsshim.PaPolicy{ | ||
| Type: "OutBoundNAT", | ||
| }) | ||
|
|
||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| hnsEndpoint.Policies = append(hnsEndpoint.Policies, natPolicy) | ||
|
|
||
| epConnectivity, err := windows.ParseEndpointConnectivity(epOptions) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| pbPolicy, err := windows.ConvertPortBindings(epConnectivity.PortBindings) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| hnsEndpoint.Policies = append(hnsEndpoint.Policies, pbPolicy...) | ||
|
|
||
| ep.disablegateway = true | ||
| } | ||
|
|
||
| configurationb, err := json.Marshal(hnsEndpoint) | ||
| if err != nil { | ||
| return err | ||
|
|
@@ -151,7 +184,7 @@ func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo, | |
| return err | ||
| } | ||
|
|
||
| ep.profileId = hnsresponse.Id | ||
| ep.profileID = hnsresponse.Id | ||
|
|
||
| if ep.mac == nil { | ||
| ep.mac, err = net.ParseMAC(hnsresponse.MacAddress) | ||
|
|
@@ -164,6 +197,12 @@ func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo, | |
| } | ||
| } | ||
|
|
||
| ep.portMapping, err = windows.ParsePortBindingPolicies(hnsresponse.Policies) | ||
| if err != nil { | ||
| hcsshim.HNSEndpointRequest("DELETE", hnsresponse.Id, "") | ||
| return err | ||
| } | ||
|
|
||
| n.addEndpoint(ep) | ||
|
|
||
| return nil | ||
|
|
@@ -186,7 +225,7 @@ func (d *driver) DeleteEndpoint(nid, eid string) error { | |
|
|
||
| n.deleteEndpoint(eid) | ||
|
|
||
| _, err := hcsshim.HNSEndpointRequest("DELETE", ep.profileId, "") | ||
| _, err := hcsshim.HNSEndpointRequest("DELETE", ep.profileID, "") | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
@@ -210,7 +249,17 @@ func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, erro | |
| } | ||
|
|
||
| data := make(map[string]interface{}, 1) | ||
| data["hnsid"] = ep.profileId | ||
| data["hnsid"] = ep.profileID | ||
| data["AllowUnqualifiedDNSQuery"] = true | ||
|
|
||
| if ep.portMapping != nil { | ||
| // Return a copy of the operational data | ||
| pmc := make([]types.PortBinding, 0, len(ep.portMapping)) | ||
| for _, pm := range ep.portMapping { | ||
| pmc = append(pmc, pm.GetCopy()) | ||
| } | ||
| data[netlabel.PortMap] = pmc | ||
| } | ||
|
|
||
| return data, nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eventually, we should look at converging type endpoint struct and type hnsEnpoint struct in windows pkg so they can be shared by all windows and overlay drivers. But, I think that is outside the scope of this PR.