Skip to content

Commit 8379c29

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 e10bfc5 commit 8379c29

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"
@@ -180,7 +178,7 @@ func (a *AWS) ReleasePrivateIP(ip net.IP, node *corev1.Node) error {
180178
}
181179
}
182180

183-
func (a *AWS) GetNodeEgressIPConfiguration(node *corev1.Node, cloudPrivateIPConfigs []*v1.CloudPrivateIPConfig) ([]*NodeEgressIPConfiguration, error) {
181+
func (a *AWS) GetNodeEgressIPConfiguration(node *corev1.Node, cpicIPs sets.Set[string]) ([]*NodeEgressIPConfiguration, error) {
184182
instance, err := a.getInstance(node)
185183
if err != nil {
186184
return nil, err
@@ -213,10 +211,8 @@ func (a *AWS) GetNodeEgressIPConfiguration(node *corev1.Node, cloudPrivateIPConf
213211
if v6Subnet != nil {
214212
config.IFAddr.IPv6 = v6Subnet.String()
215213
}
216-
capV4, capV6, err := a.getCapacity(instanceV4Capacity, instanceV6Capacity, networkInterface, cloudPrivateIPConfigs)
217-
if err != nil {
218-
return nil, err
219-
}
214+
215+
capV4, capV6 := a.getCapacity(instanceV4Capacity, instanceV6Capacity, networkInterface, cpicIPs)
220216
config.Capacity = capacity{
221217
IPv4: capV4,
222218
IPv6: capV6,
@@ -302,32 +298,28 @@ func (a *AWS) getSubnet(networkInterface *ec2.InstanceNetworkInterface) (*net.IP
302298

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

333325
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
@@ -351,7 +351,7 @@ func (a *Azure) GetNodeEgressIPConfiguration(node *corev1.Node, cloudPrivateIPCo
351351
config.IFAddr.IPv6 = v6Subnet.String()
352352
}
353353
config.Capacity = capacity{
354-
IP: a.getCapacity(networkInterface, len(cloudPrivateIPConfigs)),
354+
IP: a.getCapacity(networkInterface, cpicIPs),
355355
}
356356
return []*NodeEgressIPConfiguration{config}, nil
357357
}
@@ -407,18 +407,17 @@ func (a *Azure) getSubnet(networkInterface armnetwork.Interface) (*net.IPNet, *n
407407
// We need to retrieve the amounts assigned to the node by default and subtract
408408
// that from the default 256 value. Note: there is also a "Private IP addresses
409409
// per virtual network" quota, but that's 65.536, so we can skip that.
410-
func (a *Azure) getCapacity(networkInterface armnetwork.Interface, cloudPrivateIPsCount int) int {
411-
currentIPv4Usage, currentIPv6Usage := 0, 0
410+
func (a *Azure) getCapacity(networkInterface armnetwork.Interface, cpicIPs sets.Set[string]) int {
411+
currentIPUsage := 0
412412
for _, ipConfiguration := range networkInterface.Properties.IPConfigurations {
413413
if assignedIP := net.ParseIP(ptr.Deref(ipConfiguration.Properties.PrivateIPAddress, "")); assignedIP != nil {
414-
if utilnet.IsIPv4(assignedIP) {
415-
currentIPv4Usage++
416-
} else {
417-
currentIPv6Usage++
414+
if !cpicIPs.Has(assignedIP.String()) {
415+
currentIPUsage++
418416
}
419417
}
420418
}
421-
return defaultAzurePrivateIPCapacity + cloudPrivateIPsCount - currentIPv4Usage - currentIPv6Usage
419+
420+
return defaultAzurePrivateIPCapacity - currentIPUsage
422421
}
423422

424423
// 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
)
1615

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

157-
func (g *GCP) GetNodeEgressIPConfiguration(node *corev1.Node, cloudPrivateIPConfigs []*v1.CloudPrivateIPConfig) ([]*NodeEgressIPConfiguration, error) {
156+
func (g *GCP) GetNodeEgressIPConfiguration(node *corev1.Node, cpicIPs sets.Set[string]) ([]*NodeEgressIPConfiguration, error) {
158157
_, _, instance, err := g.getInstance(node)
159158
if err != nil {
160159
return nil, fmt.Errorf("error retrieving instance associated with node, err: %v", err)
@@ -182,7 +181,7 @@ func (g *GCP) GetNodeEgressIPConfiguration(node *corev1.Node, cloudPrivateIPConf
182181
config.IFAddr.IPv6 = v6Subnet.String()
183182
}
184183
config.Capacity = capacity{
185-
IP: g.getCapacity(networkInterface, len(cloudPrivateIPConfigs)),
184+
IP: g.getCapacity(networkInterface, cpicIPs),
186185
}
187186
return []*NodeEgressIPConfiguration{config}, nil //nolint:staticcheck
188187
}
@@ -233,25 +232,22 @@ func (g *GCP) getSubnet(networkInterface *google.NetworkInterface) (*net.IPNet,
233232

234233
// Note: there is also a global "alias IP per VPC quota", but OpenShift clusters on
235234
// GCP seem to have that value defined to 15,000. So we can skip that.
236-
func (g *GCP) getCapacity(networkInterface *google.NetworkInterface, cloudPrivateIPsCount int) int {
237-
currentIPv4Usage := 0
238-
currentIPv6Usage := 0
235+
func (g *GCP) getCapacity(networkInterface *google.NetworkInterface, cpicIPs sets.Set[string]) int {
236+
currentIPUsage := 0
239237
for _, aliasIPRange := range networkInterface.AliasIpRanges {
238+
var aliasIP net.IP
240239
if assignedIP := net.ParseIP(aliasIPRange.IpCidrRange); assignedIP != nil {
241-
if utilnet.IsIPv4(assignedIP) {
242-
currentIPv4Usage++
243-
} else {
244-
currentIPv6Usage++
245-
}
240+
aliasIP = assignedIP
246241
} else if _, assignedSubnet, err := net.ParseCIDR(aliasIPRange.IpCidrRange); err == nil {
247-
if utilnet.IsIPv4CIDR(assignedSubnet) {
248-
currentIPv4Usage++
249-
} else {
250-
currentIPv6Usage++
251-
}
242+
aliasIP = assignedSubnet.IP
243+
}
244+
245+
if aliasIP != nil && !cpicIPs.Has(aliasIP.String()) {
246+
currentIPUsage++
252247
}
253248
}
254-
return defaultGCPPrivateIPCapacity + cloudPrivateIPsCount - currentIPv4Usage - currentIPv6Usage
249+
250+
return defaultGCPPrivateIPCapacity - currentIPUsage
255251
}
256252

257253
// 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"
@@ -472,7 +471,7 @@ func (o *OpenStack) ReleasePrivateIP(ip net.IP, node *corev1.Node) error {
472471
// GetNodeEgressIPConfiguration retrieves the egress IP configuration for
473472
// the node, following the convention the cloud uses. This means
474473
// specifically for OpenStack that the interface is keyed by the port's neutron UUID.
475-
func (o *OpenStack) GetNodeEgressIPConfiguration(node *corev1.Node, cloudPrivateIPConfigs []*v1.CloudPrivateIPConfig) ([]*NodeEgressIPConfiguration, error) {
474+
func (o *OpenStack) GetNodeEgressIPConfiguration(node *corev1.Node, cpicIPs sets.Set[string]) ([]*NodeEgressIPConfiguration, error) {
476475
if node == nil {
477476
return nil, fmt.Errorf("invalid nil pointer provided for node when trying to get node EgressIP configuration")
478477
}
@@ -491,7 +490,7 @@ func (o *OpenStack) GetNodeEgressIPConfiguration(node *corev1.Node, cloudPrivate
491490
var configurations []*NodeEgressIPConfiguration
492491
for _, p := range serverPorts {
493492
// Retrieve configuration for this port.
494-
config, err := o.getNeutronPortNodeEgressIPConfiguration(p, cloudPrivateIPConfigs)
493+
config, err := o.getNeutronPortNodeEgressIPConfiguration(p, cpicIPs)
495494
if err != nil {
496495
return nil, err
497496
}
@@ -552,7 +551,7 @@ func (o *OpenStack) GetNodeEgressIPConfiguration(node *corev1.Node, cloudPrivate
552551
// neutron operates as there is no such thing as a per port quota or limit. Therefore we set a ceiling of
553552
// `openstackMaxCapacity`. The number of unique IP addresses in allowed_address_pair and fixed_ips is subtracted from
554553
// that ceiling.
555-
func (o *OpenStack) getNeutronPortNodeEgressIPConfiguration(p neutronports.Port, cloudPrivateIPConfigs []*v1.CloudPrivateIPConfig) (*NodeEgressIPConfiguration, error) {
554+
func (o *OpenStack) getNeutronPortNodeEgressIPConfiguration(p neutronports.Port, cpicIPs sets.Set[string]) (*NodeEgressIPConfiguration, error) {
556555
var ipv4, ipv6 string
557556
var err error
558557
var ip net.IP
@@ -589,12 +588,9 @@ func (o *OpenStack) getNeutronPortNodeEgressIPConfiguration(p neutronports.Port,
589588
}
590589
// Loop over all cloudPrivateIPConfigs and check if they are part of this ipnet.
591590
// If the IP is contained in the ipnet, increase cloudPrivateIPsCount.
592-
for _, cpic := range cloudPrivateIPConfigs {
593-
cip, _, err := cloudprivateipconfig.NameToIP(cpic.Name)
594-
if err != nil {
595-
return nil, err
596-
}
597-
if ipnet.Contains(cip) {
591+
for ipStr := range cpicIPs {
592+
cip := net.ParseIP(ipStr)
593+
if cip != nil && ipnet.Contains(cip) {
598594
cloudPrivateIPsCount++
599595
}
600596
}

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"
@@ -1016,7 +1015,7 @@ func TestGetNeutronPortNodeEgressIPConfiguration(t *testing.T) {
10161015
tcs := []struct {
10171016
port neutronports.Port
10181017
nodeEgressIPConfig NodeEgressIPConfiguration
1019-
cloudPrivateIPConfigs []*v1.CloudPrivateIPConfig
1018+
cloudPrivateIPConfigs []string
10201019
errString string
10211020
}{
10221021
{
@@ -1044,11 +1043,8 @@ func TestGetNeutronPortNodeEgressIPConfiguration(t *testing.T) {
10441043
IP: openstackMaxCapacity + 3 - 2, // excluding 2 allowed_address_pairs configured on the port.
10451044
},
10461045
},
1047-
// Configure cloudPrivateIPConfigs with 3 ips are within neutron subnet, 1 ip outside neutron subnet.
1048-
cloudPrivateIPConfigs: []*v1.CloudPrivateIPConfig{{ObjectMeta: metav1.ObjectMeta{
1049-
Name: "192.0.2.10"}}, {ObjectMeta: metav1.ObjectMeta{Name: "2000..1"}},
1050-
{ObjectMeta: metav1.ObjectMeta{Name: "2000..2"}},
1051-
{ObjectMeta: metav1.ObjectMeta{Name: "10.10.10.1"}}},
1046+
// Configure IPs with 3 ips are within neutron subnet, 1 ip outside neutron subnet.
1047+
cloudPrivateIPConfigs: []string{"192.0.2.10", "2000::1", "2000::2", "10.10.10.1"},
10521048
},
10531049
{
10541050
port: portMap["aafecceb-d986-42b6-8ea7-449c7cacb7d9"],
@@ -1061,7 +1057,8 @@ func TestGetNeutronPortNodeEgressIPConfiguration(t *testing.T) {
10611057
}
10621058

10631059
for i, tc := range tcs {
1064-
nodeEgressIPConfig, err := o.getNeutronPortNodeEgressIPConfiguration(tc.port, tc.cloudPrivateIPConfigs)
1060+
cpicIPs := sets.New[string](tc.cloudPrivateIPConfigs...)
1061+
nodeEgressIPConfig, err := o.getNeutronPortNodeEgressIPConfiguration(tc.port, cpicIPs)
10651062
if err != nil {
10661063
if !strings.Contains(err.Error(), tc.errString) {
10671064
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)