2525 ErrStoreEmpty = errors .New ("empty endpoint state store" )
2626 ErrParsePodIPFailed = errors .New ("failed to parse pod's ip" )
2727 ErrNoNCs = errors .New ("no NCs found in the CNS internal state" )
28- ErrNoIPFamilies = errors .New ("No IP Families found on NCs" )
2928 ErrOptManageEndpointState = errors .New ("CNS is not set to manage the endpoint state" )
3029 ErrEndpointStateNotFound = errors .New ("endpoint state could not be found in the statefile" )
3130 ErrGetAllNCResponseEmpty = errors .New ("failed to get NC responses from statefile" )
@@ -107,7 +106,6 @@ func (service *HTTPRestService) requestIPConfigHandlerHelper(ctx context.Context
107106 }
108107
109108 podIPInfoResult = append (podIPInfoResult , podIPInfo ... )
110-
111109 return & cns.IPConfigsResponse {
112110 Response : cns.Response {
113111 ReturnCode : types .Success ,
@@ -1003,8 +1001,20 @@ func (service *HTTPRestService) AssignAvailableIPConfigs(podInfo cns.PodInfo) ([
10031001
10041002 // Gets the IPFamilies from all NCs and store them in a map. This will be used to determine the number of IPs to return
10051003 for ncID := range service .state .ContainerStatus {
1006- for ipFamily := range service .state .ContainerStatus [ncID ].CreateNetworkContainerRequest .IPFamilies {
1007- ipFamilies [ipFamily ] = struct {}{}
1004+ if len (ipFamilies ) == 2 {
1005+ break
1006+ }
1007+
1008+ for _ , secIPConfig := range service .state .ContainerStatus [ncID ].CreateNetworkContainerRequest .SecondaryIPConfigs {
1009+ if len (ipFamilies ) == 2 {
1010+ break
1011+ }
1012+
1013+ if net .ParseIP (secIPConfig .IPAddress ).To4 () != nil {
1014+ ipFamilies [cns .IPv4Family ] = struct {}{}
1015+ } else {
1016+ ipFamilies [cns .IPv6Family ] = struct {}{}
1017+ }
10081018 }
10091019 }
10101020
@@ -1034,7 +1044,7 @@ func (service *HTTPRestService) AssignAvailableIPConfigs(podInfo cns.PodInfo) ([
10341044 ipStateFamily = cns .IPv6Family
10351045 }
10361046
1037- key := ipState .NCID + string ( ipStateFamily )
1047+ key := generateAssignedIPKey ( ipState .NCID , ipStateFamily )
10381048
10391049 // check if the IP with the same family type exists already
10401050 if _ , ncIPFamilyAlreadyMarkedForAssignment := ipsToAssign [key ]; ncIPFamilyAlreadyMarkedForAssignment {
@@ -1054,8 +1064,8 @@ func (service *HTTPRestService) AssignAvailableIPConfigs(podInfo cns.PodInfo) ([
10541064 // Checks to make sure we found one IP for each NCxIPFamily
10551065 if len (ipsToAssign ) != numberOfIPs {
10561066 for ncID := range service .state .ContainerStatus {
1057- for ipFamily := range service . state . ContainerStatus [ ncID ]. CreateNetworkContainerRequest . IPFamilies {
1058- if _ , found := ipsToAssign [ncID + string ( ipFamily )]; found {
1067+ for ipFamily := range ipFamilies {
1068+ if _ , found := ipsToAssign [generateAssignedIPKey ( ncID , ipFamily )]; found {
10591069 continue
10601070 }
10611071 return podIPInfo , errors .Errorf ("not enough IPs available of type %s for %s, waiting on Azure CNS to allocate more with NC Status: %s" ,
@@ -1099,6 +1109,10 @@ func (service *HTTPRestService) AssignAvailableIPConfigs(podInfo cns.PodInfo) ([
10991109 return podIPInfo , nil
11001110}
11011111
1112+ func generateAssignedIPKey (ncID string , ipFamily cns.IPFamily ) string {
1113+ return fmt .Sprintf ("%s_%s" , ncID , string (ipFamily ))
1114+ }
1115+
11021116// If IPConfigs are already assigned to the pod, it returns that else it returns the available ipconfigs.
11031117func requestIPConfigsHelper (service * HTTPRestService , req cns.IPConfigsRequest ) ([]cns.PodIpInfo , error ) {
11041118 // check if ipconfigs already assigned to this pod and return if exists or error
0 commit comments