Skip to content

Commit 1f25704

Browse files
jaer-tsunJaeryn
andcommitted
fix: skip reserved IPs (#2060)
Co-authored-by: Jaeryn <[email protected]>
1 parent 243863d commit 1f25704

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

cns/kubecontroller/nodenetworkconfig/conversion_windows.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ import (
99
)
1010

1111
// createNCRequestFromStaticNCHelper generates a CreateNetworkContainerRequest from a static NetworkContainer.
12-
// If the NC's DefaultGateway is empty, it will set the 0th IP as the gateway IP and all remaining IPs as
13-
// secondary IPs. If the gateway is not empty, it will not reserve the 0th IP and add it as a secondary IP.
12+
// If the NC's DefaultGateway is empty and nc type is overlay, it will set the 2nd IP (*.1) as the gateway IP and all remaining IPs as
13+
// secondary IPs. If the gateway is not empty, it will not reserve the 2nd IP and add it as a secondary IP.
1414
//
1515
//nolint:gocritic //ignore hugeparam
1616
func createNCRequestFromStaticNCHelper(nc v1alpha.NetworkContainer, primaryIPPrefix netip.Prefix, subnet cns.IPSubnet) *cns.CreateNetworkContainerRequest {
1717
secondaryIPConfigs := map[string]cns.SecondaryIPConfig{}
18-
19-
// if NC DefaultGateway is empty, set the 0th IP to the gateway and add the rest of the IPs
20-
// as secondary IPs
21-
startingAddr := primaryIPPrefix.Masked().Addr() // the masked address is the 0th IP in the subnet
18+
// the masked address is the 0th IP in the subnet and startingAddr is the 2nd IP (*.1)
19+
startingAddr := primaryIPPrefix.Masked().Addr().Next()
20+
lastAddr := startingAddr
21+
// if NC DefaultGateway is empty, set the 2nd IP (*.1) to the gateway and add the rest of the IPs as secondary IPs
2222
if nc.DefaultGateway == "" {
2323
nc.DefaultGateway = startingAddr.String()
2424
startingAddr = startingAddr.Next()
@@ -31,7 +31,10 @@ func createNCRequestFromStaticNCHelper(nc v1alpha.NetworkContainer, primaryIPPre
3131
IPAddress: addr.String(),
3232
NCVersion: int(nc.Version),
3333
}
34+
lastAddr = addr
3435
}
36+
delete(secondaryIPConfigs, lastAddr.String())
37+
3538
return &cns.CreateNetworkContainerRequest{
3639
SecondaryIPConfigs: secondaryIPConfigs,
3740
NetworkContainerid: nc.ID,

cns/kubecontroller/nodenetworkconfig/conversion_windows_test.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,14 @@ var validOverlayRequest = &cns.CreateNetworkContainerRequest{
1313
PrefixLength: uint8(subnetPrefixLen),
1414
IPAddress: primaryIP,
1515
},
16-
GatewayIPAddress: "10.0.0.0",
16+
GatewayIPAddress: "10.0.0.1",
1717
},
1818
NetworkContainerid: ncID,
1919
NetworkContainerType: cns.Docker,
2020
SecondaryIPConfigs: map[string]cns.SecondaryIPConfig{
21-
"10.0.0.1": {
22-
IPAddress: "10.0.0.1",
23-
NCVersion: version,
24-
},
2521
"10.0.0.2": {
2622
IPAddress: "10.0.0.2",
27-
NCVersion: version,
28-
},
29-
"10.0.0.3": {
30-
IPAddress: "10.0.0.3",
31-
NCVersion: version,
23+
NCVersion: 0,
3224
},
3325
},
3426
}

0 commit comments

Comments
 (0)