Skip to content

Commit 7241b09

Browse files
committed
updates to IPFamily and dependencies
1 parent 1fa64d3 commit 7241b09

File tree

6 files changed

+19
-34
lines changed

6 files changed

+19
-34
lines changed

cns/NetworkContainerContract.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"strconv"
88
"strings"
99

10-
"github.com/Azure/azure-container-networking/cns/restserver"
1110
"github.com/Azure/azure-container-networking/cns/types"
1211
"github.com/Azure/azure-container-networking/crd/nodenetworkconfig/api/v1alpha"
1312
"github.com/google/uuid"
@@ -128,7 +127,7 @@ type CreateNetworkContainerRequest struct {
128127
EndpointPolicies []NetworkContainerRequestPolicies
129128
NCStatus v1alpha.NCStatus
130129
NetworkInterfaceInfo NetworkInterfaceInfo //nolint // introducing new field for backendnic, to be used later by cni code
131-
IPFamilies map[restserver.IPFamily]struct{}
130+
IPFamilies map[IPFamily]struct{}
132131
}
133132

134133
func (req *CreateNetworkContainerRequest) Validate() error {
@@ -744,3 +743,10 @@ type NodeRegisterRequest struct {
744743
NumCores int
745744
NmAgentSupportedApis []string
746745
}
746+
747+
type IPFamily string
748+
749+
const (
750+
IPv4Family IPFamily = "ipv4"
751+
IPv6Family IPFamily = "ipv6"
752+
)

cns/kubecontroller/nodenetworkconfig/conversion_linux.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"strconv"
77

88
"github.com/Azure/azure-container-networking/cns"
9-
"github.com/Azure/azure-container-networking/cns/restserver"
109
"github.com/Azure/azure-container-networking/crd/nodenetworkconfig/api/v1alpha"
1110
"github.com/pkg/errors"
1211
)
@@ -17,7 +16,7 @@ import (
1716
//nolint:gocritic //ignore hugeparam
1817
func createNCRequestFromStaticNCHelper(nc v1alpha.NetworkContainer, primaryIPPrefix netip.Prefix, subnet cns.IPSubnet) (*cns.CreateNetworkContainerRequest, error) {
1918
secondaryIPConfigs := map[string]cns.SecondaryIPConfig{}
20-
ipFamilies := map[restserver.IPFamily]struct{}{}
19+
ipFamilies := map[cns.IPFamily]struct{}{}
2120

2221
// iterate through all IP addresses in the subnet described by primaryPrefix and
2322
// add them to the request as secondary IPConfigs.
@@ -30,9 +29,9 @@ func createNCRequestFromStaticNCHelper(nc v1alpha.NetworkContainer, primaryIPPre
3029
}
3130
// adds the IPFamily of the primary CIDR to the set
3231
if primaryIPPrefix.Addr().Is4() {
33-
ipFamilies[restserver.IPv4Family] = struct{}{}
32+
ipFamilies[cns.IPv4Family] = struct{}{}
3433
} else {
35-
ipFamilies[restserver.IPv6Family] = struct{}{}
34+
ipFamilies[cns.IPv6Family] = struct{}{}
3635
}
3736

3837
// Add IPs from CIDR block to the secondary IPConfigs
@@ -55,9 +54,9 @@ func createNCRequestFromStaticNCHelper(nc v1alpha.NetworkContainer, primaryIPPre
5554
}
5655
// adds the IPFamily of the secondary CIDR to the set
5756
if cidrPrefix.Addr().Is4() {
58-
ipFamilies[restserver.IPv4Family] = struct{}{}
57+
ipFamilies[cns.IPv4Family] = struct{}{}
5958
} else {
60-
ipFamilies[restserver.IPv6Family] = struct{}{}
59+
ipFamilies[cns.IPv6Family] = struct{}{}
6160
}
6261
}
6362
}

cns/restserver/const.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,3 @@ const (
1313
dncApiVersion = "?api-version=2018-03-01"
1414
nmaAPICallTimeout = 2 * time.Second
1515
)
16-
17-
type IPFamily string
18-
19-
const (
20-
IPv4Family IPFamily = "ipv4"
21-
IPv6Family IPFamily = "ipv6"
22-
)

cns/restserver/ipam.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ func (service *HTTPRestService) AssignDesiredIPConfigs(podInfo cns.PodInfo, desi
992992
// In the case of dualstack we would expect to have one IPv6 from one NC and one IPv4 from a second NC
993993
func (service *HTTPRestService) AssignAvailableIPConfigs(podInfo cns.PodInfo) ([]cns.PodIpInfo, error) {
994994
// Map used to get the number of IPFamilies across all NCs
995-
ipFamilies := map[IPFamily]struct{}{}
995+
ipFamilies := map[cns.IPFamily]struct{}{}
996996

997997
// checks to make sure we have at least one NC
998998
if len(service.state.ContainerStatus) == 0 {
@@ -1015,16 +1015,16 @@ func (service *HTTPRestService) AssignAvailableIPConfigs(podInfo cns.PodInfo) ([
10151015
// Creates a slice of PodIpInfo with the size as number of NCs to hold the result for assigned IP configs
10161016
podIPInfo := make([]cns.PodIpInfo, numOfIPFamilies)
10171017
// This map is used to store whether or not we have found an available IP from an NC when looping through the pool
1018-
ipsToAssign := make(map[IPFamily]cns.IPConfigurationStatus)
1018+
ipsToAssign := make(map[cns.IPFamily]cns.IPConfigurationStatus)
10191019

10201020
// Searches for available IPs in the pool
10211021
for _, ipState := range service.PodIPConfigState {
10221022
// get the IPFamily of the current ipState
1023-
var ipStateFamily IPFamily
1023+
var ipStateFamily cns.IPFamily
10241024
if net.ParseIP(ipState.IPAddress).To4() != nil {
1025-
ipStateFamily = IPv4Family
1025+
ipStateFamily = cns.IPv4Family
10261026
} else {
1027-
ipStateFamily = IPv6Family
1027+
ipStateFamily = cns.IPv6Family
10281028
}
10291029

10301030
// check if the IP with the same family type exists already

cns/restserver/ipusage.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,6 @@ import (
55
"github.com/Azure/azure-container-networking/cns/types"
66
)
77

8-
type ipState struct {
9-
// allocatedIPs are all the IPs given to CNS by DNC.
10-
allocatedIPs int64
11-
// assignedIPs are the IPs CNS gives to Pods.
12-
assignedIPs int64
13-
// availableIPs are the IPs in state "Available".
14-
availableIPs int64
15-
// programmingIPs are the IPs in state "PendingProgramming".
16-
programmingIPs int64
17-
// releasingIPs are the IPs in state "PendingReleasr".
18-
releasingIPs int64
19-
}
20-
218
func (service *HTTPRestService) buildIPState() *ipState {
229
service.Lock()
2310
defer service.Unlock()

cns/restserver/restserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ type HTTPRestService struct {
8080
PnpIDByMacAddress map[string]string
8181
imdsClient imdsClient
8282
nodesubnetIPFetcher *nodesubnet.IPFetcher
83-
IPFamilies []IPFamily
83+
IPFamilies []cns.IPFamily
8484
}
8585

8686
type CNIConflistGenerator interface {

0 commit comments

Comments
 (0)