Skip to content

Commit 06577fe

Browse files
committed
Fix capacity calculation
The previous capacity calculation incorrectly only counted CloudPrivateIPConfigs that had the status set. This is racy and can lead to artificially reduced capacity. Fix it by accounting for all CloudPrivateIPConfigs that are or were assigned to the matching node. Signed-off-by: Patryk Diak <[email protected]>
1 parent 8384756 commit 06577fe

File tree

8 files changed

+75
-83
lines changed

8 files changed

+75
-83
lines changed

pkg/cloudprovider/aws.go

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import (
1414
"github.com/aws/aws-sdk-go/aws/endpoints"
1515
"github.com/aws/aws-sdk-go/aws/session"
1616
"github.com/aws/aws-sdk-go/service/ec2"
17-
v1 "github.com/openshift/api/cloudnetwork/v1"
18-
"github.com/openshift/cloud-network-config-controller/pkg/cloudprivateipconfig"
1917
"github.com/pkg/errors"
2018
corev1 "k8s.io/api/core/v1"
2119
"k8s.io/apimachinery/pkg/util/sets"
@@ -181,7 +179,7 @@ func (a *AWS) ReleasePrivateIP(ip net.IP, node *corev1.Node) error {
181179
}
182180
}
183181

184-
func (a *AWS) GetNodeEgressIPConfiguration(node *corev1.Node, cloudPrivateIPConfigs []*v1.CloudPrivateIPConfig) ([]*NodeEgressIPConfiguration, error) {
182+
func (a *AWS) GetNodeEgressIPConfiguration(node *corev1.Node, cpicIPs sets.Set[string]) ([]*NodeEgressIPConfiguration, error) {
185183
instance, err := a.getInstance(node)
186184
if err != nil {
187185
return nil, err
@@ -214,10 +212,8 @@ func (a *AWS) GetNodeEgressIPConfiguration(node *corev1.Node, cloudPrivateIPConf
214212
if v6Subnet != nil {
215213
config.IFAddr.IPv6 = v6Subnet.String()
216214
}
217-
capV4, capV6, err := a.getCapacity(instanceV4Capacity, instanceV6Capacity, networkInterface, cloudPrivateIPConfigs)
218-
if err != nil {
219-
return nil, err
220-
}
215+
216+
capV4, capV6 := a.getCapacity(instanceV4Capacity, instanceV6Capacity, networkInterface, cpicIPs)
221217
config.Capacity = capacity{
222218
IPv4: ptr.To(capV4),
223219
IPv6: ptr.To(capV6),
@@ -304,32 +300,28 @@ func (a *AWS) getSubnet(networkInterface *ec2.InstanceNetworkInterface) (*net.IP
304300

305301
// AWS uses a variable capacity per instance type, see:
306302
// https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-eni.html#AvailableIpPerENI
307-
// Hence we need to retrieve that and then subtract the amount already assigned
308-
// by default.
309-
func (a *AWS) getCapacity(instanceV4Capacity, instanceV6Capacity int, networkInterface *ec2.InstanceNetworkInterface, cloudPrivateIPConfigs []*v1.CloudPrivateIPConfig) (int, int, error) {
303+
// Capacity represents the number of IPs available for consumption.
304+
// We calculate this as: instance_limit - IPs_consumed_by_non_CPIC_sources
305+
// This way, CNCC managed IPs (regardless of their status) don't reduce capacity.
306+
func (a *AWS) getCapacity(instanceV4Capacity, instanceV6Capacity int, networkInterface *ec2.InstanceNetworkInterface, cpicIPs sets.Set[string]) (int, int) {
310307
currentIPv4Usage, currentIPv6Usage := 0, 0
311308
for _, assignedIPv6 := range networkInterface.Ipv6Addresses {
312309
if assignedIP := net.ParseIP(*assignedIPv6.Ipv6Address); assignedIP != nil {
313-
currentIPv6Usage++
310+
if !cpicIPs.Has(assignedIP.String()) {
311+
currentIPv6Usage++
312+
}
314313
}
315314
}
315+
316316
for _, assignedIPv4 := range networkInterface.PrivateIpAddresses {
317317
if assignedIP := net.ParseIP(*assignedIPv4.PrivateIpAddress); assignedIP != nil {
318-
currentIPv4Usage++
319-
}
320-
}
321-
for _, cloudPrivateIPConfig := range cloudPrivateIPConfigs {
322-
_, ipFamily, err := cloudprivateipconfig.NameToIP(cloudPrivateIPConfig.Name)
323-
if err != nil {
324-
return 0, 0, err
325-
}
326-
if ipFamily == cloudprivateipconfig.IPv4 {
327-
instanceV4Capacity++
328-
} else if ipFamily == cloudprivateipconfig.IPv6 {
329-
instanceV6Capacity++
318+
if !cpicIPs.Has(assignedIP.String()) {
319+
currentIPv4Usage++
320+
}
330321
}
331322
}
332-
return instanceV4Capacity - currentIPv4Usage, instanceV6Capacity - currentIPv6Usage, nil
323+
324+
return instanceV4Capacity - currentIPv4Usage, instanceV6Capacity - currentIPv6Usage
333325
}
334326

335327
func (a *AWS) getNetworkInterfaces(instance *ec2.Instance) ([]*ec2.InstanceNetworkInterface, error) {

pkg/cloudprovider/azure.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import (
2121
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork/v6"
2222
azureapi "github.com/Azure/go-autorest/autorest/azure"
2323
"github.com/Azure/msi-dataplane/pkg/dataplane"
24-
v1 "github.com/openshift/api/cloudnetwork/v1"
2524
configv1 "github.com/openshift/api/config/v1"
2625
corev1 "k8s.io/api/core/v1"
26+
"k8s.io/apimachinery/pkg/util/sets"
2727
"k8s.io/klog/v2"
2828
utilnet "k8s.io/utils/net"
2929
)
@@ -322,7 +322,7 @@ func (a *Azure) ReleasePrivateIP(ip net.IP, node *corev1.Node) error {
322322
return a.waitForCompletion(poller)
323323
}
324324

325-
func (a *Azure) GetNodeEgressIPConfiguration(node *corev1.Node, cloudPrivateIPConfigs []*v1.CloudPrivateIPConfig) ([]*NodeEgressIPConfiguration, error) {
325+
func (a *Azure) GetNodeEgressIPConfiguration(node *corev1.Node, cpicIPs sets.Set[string]) ([]*NodeEgressIPConfiguration, error) {
326326
instance, err := a.getInstance(node)
327327
if err != nil {
328328
return nil, err
@@ -352,7 +352,7 @@ func (a *Azure) GetNodeEgressIPConfiguration(node *corev1.Node, cloudPrivateIPCo
352352
}
353353
config.Capacity = capacity{
354354
// IPv4 and IPv6 fields not used by Azure (uses IP-family-agnostic capacity)
355-
IP: ptr.To(a.getCapacity(networkInterface, len(cloudPrivateIPConfigs))),
355+
IP: ptr.To(a.getCapacity(networkInterface, cpicIPs)),
356356
}
357357
return []*NodeEgressIPConfiguration{config}, nil
358358
}
@@ -408,18 +408,17 @@ func (a *Azure) getSubnet(networkInterface armnetwork.Interface) (*net.IPNet, *n
408408
// We need to retrieve the amounts assigned to the node by default and subtract
409409
// that from the default 256 value. Note: there is also a "Private IP addresses
410410
// per virtual network" quota, but that's 65.536, so we can skip that.
411-
func (a *Azure) getCapacity(networkInterface armnetwork.Interface, cloudPrivateIPsCount int) int {
412-
currentIPv4Usage, currentIPv6Usage := 0, 0
411+
func (a *Azure) getCapacity(networkInterface armnetwork.Interface, cpicIPs sets.Set[string]) int {
412+
currentIPUsage := 0
413413
for _, ipConfiguration := range networkInterface.Properties.IPConfigurations {
414414
if assignedIP := net.ParseIP(ptr.Deref(ipConfiguration.Properties.PrivateIPAddress, "")); assignedIP != nil {
415-
if utilnet.IsIPv4(assignedIP) {
416-
currentIPv4Usage++
417-
} else {
418-
currentIPv6Usage++
415+
if !cpicIPs.Has(assignedIP.String()) {
416+
currentIPUsage++
419417
}
420418
}
421419
}
422-
return defaultAzurePrivateIPCapacity + cloudPrivateIPsCount - currentIPv4Usage - currentIPv6Usage
420+
421+
return defaultAzurePrivateIPCapacity - currentIPUsage
423422
}
424423

425424
// This is what the node's providerID looks like on Azure

pkg/cloudprovider/cloudprovider.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313
apifeatures "github.com/openshift/api/features"
1414
"github.com/openshift/library-go/pkg/operator/configobserver/featuregates"
1515

16-
v1 "github.com/openshift/api/cloudnetwork/v1"
1716
corev1 "k8s.io/api/core/v1"
17+
"k8s.io/apimachinery/pkg/util/sets"
1818
)
1919

2020
var (
@@ -60,7 +60,9 @@ type CloudProviderIntf interface {
6060
// for all instance types and IP families (GCP, Azure) or variable per
6161
// instance and IP family (AWS), also: the interface is either keyed by name
6262
// (GCP) or ID (Azure, AWS).
63-
GetNodeEgressIPConfiguration(node *corev1.Node, cloudPrivateIPConfigs []*v1.CloudPrivateIPConfig) ([]*NodeEgressIPConfiguration, error)
63+
// The cpicIPs parameter is a set of IP addresses that are
64+
// managed by CloudPrivateIPConfigs and should be excluded from capacity calculations.
65+
GetNodeEgressIPConfiguration(node *corev1.Node, cpicIPs sets.Set[string]) ([]*NodeEgressIPConfiguration, error)
6466
}
6567

6668
// CloudProviderWithMoveIntf is additional interface that can be added to cloud

pkg/cloudprovider/cloudprovider_fake.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"net"
66
"time"
77

8-
v1 "github.com/openshift/api/cloudnetwork/v1"
98
corev1 "k8s.io/api/core/v1"
9+
"k8s.io/apimachinery/pkg/util/sets"
1010
)
1111

1212
type FakeCloudProvider struct {
@@ -63,7 +63,7 @@ func (f *FakeCloudProvider) waitForCompletion() error {
6363
return nil
6464
}
6565

66-
func (f *FakeCloudProvider) GetNodeEgressIPConfiguration(node *corev1.Node, cloudPrivateIPConfigs []*v1.CloudPrivateIPConfig) ([]*NodeEgressIPConfiguration, error) {
66+
func (f *FakeCloudProvider) GetNodeEgressIPConfiguration(node *corev1.Node, cpicIPs sets.Set[string]) ([]*NodeEgressIPConfiguration, error) {
6767
if f.mockErrorOnGetNodeEgressIPConfiguration {
6868
return nil, fmt.Errorf("Get node egress IP configuration failed")
6969
}

pkg/cloudprovider/gcp.go

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ import (
77
"net/url"
88
"strings"
99

10-
v1 "github.com/openshift/api/cloudnetwork/v1"
1110
google "google.golang.org/api/compute/v1"
1211
"google.golang.org/api/option"
1312
corev1 "k8s.io/api/core/v1"
14-
utilnet "k8s.io/utils/net"
13+
"k8s.io/apimachinery/pkg/util/sets"
1514
"k8s.io/utils/ptr"
1615
)
1716

@@ -155,7 +154,7 @@ func (g *GCP) ReleasePrivateIP(ip net.IP, node *corev1.Node) error {
155154
return g.waitForCompletion(project, zone, operation.Name)
156155
}
157156

158-
func (g *GCP) GetNodeEgressIPConfiguration(node *corev1.Node, cloudPrivateIPConfigs []*v1.CloudPrivateIPConfig) ([]*NodeEgressIPConfiguration, error) {
157+
func (g *GCP) GetNodeEgressIPConfiguration(node *corev1.Node, cpicIPs sets.Set[string]) ([]*NodeEgressIPConfiguration, error) {
159158
_, _, instance, err := g.getInstance(node)
160159
if err != nil {
161160
return nil, fmt.Errorf("error retrieving instance associated with node, err: %v", err)
@@ -184,7 +183,7 @@ func (g *GCP) GetNodeEgressIPConfiguration(node *corev1.Node, cloudPrivateIPConf
184183
}
185184
config.Capacity = capacity{
186185
// IPv4 and IPv6 fields not used by GCP (uses IP-family-agnostic capacity)
187-
IP: ptr.To(g.getCapacity(networkInterface, len(cloudPrivateIPConfigs))),
186+
IP: ptr.To(g.getCapacity(networkInterface, cpicIPs)),
188187
}
189188
return []*NodeEgressIPConfiguration{config}, nil //nolint:staticcheck
190189
}
@@ -235,25 +234,22 @@ func (g *GCP) getSubnet(networkInterface *google.NetworkInterface) (*net.IPNet,
235234

236235
// Note: there is also a global "alias IP per VPC quota", but OpenShift clusters on
237236
// GCP seem to have that value defined to 15,000. So we can skip that.
238-
func (g *GCP) getCapacity(networkInterface *google.NetworkInterface, cloudPrivateIPsCount int) int {
239-
currentIPv4Usage := 0
240-
currentIPv6Usage := 0
237+
func (g *GCP) getCapacity(networkInterface *google.NetworkInterface, cpicIPs sets.Set[string]) int {
238+
currentIPUsage := 0
241239
for _, aliasIPRange := range networkInterface.AliasIpRanges {
240+
var aliasIP net.IP
242241
if assignedIP := net.ParseIP(aliasIPRange.IpCidrRange); assignedIP != nil {
243-
if utilnet.IsIPv4(assignedIP) {
244-
currentIPv4Usage++
245-
} else {
246-
currentIPv6Usage++
247-
}
242+
aliasIP = assignedIP
248243
} else if _, assignedSubnet, err := net.ParseCIDR(aliasIPRange.IpCidrRange); err == nil {
249-
if utilnet.IsIPv4CIDR(assignedSubnet) {
250-
currentIPv4Usage++
251-
} else {
252-
currentIPv6Usage++
253-
}
244+
aliasIP = assignedSubnet.IP
245+
}
246+
247+
if aliasIP != nil && !cpicIPs.Has(aliasIP.String()) {
248+
currentIPUsage++
254249
}
255250
}
256-
return defaultGCPPrivateIPCapacity + cloudPrivateIPsCount - currentIPv4Usage - currentIPv6Usage
251+
252+
return defaultGCPPrivateIPCapacity - currentIPUsage
257253
}
258254

259255
// getInstance retrieves the GCP instance referred by the Node object.

pkg/cloudprovider/openstack.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@ import (
2222
neutronsubnets "github.com/gophercloud/gophercloud/v2/openstack/networking/v2/subnets"
2323
"github.com/gophercloud/gophercloud/v2/pagination"
2424
"github.com/gophercloud/utils/v2/openstack/clientconfig"
25-
v1 "github.com/openshift/api/cloudnetwork/v1"
26-
"github.com/openshift/cloud-network-config-controller/pkg/cloudprivateipconfig"
2725
"gopkg.in/yaml.v2"
2826
corev1 "k8s.io/api/core/v1"
2927
apierrors "k8s.io/apimachinery/pkg/api/errors"
3028
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29+
"k8s.io/apimachinery/pkg/util/sets"
3130
"k8s.io/client-go/util/retry"
3231
"k8s.io/klog/v2"
3332
utilnet "k8s.io/utils/net"
@@ -473,7 +472,7 @@ func (o *OpenStack) ReleasePrivateIP(ip net.IP, node *corev1.Node) error {
473472
// GetNodeEgressIPConfiguration retrieves the egress IP configuration for
474473
// the node, following the convention the cloud uses. This means
475474
// specifically for OpenStack that the interface is keyed by the port's neutron UUID.
476-
func (o *OpenStack) GetNodeEgressIPConfiguration(node *corev1.Node, cloudPrivateIPConfigs []*v1.CloudPrivateIPConfig) ([]*NodeEgressIPConfiguration, error) {
475+
func (o *OpenStack) GetNodeEgressIPConfiguration(node *corev1.Node, cpicIPs sets.Set[string]) ([]*NodeEgressIPConfiguration, error) {
477476
if node == nil {
478477
return nil, fmt.Errorf("invalid nil pointer provided for node when trying to get node EgressIP configuration")
479478
}
@@ -492,7 +491,7 @@ func (o *OpenStack) GetNodeEgressIPConfiguration(node *corev1.Node, cloudPrivate
492491
var configurations []*NodeEgressIPConfiguration
493492
for _, p := range serverPorts {
494493
// Retrieve configuration for this port.
495-
config, err := o.getNeutronPortNodeEgressIPConfiguration(p, cloudPrivateIPConfigs)
494+
config, err := o.getNeutronPortNodeEgressIPConfiguration(p, cpicIPs)
496495
if err != nil {
497496
return nil, err
498497
}
@@ -553,7 +552,7 @@ func (o *OpenStack) GetNodeEgressIPConfiguration(node *corev1.Node, cloudPrivate
553552
// neutron operates as there is no such thing as a per port quota or limit. Therefore we set a ceiling of
554553
// `openstackMaxCapacity`. The number of unique IP addresses in allowed_address_pair and fixed_ips is subtracted from
555554
// that ceiling.
556-
func (o *OpenStack) getNeutronPortNodeEgressIPConfiguration(p neutronports.Port, cloudPrivateIPConfigs []*v1.CloudPrivateIPConfig) (*NodeEgressIPConfiguration, error) {
555+
func (o *OpenStack) getNeutronPortNodeEgressIPConfiguration(p neutronports.Port, cpicIPs sets.Set[string]) (*NodeEgressIPConfiguration, error) {
557556
var ipv4, ipv6 string
558557
var err error
559558
var ip net.IP
@@ -590,12 +589,9 @@ func (o *OpenStack) getNeutronPortNodeEgressIPConfiguration(p neutronports.Port,
590589
}
591590
// Loop over all cloudPrivateIPConfigs and check if they are part of this ipnet.
592591
// If the IP is contained in the ipnet, increase cloudPrivateIPsCount.
593-
for _, cpic := range cloudPrivateIPConfigs {
594-
cip, _, err := cloudprivateipconfig.NameToIP(cpic.Name)
595-
if err != nil {
596-
return nil, err
597-
}
598-
if ipnet.Contains(cip) {
592+
for ipStr := range cpicIPs {
593+
cip := net.ParseIP(ipStr)
594+
if cip != nil && ipnet.Contains(cip) {
599595
cloudPrivateIPsCount++
600596
}
601597
}

pkg/cloudprovider/openstack_test.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
neutronsubnets "github.com/gophercloud/gophercloud/v2/openstack/networking/v2/subnets"
1919
th "github.com/gophercloud/gophercloud/v2/testhelper"
2020
testclient "github.com/gophercloud/gophercloud/v2/testhelper/client"
21-
v1 "github.com/openshift/api/cloudnetwork/v1"
2221
corev1 "k8s.io/api/core/v1"
2322
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2423
"k8s.io/apimachinery/pkg/util/sets"
@@ -1017,7 +1016,7 @@ func TestGetNeutronPortNodeEgressIPConfiguration(t *testing.T) {
10171016
tcs := []struct {
10181017
port neutronports.Port
10191018
nodeEgressIPConfig NodeEgressIPConfiguration
1020-
cloudPrivateIPConfigs []*v1.CloudPrivateIPConfig
1019+
cloudPrivateIPConfigs []string
10211020
errString string
10221021
}{
10231022
{
@@ -1045,11 +1044,8 @@ func TestGetNeutronPortNodeEgressIPConfiguration(t *testing.T) {
10451044
IP: ptr.To(openstackMaxCapacity + 3 - 2), // excluding 2 allowed_address_pairs configured on the port.
10461045
},
10471046
},
1048-
// Configure cloudPrivateIPConfigs with 3 ips are within neutron subnet, 1 ip outside neutron subnet.
1049-
cloudPrivateIPConfigs: []*v1.CloudPrivateIPConfig{{ObjectMeta: metav1.ObjectMeta{
1050-
Name: "192.0.2.10"}}, {ObjectMeta: metav1.ObjectMeta{Name: "2000..1"}},
1051-
{ObjectMeta: metav1.ObjectMeta{Name: "2000..2"}},
1052-
{ObjectMeta: metav1.ObjectMeta{Name: "10.10.10.1"}}},
1047+
// Configure IPs with 3 ips are within neutron subnet, 1 ip outside neutron subnet.
1048+
cloudPrivateIPConfigs: []string{"192.0.2.10", "2000::1", "2000::2", "10.10.10.1"},
10531049
},
10541050
{
10551051
port: portMap["aafecceb-d986-42b6-8ea7-449c7cacb7d9"],
@@ -1062,7 +1058,8 @@ func TestGetNeutronPortNodeEgressIPConfiguration(t *testing.T) {
10621058
}
10631059

10641060
for i, tc := range tcs {
1065-
nodeEgressIPConfig, err := o.getNeutronPortNodeEgressIPConfiguration(tc.port, tc.cloudPrivateIPConfigs)
1061+
cpicIPs := sets.New[string](tc.cloudPrivateIPConfigs...)
1062+
nodeEgressIPConfig, err := o.getNeutronPortNodeEgressIPConfiguration(tc.port, cpicIPs)
10661063
if err != nil {
10671064
if !strings.Contains(err.Error(), tc.errString) {
10681065
t.Fatalf("TestGetNeutronPortNodeEgressIPConfiguration(%d): Received unexpected error, err: %q, expected: %q", i, err, tc.errString)

pkg/controller/node/node_controller.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
v1 "k8s.io/api/core/v1"
1111
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1212
"k8s.io/apimachinery/pkg/labels"
13+
"k8s.io/apimachinery/pkg/util/sets"
1314
coreinformers "k8s.io/client-go/informers/core/v1"
1415
"k8s.io/client-go/kubernetes"
1516
corelisters "k8s.io/client-go/listers/core/v1"
@@ -22,6 +23,7 @@ import (
2223
cloudnetworkinformers "github.com/openshift/client-go/cloudnetwork/informers/externalversions/cloudnetwork/v1"
2324
cloudnetworklisters "github.com/openshift/client-go/cloudnetwork/listers/cloudnetwork/v1"
2425
cloudprovider "github.com/openshift/cloud-network-config-controller/pkg/cloudprovider"
26+
"github.com/openshift/cloud-network-config-controller/pkg/cloudprivateipconfig"
2527
controller "github.com/openshift/cloud-network-config-controller/pkg/controller"
2628
)
2729

@@ -116,17 +118,25 @@ func (n *NodeController) SyncHandler(key string) error {
116118
if err != nil {
117119
return fmt.Errorf("error listing cloud private ip config, err: %v", err)
118120
}
119-
// Filter out cloudPrivateIPConfigs assigned to node (key) and write the entry
120-
// into same slice starting from index 0, finally chop off unwanted entries
121-
// when passing it into GetNodeEgressIPConfiguration.
122-
index := 0
121+
// Filter cloudPrivateIPConfigs that are associated with this node.
122+
// Include CPICs where spec.node OR status.node matches, to handle transitions
123+
// during move operations and avoid counting CPIC IPs as "consumed capacity".
124+
// We need both spec.node and status.node because during a move operation:
125+
// - The IP might still be on the old node (status.node) while spec.node has changed
126+
// - The IP might already be on the new node (spec.node) while status.node hasn't updated
127+
// Build set of CPIC-managed IP addresses for this node
128+
// Include CPICs where spec.node OR status.node matches to handle transitions
129+
cpicIPs := sets.New[string]()
123130
for _, cloudPrivateIPConfig := range cloudPrivateIPConfigs {
124-
if isAssignedCloudPrivateIPConfigOnNode(cloudPrivateIPConfig, key) {
125-
cloudPrivateIPConfigs[index] = cloudPrivateIPConfig
126-
index++
131+
if cloudPrivateIPConfig.Spec.Node == key || cloudPrivateIPConfig.Status.Node == key {
132+
ip, _, err := cloudprivateipconfig.NameToIP(cloudPrivateIPConfig.Name)
133+
if err != nil {
134+
return fmt.Errorf("error parsing CloudPrivateIPConfig %s: %v", cloudPrivateIPConfig.Name, err)
135+
}
136+
cpicIPs.Insert(ip.String())
127137
}
128138
}
129-
nodeEgressIPConfigs, err := n.cloudProviderClient.GetNodeEgressIPConfiguration(node, cloudPrivateIPConfigs[:index])
139+
nodeEgressIPConfigs, err := n.cloudProviderClient.GetNodeEgressIPConfiguration(node, cpicIPs)
130140
if err != nil {
131141
return fmt.Errorf("error retrieving the private IP configuration for node: %s, err: %v", node.Name, err)
132142
}

0 commit comments

Comments
 (0)