Skip to content

Commit 384e9d8

Browse files
committed
fixes overlay issue
1 parent 3964d0f commit 384e9d8

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")
@@ -990,13 +991,25 @@ func (service *HTTPRestService) AssignDesiredIPConfigs(podInfo cns.PodInfo, desi
990991
// Assigns an available IP from each NC on the NNC. If there is one NC then we expect to only have one IP return
991992
// In the case of dualstack we would expect to have one IPv6 from one NC and one IPv4 from a second NC
992993
func (service *HTTPRestService) AssignAvailableIPConfigs(podInfo cns.PodInfo) ([]cns.PodIpInfo, error) {
993-
// Gets the number of IPFamilies expected to be returned.
994-
numOfIPFamilies := len(service.IPFamilies)
994+
// Gets the number of IPFamilies expected to be returned across all NCs
995+
ipFamilies := map[IPFamily]struct{}{}
995996

996-
if numOfIPFamilies == 0 {
997-
// TODO: replace with it's own error
997+
// checks to make sure we have at least one NC
998+
if len(service.state.ContainerStatus) == 0 {
998999
return nil, ErrNoNCs
9991000
}
1001+
1002+
for ncID := range service.state.ContainerStatus {
1003+
for ipFamily := range service.state.ContainerStatus[ncID].CreateNetworkContainerRequest.IPFamilies {
1004+
ipFamilies[ipFamily] = struct{}{}
1005+
}
1006+
}
1007+
1008+
numOfIPFamilies := len(ipFamilies)
1009+
if numOfIPFamilies == 0 {
1010+
return nil, ErrNoIPFamilies
1011+
}
1012+
10001013
service.Lock()
10011014
defer service.Unlock()
10021015
// Creates a slice of PodIpInfo with the size as number of NCs to hold the result for assigned IP configs
@@ -1006,29 +1019,37 @@ func (service *HTTPRestService) AssignAvailableIPConfigs(podInfo cns.PodInfo) ([
10061019

10071020
// Searches for available IPs in the pool
10081021
for _, ipState := range service.PodIPConfigState {
1022+
// get the IPFamily of the current ipState
1023+
var ipStateFamily IPFamily
1024+
if net.ParseIP(ipState.IPAddress).To4() != nil {
1025+
ipStateFamily = IPv4Family
1026+
} else {
1027+
ipStateFamily = IPv6Family
1028+
}
1029+
10091030
// check if the IP with the same family type exists already
1010-
if _, IPFamilyAlreadyMarkedForAssignment := ipsToAssign[net.ParseIP(ipState.IPAddress).To4() == nil]; IPFamilyAlreadyMarkedForAssignment {
1031+
if _, IPFamilyAlreadyMarkedForAssignment := ipsToAssign[ipStateFamily]; IPFamilyAlreadyMarkedForAssignment {
10111032
continue
10121033
}
10131034
// Checks if the current IP is available
10141035
if ipState.GetState() != types.Available {
10151036
continue
10161037
}
1017-
ipsToAssign[net.ParseIP(ipState.IPAddress).To4() == nil] = ipState
1018-
// Once one IP per container is found break out of the loop and stop searching
1038+
ipsToAssign[ipStateFamily] = ipState
1039+
// Once one IP per family is found break out of the loop and stop searching
10191040
if len(ipsToAssign) == numOfIPFamilies {
10201041
break
10211042
}
10221043
}
10231044

1024-
// Checks to make sure we found one IP for each NC
1045+
// Checks to make sure we found one IP for each IPFamily
10251046
if len(ipsToAssign) != numOfIPFamilies {
1026-
for _, ipFamily := range service.IPFamilies {
1027-
if _, found := ipsToAssign[ipFamily]; found {
1047+
for ncID := range service.state.ContainerStatus {
1048+
if _, found := ipsToAssign[ncID]; found {
10281049
continue
10291050
}
1030-
return podIPInfo, errors.Errorf("not enough IPs available of type %s, waiting on Azure CNS to allocate more with NC Status: %s",
1031-
ipFamily, string(service.state.ContainerStatus[ncID].CreateNetworkContainerRequest.NCStatus))
1051+
return podIPInfo, errors.Errorf("not enough IPs available for %s, waiting on Azure CNS to allocate more with NC Status: %s",
1052+
ncID, string(service.state.ContainerStatus[ncID].CreateNetworkContainerRequest.NCStatus))
10321053
}
10331054
}
10341055

cns/restserver/util.go

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

186-
service.IPFamilies = req.IPFamilies
187-
188186
switch req.NetworkContainerType {
189187
case cns.AzureContainerInstance:
190188
fallthrough

0 commit comments

Comments
 (0)