Skip to content

Commit 394540b

Browse files
committed
wip
Signed-off-by: Patryk Diak <[email protected]>
1 parent 36d6842 commit 394540b

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

pkg/cloudprovider/gcp.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
corev1 "k8s.io/api/core/v1"
1414
"k8s.io/apimachinery/pkg/util/sets"
1515
"k8s.io/utils/ptr"
16+
"k8s.io/klog/v2"
1617
)
1718

1819
const (
@@ -246,6 +247,7 @@ func (g *GCP) getSubnet(networkInterface *google.NetworkInterface) (*net.IPNet,
246247
// Note: there is also a global "alias IP per VPC quota", but OpenShift clusters on
247248
// GCP seem to have that value defined to 15,000. So we can skip that.
248249
func (g *GCP) getCapacity(networkInterface *google.NetworkInterface, cpicIPs sets.Set[string]) int {
250+
klog.Infof("getCapacity, existing cpicIPs: %+v", cpicIPs)
249251
currentIPUsage := 0
250252
for _, aliasIPRange := range networkInterface.AliasIpRanges {
251253
var aliasIP net.IP
@@ -256,6 +258,7 @@ func (g *GCP) getCapacity(networkInterface *google.NetworkInterface, cpicIPs set
256258
}
257259

258260
if aliasIP != nil && !cpicIPs.Has(aliasIP.String()) {
261+
klog.Infof("getCapacity, assigned IP address %s", aliasIP.String())
259262
currentIPUsage++
260263
}
261264
}

pkg/cloudprovider/openstack.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,6 @@ func (o *OpenStack) getNeutronPortNodeEgressIPConfiguration(p neutronports.Port,
567567
// Loop over all subnets. OpenStack potentially has several IPv4 or IPv6 subnets per port, but the
568568
// CloudPrivateIPConfig expects only a single subnet of each address family per port. Throw an error
569569
// in such a case.
570-
var cloudPrivateIPsCount int
571570
for _, s := range subnets {
572571
// Parse CIDR information into ip and ipnet.
573572
ip, ipnet, err = net.ParseCIDR(s.CIDR)
@@ -587,13 +586,14 @@ func (o *OpenStack) getNeutronPortNodeEgressIPConfiguration(p neutronports.Port,
587586
}
588587
ipv6 = ipnet.String()
589588
}
590-
// Loop over all cloudPrivateIPConfigs and check if they are part of this ipnet.
591-
// If the IP is contained in the ipnet, increase cloudPrivateIPsCount.
592-
for ipStr := range cpicIPs {
593-
cip := net.ParseIP(ipStr)
594-
if cip != nil && ipnet.Contains(cip) {
595-
cloudPrivateIPsCount++
596-
}
589+
}
590+
591+
// Loop over all cloudPrivateIPConfigs and check if they are part of this port.
592+
// If the IP is contained in the port, increase cloudPrivateIPsCount.
593+
cloudPrivateIPsCount := 0
594+
for _, portIP := range p.AllowedAddressPairs {
595+
if cpicIPs.Has(portIP.IPAddress) {
596+
cloudPrivateIPsCount++
597597
}
598598
}
599599

pkg/cloudprovider/openstack_test.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ var portMap = map[string]neutronports.Port{
6565
{
6666
IPAddress: "192.0.2.2",
6767
},
68+
{
69+
IPAddress: "192.0.2.10",
70+
},
71+
{
72+
IPAddress: "2000::1",
73+
},
74+
{
75+
IPAddress: "2000::2",
76+
},
6877
},
6978
DeviceID: "9e5476bd-a4ec-4653-93d6-72c93aa682ba",
7079
DeviceOwner: novaDeviceOwner,
@@ -1028,7 +1037,7 @@ func TestGetNeutronPortNodeEgressIPConfiguration(t *testing.T) {
10281037
IPv6: "2000::/64",
10291038
},
10301039
Capacity: capacity{
1031-
IP: ptr.To(openstackMaxCapacity - 2), // 2 allowed_address_pairs configured on the port.
1040+
IP: ptr.To(openstackMaxCapacity - 5), // 5 allowed_address_pairs configured on the port.
10321041
},
10331042
},
10341043
},
@@ -1041,7 +1050,7 @@ func TestGetNeutronPortNodeEgressIPConfiguration(t *testing.T) {
10411050
IPv6: "2000::/64",
10421051
},
10431052
Capacity: capacity{
1044-
IP: ptr.To(openstackMaxCapacity + 3 - 2), // excluding 2 allowed_address_pairs configured on the port.
1053+
IP: ptr.To(openstackMaxCapacity - 2), // excluding 2 allowed_address_pairs configured on the port.
10451054
},
10461055
},
10471056
// Configure IPs with 3 ips are within neutron subnet, 1 ip outside neutron subnet.
@@ -1096,23 +1105,23 @@ func TestAllowUnAllowIPAddressOnNeutronPort(t *testing.T) {
10961105
{
10971106
portID: "9ab428d4-58f8-42d7-9672-90c3f5641f83",
10981107
ip: net.ParseIP("192.0.2.20"),
1099-
allowedIPs: []string{"192.0.2.1", "192.0.2.2", "192.0.2.20"},
1108+
allowedIPs: []string{"192.0.2.1", "192.0.2.10", "192.0.2.2", "192.0.2.20", "2000::1", "2000::2"},
11001109
},
11011110
{
11021111
portID: "9ab428d4-58f8-42d7-9672-90c3f5641f83",
11031112
ip: net.ParseIP("192.0.2.21"),
1104-
allowedIPs: []string{"192.0.2.1", "192.0.2.2", "192.0.2.20", "192.0.2.21"},
1113+
allowedIPs: []string{"192.0.2.1", "192.0.2.10", "192.0.2.2", "192.0.2.20", "192.0.2.21", "2000::1", "2000::2"},
11051114
},
11061115
{
11071116
portID: "9ab428d4-58f8-42d7-9672-90c3f5641f83",
11081117
ip: net.ParseIP("192.0.2.20"),
11091118
unallow: true,
1110-
allowedIPs: []string{"192.0.2.1", "192.0.2.2", "192.0.2.21"},
1119+
allowedIPs: []string{"192.0.2.1", "192.0.2.10", "192.0.2.2", "192.0.2.21", "2000::1", "2000::2"},
11111120
},
11121121
{
11131122
portID: "9ab428d4-58f8-42d7-9672-90c3f5641f83",
11141123
ip: net.ParseIP("192.0.2.21"),
1115-
allowedIPs: []string{"192.0.2.1", "192.0.2.2", "192.0.2.21"},
1124+
allowedIPs: []string{"192.0.2.1", "192.0.2.10", "192.0.2.2", "192.0.2.21", "2000::1", "2000::2"},
11161125
errString: "the requested IP for assignment is already assigned",
11171126
},
11181127
{
@@ -1132,7 +1141,7 @@ func TestAllowUnAllowIPAddressOnNeutronPort(t *testing.T) {
11321141
portID: "9ab428d4-58f8-42d7-9672-90c3f5641f83",
11331142
ip: net.ParseIP("192.0.2.21"),
11341143
unallow: true,
1135-
allowedIPs: []string{"192.0.2.1", "192.0.2.2"},
1144+
allowedIPs: []string{"192.0.2.1", "192.0.2.10", "192.0.2.2", "2000::1", "2000::2"},
11361145
},
11371146
}
11381147

0 commit comments

Comments
 (0)