Skip to content

Commit b4c3cbc

Browse files
committed
fixes overlay issue
1 parent 4a37b99 commit b4c3cbc

File tree

3 files changed

+36
-18
lines changed

3 files changed

+36
-18
lines changed

cns/kubecontroller/nodenetworkconfig/conversion_linux.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,14 @@ func createNCRequestFromStaticNCHelper(nc v1alpha.NetworkContainer, primaryIPPre
2121

2222
// iterate through all IP addresses in the subnet described by primaryPrefix and
2323
// add them to the request as secondary IPConfigs.
24-
// TODO: we need to pass in a pointer to an IPFamilies slice to this function and add the family of the IPs added in
25-
// Here we check the primary CIDR which is needed for overlay and VNET Block
2624
for addr := primaryIPPrefix.Masked().Addr(); primaryIPPrefix.Contains(addr); addr = addr.Next() {
2725
secondaryIPConfigs[addr.String()] = cns.SecondaryIPConfig{
2826
IPAddress: addr.String(),
2927
NCVersion: int(nc.Version),
3028
}
3129

3230
}
33-
31+
// adds the IPFamily of the primary CIDR to the set
3432
if primaryIPPrefix.Addr().Is4() {
3533
ipFamilies[restserver.IPv4Family] = struct{}{}
3634
} else {
@@ -55,6 +53,7 @@ func createNCRequestFromStaticNCHelper(nc v1alpha.NetworkContainer, primaryIPPre
5553
NCVersion: int(nc.Version),
5654
}
5755
}
56+
// adds the IPFamily of the secondary CIDR to the set
5857
if cidrPrefix.Addr().Is4() {
5958
ipFamilies[restserver.IPv4Family] = struct{}{}
6059
} else {
@@ -63,7 +62,7 @@ func createNCRequestFromStaticNCHelper(nc v1alpha.NetworkContainer, primaryIPPre
6362
}
6463
}
6564

66-
fmt.Printf("IPFamilies on NC %+v and %+v", nc.ID, ipFamilies)
65+
fmt.Printf("IPFamilies found on NC %+v are %+v", nc.ID, ipFamilies)
6766

6867
return &cns.CreateNetworkContainerRequest{
6968
HostPrimaryIP: nc.NodeIP,

cns/restserver/ipam.go

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var (
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")
2829
ErrOptManageEndpointState = errors.New("CNS is not set to manage the endpoint state")
2930
ErrEndpointStateNotFound = errors.New("endpoint state could not be found in the statefile")
3031
ErrGetAllNCResponseEmpty = errors.New("failed to get NC responses from statefile")
@@ -979,13 +980,25 @@ func (service *HTTPRestService) AssignDesiredIPConfigs(podInfo cns.PodInfo, desi
979980
// Assigns an available IP from each NC on the NNC. If there is one NC then we expect to only have one IP return
980981
// In the case of dualstack we would expect to have one IPv6 from one NC and one IPv4 from a second NC
981982
func (service *HTTPRestService) AssignAvailableIPConfigs(podInfo cns.PodInfo) ([]cns.PodIpInfo, error) {
982-
// Gets the number of IPFamilies expected to be returned.
983-
numOfIPFamilies := len(service.IPFamilies)
983+
// Gets the number of IPFamilies expected to be returned across all NCs
984+
ipFamilies := map[IPFamily]struct{}{}
984985

985-
if numOfIPFamilies == 0 {
986-
// TODO: replace with it's own error
986+
// checks to make sure we have at least one NC
987+
if len(service.state.ContainerStatus) == 0 {
987988
return nil, ErrNoNCs
988989
}
990+
991+
for ncID := range service.state.ContainerStatus {
992+
for ipFamily := range service.state.ContainerStatus[ncID].CreateNetworkContainerRequest.IPFamilies {
993+
ipFamilies[ipFamily] = struct{}{}
994+
}
995+
}
996+
997+
numOfIPFamilies := len(ipFamilies)
998+
if numOfIPFamilies == 0 {
999+
return nil, ErrNoIPFamilies
1000+
}
1001+
9891002
service.Lock()
9901003
defer service.Unlock()
9911004
// Creates a slice of PodIpInfo with the size as number of NCs to hold the result for assigned IP configs
@@ -995,29 +1008,37 @@ func (service *HTTPRestService) AssignAvailableIPConfigs(podInfo cns.PodInfo) ([
9951008

9961009
// Searches for available IPs in the pool
9971010
for _, ipState := range service.PodIPConfigState {
1011+
// get the IPFamily of the current ipState
1012+
var ipStateFamily IPFamily
1013+
if net.ParseIP(ipState.IPAddress).To4() != nil {
1014+
ipStateFamily = IPv4Family
1015+
} else {
1016+
ipStateFamily = IPv6Family
1017+
}
1018+
9981019
// check if the IP with the same family type exists already
999-
if _, IPFamilyAlreadyMarkedForAssignment := ipsToAssign[net.ParseIP(ipState.IPAddress).To4() == nil]; IPFamilyAlreadyMarkedForAssignment {
1020+
if _, IPFamilyAlreadyMarkedForAssignment := ipsToAssign[ipStateFamily]; IPFamilyAlreadyMarkedForAssignment {
10001021
continue
10011022
}
10021023
// Checks if the current IP is available
10031024
if ipState.GetState() != types.Available {
10041025
continue
10051026
}
1006-
ipsToAssign[net.ParseIP(ipState.IPAddress).To4() == nil] = ipState
1007-
// Once one IP per container is found break out of the loop and stop searching
1027+
ipsToAssign[ipStateFamily] = ipState
1028+
// Once one IP per family is found break out of the loop and stop searching
10081029
if len(ipsToAssign) == numOfIPFamilies {
10091030
break
10101031
}
10111032
}
10121033

1013-
// Checks to make sure we found one IP for each NC
1034+
// Checks to make sure we found one IP for each IPFamily
10141035
if len(ipsToAssign) != numOfIPFamilies {
1015-
for _, ipFamily := range service.IPFamilies {
1016-
if _, found := ipsToAssign[ipFamily]; found {
1036+
for ncID := range service.state.ContainerStatus {
1037+
if _, found := ipsToAssign[ncID]; found {
10171038
continue
10181039
}
1019-
return podIPInfo, errors.Errorf("not enough IPs available of type %s, waiting on Azure CNS to allocate more with NC Status: %s",
1020-
ipFamily, string(service.state.ContainerStatus[ncID].CreateNetworkContainerRequest.NCStatus))
1040+
return podIPInfo, errors.Errorf("not enough IPs available for %s, waiting on Azure CNS to allocate more with NC Status: %s",
1041+
ncID, string(service.state.ContainerStatus[ncID].CreateNetworkContainerRequest.NCStatus))
10211042
}
10221043
}
10231044

cns/restserver/util.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,6 @@ func (service *HTTPRestService) saveNetworkContainerGoalState(req cns.CreateNetw
176176
VfpUpdateComplete: vfpUpdateComplete,
177177
}
178178

179-
service.IPFamilies = req.IPFamilies
180-
181179
switch req.NetworkContainerType {
182180
case cns.AzureContainerInstance:
183181
fallthrough

0 commit comments

Comments
 (0)