Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions pkg/cloudprovider/providers/oci/load_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2244,19 +2244,20 @@ func (cp *CloudProvider) getLbListenerBackendSetIpVersion(ipFamilies []string, i
}
return []string{IPv4, IPv6}, nil
case string(v1.IPFamilyPolicyPreferDualStack):
if errIPv6Subnet != nil && errIPv4Subnet != nil {
// should never happen
return nil, errors.New("subnet does not have IPv4 or IPv6 cidr, can't create loadbalancer")
// ipFamilies is the authoritative source of what IP families the service uses.
// Only include IP versions that are in ipFamilies AND supported by the subnet.
var result []string
for _, ipFamily := range ipFamilies {
if ipFamily == IPv4 && errIPv4Subnet == nil {
result = append(result, IPv4)
} else if ipFamily == IPv6 && errIPv6Subnet == nil {
result = append(result, IPv6)
}
}
if errIPv6Subnet != nil {
cp.logger.Warn("subnet provided does not have IPv6 subnet CIDR block, creating listeners and backends of ip-version IPv4")
return []string{IPv4}, nil
if len(result) == 0 {
return nil, errors.New("no compatible IP families between service spec and subnet capabilities")
}
if errIPv4Subnet != nil {
cp.logger.Warn("subnet provided does not have IPV4 subnet CIDR block, creating listeners and backends of ip-version IPv6")
return []string{IPv6}, nil
}
return []string{IPv4, IPv6}, nil
return result, nil
}
return []string{IPv4}, nil
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/cloudprovider/providers/oci/load_balancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1781,7 +1781,7 @@ func Test_getLbListenerBackendSetIpVersion(t *testing.T) {
listenerBackendSetIpVersions: []string{IPv4},
wantErr: nil,
},
"PreferDualStack IPv4": {
"PreferDualStack IPv4 - ipFamilies takes precedence over subnet capabilities": {
ipFamilies: []string{IPv4},
ipFamilyPolicy: string(v1.IPFamilyPolicyPreferDualStack),
nodeSubnets: []*core.Subnet{
Expand All @@ -1791,10 +1791,10 @@ func Test_getLbListenerBackendSetIpVersion(t *testing.T) {
Ipv6CidrBlocks: []string{"2001:0000:130F:0000:0000:09C0:876A:130B"},
},
},
listenerBackendSetIpVersions: []string{IPv4, IPv6},
listenerBackendSetIpVersions: []string{IPv4},
wantErr: nil,
},
"PreferDualStack IPv4 multiple subnets": {
"PreferDualStack IPv4 multiple subnets - ipFamilies takes precedence": {
ipFamilies: []string{IPv4},
ipFamilyPolicy: string(v1.IPFamilyPolicyPreferDualStack),
nodeSubnets: []*core.Subnet{
Expand All @@ -1806,7 +1806,7 @@ func Test_getLbListenerBackendSetIpVersion(t *testing.T) {
Ipv6CidrBlocks: []string{"2001:0000:130F:0000:0000:09C0:876A:130B"},
},
},
listenerBackendSetIpVersions: []string{IPv4, IPv6},
listenerBackendSetIpVersions: []string{IPv4},
wantErr: nil,
},
}
Expand Down