@@ -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
1616func 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 ,
0 commit comments