-
Notifications
You must be signed in to change notification settings - Fork 260
Prefix on nicv6 support #3657
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
Closed
NihaNallappagari
wants to merge
2
commits into
Azure:master
from
NihaNallappagari:prefixOnNicv6Support
Closed
Prefix on nicv6 support #3657
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -995,38 +995,85 @@ func (service *HTTPRestService) AssignAvailableIPConfigs(podInfo cns.PodInfo) ([ | |
| if numOfNCs == 0 { | ||
| return nil, ErrNoNCs | ||
| } | ||
|
|
||
| // Map used to get the number of IPFamilies across all NCs | ||
| ncIPFamilies := map[cns.IPFamily]struct{}{} | ||
| // Gets the IPFamilies from all NCs and store them in a map. This will be used to determine the number of IPs to return | ||
| for ncID := range service.state.ContainerStatus { | ||
| if len(ncIPFamilies) == 2 { | ||
| break | ||
| } | ||
|
|
||
| for _, secIPConfig := range service.state.ContainerStatus[ncID].CreateNetworkContainerRequest.SecondaryIPConfigs { | ||
| if len(ncIPFamilies) == 2 { | ||
| break | ||
| } | ||
|
|
||
| ip := net.ParseIP(secIPConfig.IPAddress) | ||
| if ip == nil { | ||
| continue | ||
| } | ||
|
|
||
| if ip.To4() != nil { | ||
| ncIPFamilies[cns.IPv4] = struct{}{} | ||
| } else { | ||
| ncIPFamilies[cns.IPv6] = struct{}{} | ||
| } | ||
| } | ||
| } | ||
| // Makes sure we have at least one IPFamily across all NCs | ||
| numOfIPFamilies := len(ncIPFamilies) | ||
|
|
||
| numberOfIPs := numOfNCs | ||
| if numOfIPFamilies != 0 { | ||
| numberOfIPs = numOfIPFamilies | ||
| } | ||
|
|
||
| service.Lock() | ||
| defer service.Unlock() | ||
| // Creates a slice of PodIpInfo with the size as number of NCs to hold the result for assigned IP configs | ||
| podIPInfo := make([]cns.PodIpInfo, numOfNCs) | ||
| podIPInfo := make([]cns.PodIpInfo, numberOfIPs) | ||
|
Comment on lines
+1027
to
+1035
|
||
| // This map is used to store whether or not we have found an available IP from an NC when looping through the pool | ||
| ipsToAssign := make(map[string]cns.IPConfigurationStatus) | ||
|
|
||
| // Searches for available IPs in the pool | ||
| for _, ipState := range service.PodIPConfigState { | ||
| // check if an IP from this NC is already set side for assignment. | ||
| if _, ncAlreadyMarkedForAssignment := ipsToAssign[ipState.NCID]; ncAlreadyMarkedForAssignment { | ||
|
|
||
| // get the IPFamily of the current ipState | ||
| var ipStateFamily cns.IPFamily | ||
| if net.ParseIP(ipState.IPAddress).To4() != nil { | ||
| ipStateFamily = cns.IPv4 | ||
| } else { | ||
| ipStateFamily = cns.IPv6 | ||
| } | ||
|
|
||
| key := generateAssignedIPKey(ipState.NCID, ipStateFamily) | ||
|
|
||
| // check if the IP with the same family type exists already | ||
| if _, ncIPFamilyAlreadyMarkedForAssignment := ipsToAssign[key]; ncIPFamilyAlreadyMarkedForAssignment { | ||
| continue | ||
| } | ||
| // Checks if the current IP is available | ||
| if ipState.GetState() != types.Available { | ||
| continue | ||
| } | ||
| ipsToAssign[ipState.NCID] = ipState | ||
| // Once one IP per container is found break out of the loop and stop searching | ||
| if len(ipsToAssign) == numOfNCs { | ||
| ipsToAssign[key] = ipState | ||
| // Once numberOfIPs per container is found break out of the loop and stop searching | ||
| if len(ipsToAssign) == numberOfIPs { | ||
| break | ||
| } | ||
| } | ||
|
|
||
| // Checks to make sure we found one IP for each NC | ||
| if len(ipsToAssign) != numOfNCs { | ||
| // Checks to make sure we found one IP for each NCxIPFamily | ||
| if len(ipsToAssign) != numberOfIPs { | ||
| for ncID := range service.state.ContainerStatus { | ||
| if _, found := ipsToAssign[ncID]; found { | ||
| continue | ||
| for ipFamily := range ncIPFamilies { | ||
| if _, found := ipsToAssign[generateAssignedIPKey(ncID, ipFamily)]; found { | ||
| continue | ||
| } | ||
| return podIPInfo, errors.Errorf("not enough IPs available of type %s for %s, waiting on Azure CNS to allocate more with NC Status: %s", | ||
| ipFamily, ncID, string(service.state.ContainerStatus[ncID].CreateNetworkContainerRequest.NCStatus)) | ||
| } | ||
| return podIPInfo, errors.Errorf("not enough IPs available for %s, waiting on Azure CNS to allocate more with NC Status: %s", | ||
| ncID, string(service.state.ContainerStatus[ncID].CreateNetworkContainerRequest.NCStatus)) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -1061,10 +1108,14 @@ func (service *HTTPRestService) AssignAvailableIPConfigs(podInfo cns.PodInfo) ([ | |
| return podIPInfo, fmt.Errorf("not enough IPs available, waiting on Azure CNS to allocate more") | ||
| } | ||
|
|
||
| logger.Printf("[AssignDesiredIPConfigs] Successfully assigned IPs for pod %+v", podInfo) | ||
| logger.Printf("[AssignAvailableIPConfigs] Successfully assigned IPs for pod %+v", podInfo) | ||
| return podIPInfo, nil | ||
| } | ||
|
|
||
| func generateAssignedIPKey(ncID string, ipFamily cns.IPFamily) string { | ||
| return fmt.Sprintf("%s_%s", ncID, string(ipFamily)) | ||
| } | ||
|
|
||
| // If IPConfigs are already assigned to the pod, it returns that else it returns the available ipconfigs. | ||
| func requestIPConfigsHelper(service *HTTPRestService, req cns.IPConfigsRequest) ([]cns.PodIpInfo, error) { | ||
| // check if ipconfigs already assigned to this pod and return if exists or error | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
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.
[nitpick] Consider adding a comment explaining why a /32 primary IP is excluded from the secondary IP configurations to improve code clarity.