-
Notifications
You must be signed in to change notification settings - Fork 260
Enable outboundNAT for Windows containers. #86
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
Changes from all commits
d862858
bee152a
8563233
a40d480
ea892db
c048ab2
3a302a0
e656627
07fbec6
6be42c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,16 +14,71 @@ import ( | |
| "github.com/Microsoft/hcsshim" | ||
| ) | ||
|
|
||
| // ConstructEpName constructs endpoint name from netNsPath. | ||
| func ConstructEpName(containerID string, netNsPath string, ifName string) (string, string) { | ||
| infraEpName, workloadEpName := "", "" | ||
|
|
||
| if len(containerID) > 8 { | ||
| containerID = containerID[:8] | ||
| } | ||
|
|
||
| if netNsPath != "" { | ||
| splits := strings.Split(netNsPath, ":") | ||
| // For workload containers, we extract its linking infrastructure container ID. | ||
| if len(splits) == 2 { | ||
| if len(splits[1]) > 8 { | ||
| splits[1] = splits[1][:8] | ||
| } | ||
| infraEpName = splits[1] + "-" + ifName | ||
| workloadEpName = containerID + "-" + ifName | ||
| } else { | ||
| // For infrastructure containers, we just use its container ID. | ||
| infraEpName = containerID + "-" + ifName | ||
| } | ||
| } | ||
| return infraEpName, workloadEpName | ||
| } | ||
|
|
||
| // newEndpointImpl creates a new endpoint in the network. | ||
| func (nw *network) newEndpointImpl(epInfo *EndpointInfo) (*endpoint, error) { | ||
| // Initialize HNS endpoint. | ||
| hnsEndpoint := &hcsshim.HNSEndpoint{ | ||
| Name: epInfo.Id, | ||
| // Get Infrastructure containerID. Handle ADD calls for workload container. | ||
| infraEpName, workloadEpName := ConstructEpName(epInfo.ContainerID, epInfo.NetNsPath, epInfo.IfName) | ||
|
|
||
| /* Handle consecutive ADD calls for infrastructure containers. | ||
| * This is a temporary work around for issue #57253 of Kubernetes. | ||
| * We can delete this if statement once they fix it. | ||
| * Issue link: https://github.com/kubernetes/kubernetes/issues/57253 | ||
| */ | ||
| if workloadEpName == "" { | ||
| if nw.Endpoints[infraEpName] != nil { | ||
| log.Printf("[net] Found existing endpoint %v, return immediately.", infraEpName) | ||
| return nw.Endpoints[infraEpName], nil | ||
| } | ||
| } | ||
|
|
||
| log.Printf("[net] infraEpName: %v", infraEpName) | ||
|
|
||
| hnsEndpoint, _ := hcsshim.GetHNSEndpointByName(infraEpName) | ||
| if hnsEndpoint != nil { | ||
| log.Printf("[net] Found existing endpoint through hcsshim%v", infraEpName) | ||
| log.Printf("[net] Attaching ep %v to container %v", hnsEndpoint.Id, epInfo.ContainerID) | ||
| if err := hcsshim.HotAttachEndpoint(epInfo.ContainerID, hnsEndpoint.Id); err != nil { | ||
| return nil, err | ||
| } | ||
| return nw.Endpoints[infraEpName], nil | ||
| } | ||
|
|
||
| hnsEndpoint = &hcsshim.HNSEndpoint{ | ||
| Name: infraEpName, | ||
| VirtualNetwork: nw.HnsId, | ||
| DNSSuffix: epInfo.DNS.Suffix, | ||
| DNSServerList: strings.Join(epInfo.DNS.Servers, ","), | ||
| } | ||
|
|
||
| //enable outbound NAT | ||
| var enableOutBoundNat = json.RawMessage(`{"Type": "OutBoundNAT"}`) | ||
|
Member
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. Do we have unit test for testing this function? If its there, can we add one to test this property is set?
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. I didn't write unit test for this. We can discuss this. |
||
| hnsEndpoint.Policies = append(hnsEndpoint.Policies, enableOutBoundNat) | ||
|
|
||
| // HNS currently supports only one IP address per endpoint. | ||
| if epInfo.IPAddresses != nil { | ||
| hnsEndpoint.IPAddress = epInfo.IPAddresses[0].IP | ||
|
|
@@ -55,7 +110,7 @@ func (nw *network) newEndpointImpl(epInfo *EndpointInfo) (*endpoint, error) { | |
|
|
||
| // Create the endpoint object. | ||
| ep := &endpoint{ | ||
| Id: epInfo.Id, | ||
| Id: infraEpName, | ||
| HnsId: hnsResponse.Id, | ||
| SandboxKey: epInfo.ContainerID, | ||
| IfName: epInfo.IfName, | ||
|
|
||
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.
remove this empty line also. not needed