@@ -1408,8 +1408,10 @@ func (lbaas *LbaasV2) buildListenerCreateOpt(port corev1.ServicePort, svcConf *s
1408
1408
listenerCreateOpt .Protocol = listeners .ProtocolHTTP
1409
1409
}
1410
1410
1411
- if len (svcConf .allowedCIDR ) > 0 {
1412
- listenerCreateOpt .AllowedCIDRs = svcConf .allowedCIDR
1411
+ if openstackutil .IsOctaviaFeatureSupported (lbaas .lb , openstackutil .OctaviaFeatureVIPACL , lbaas .opts .LBProvider ) {
1412
+ if len (svcConf .allowedCIDR ) > 0 {
1413
+ listenerCreateOpt .AllowedCIDRs = svcConf .allowedCIDR
1414
+ }
1413
1415
}
1414
1416
return listenerCreateOpt
1415
1417
}
@@ -1781,18 +1783,19 @@ func (lbaas *LbaasV2) checkService(service *corev1.Service, nodes []*corev1.Node
1781
1783
svcConf .timeoutTCPInspect = getIntFromServiceAnnotation (service , ServiceAnnotationLoadBalancerTimeoutTCPInspect , 0 )
1782
1784
}
1783
1785
1784
- var listenerAllowedCIDRs []string
1785
1786
sourceRanges , err := GetLoadBalancerSourceRanges (service , svcConf .preferredIPFamily )
1786
1787
if err != nil {
1787
1788
return fmt .Errorf ("failed to get source ranges for loadbalancer service %s: %v" , serviceName , err )
1788
1789
}
1789
1790
if openstackutil .IsOctaviaFeatureSupported (lbaas .lb , openstackutil .OctaviaFeatureVIPACL , lbaas .opts .LBProvider ) {
1790
1791
klog .V (4 ).Info ("LoadBalancerSourceRanges is suppported" )
1791
- listenerAllowedCIDRs = sourceRanges .StringSlice ()
1792
+ svcConf .allowedCIDR = sourceRanges .StringSlice ()
1793
+ } else if lbaas .opts .LBProvider == "ovn" && lbaas .opts .ManageSecurityGroups {
1794
+ klog .V (4 ).Info ("LoadBalancerSourceRanges will be enforced on the SG created and attached to LB members" )
1795
+ svcConf .allowedCIDR = sourceRanges .StringSlice ()
1792
1796
} else {
1793
- klog .Warning ("LoadBalancerSourceRanges is ignored" )
1797
+ klog .Warning ("LoadBalancerSourceRanges are ignored" )
1794
1798
}
1795
- svcConf .allowedCIDR = listenerAllowedCIDRs
1796
1799
1797
1800
if openstackutil .IsOctaviaFeatureSupported (lbaas .lb , openstackutil .OctaviaFeatureFlavors , lbaas .opts .LBProvider ) {
1798
1801
svcConf .flavorID = getStringFromServiceAnnotation (service , ServiceAnnotationLoadBalancerFlavorID , lbaas .opts .FlavorID )
@@ -2040,7 +2043,7 @@ func (lbaas *LbaasV2) ensureOctaviaLoadBalancer(ctx context.Context, clusterName
2040
2043
status := lbaas .createLoadBalancerStatus (service , svcConf , addr )
2041
2044
2042
2045
if lbaas .opts .ManageSecurityGroups {
2043
- err := lbaas .ensureSecurityGroup (clusterName , service , nodes , loadbalancer , svcConf . preferredIPFamily , svcConf . lbMemberSubnetID )
2046
+ err := lbaas .ensureAndUpdateOctaviaSecurityGroup (clusterName , service , nodes , svcConf )
2044
2047
if err != nil {
2045
2048
return status , fmt .Errorf ("failed when reconciling security groups for LB service %v/%v: %v" , service .Namespace , service .Name , err )
2046
2049
}
@@ -2101,14 +2104,6 @@ func (lbaas *LbaasV2) ensureSecurityRule(sgRuleCreateOpts rules.CreateOpts) erro
2101
2104
return nil
2102
2105
}
2103
2106
2104
- // ensureSecurityGroup ensures security group exist for specific loadbalancer service.
2105
- // Creating security group for specific loadbalancer service when it does not exist.
2106
- func (lbaas * LbaasV2 ) ensureSecurityGroup (clusterName string , apiService * corev1.Service , nodes []* corev1.Node ,
2107
- loadbalancer * loadbalancers.LoadBalancer , preferredIPFamily corev1.IPFamily , memberSubnetID string ) error {
2108
-
2109
- return lbaas .ensureAndUpdateOctaviaSecurityGroup (clusterName , apiService , nodes , memberSubnetID )
2110
- }
2111
-
2112
2107
func (lbaas * LbaasV2 ) updateOctaviaLoadBalancer (ctx context.Context , clusterName string , service * corev1.Service , nodes []* corev1.Node ) error {
2113
2108
svcConf := new (serviceConfig )
2114
2109
var err error
@@ -2176,7 +2171,7 @@ func (lbaas *LbaasV2) updateOctaviaLoadBalancer(ctx context.Context, clusterName
2176
2171
}
2177
2172
2178
2173
if lbaas .opts .ManageSecurityGroups {
2179
- err := lbaas .updateSecurityGroup (clusterName , service , nodes , svcConf . lbMemberSubnetID )
2174
+ err := lbaas .ensureAndUpdateOctaviaSecurityGroup (clusterName , service , nodes , svcConf )
2180
2175
if err != nil {
2181
2176
return fmt .Errorf ("failed to update Security Group for loadbalancer service %s: %v" , serviceName , err )
2182
2177
}
@@ -2240,7 +2235,7 @@ func getRulesToCreateAndDelete(wantedRules []rules.CreateOpts, existingRules []r
2240
2235
}
2241
2236
2242
2237
// ensureAndUpdateOctaviaSecurityGroup handles the creation and update of the security group and the securiry rules for the octavia load balancer
2243
- func (lbaas * LbaasV2 ) ensureAndUpdateOctaviaSecurityGroup (clusterName string , apiService * corev1.Service , nodes []* corev1.Node , memberSubnetID string ) error {
2238
+ func (lbaas * LbaasV2 ) ensureAndUpdateOctaviaSecurityGroup (clusterName string , apiService * corev1.Service , nodes []* corev1.Node , svcConf * serviceConfig ) error {
2244
2239
// get service ports
2245
2240
ports := apiService .Spec .Ports
2246
2241
if len (ports ) == 0 {
@@ -2274,16 +2269,23 @@ func (lbaas *LbaasV2) ensureAndUpdateOctaviaSecurityGroup(clusterName string, ap
2274
2269
}
2275
2270
2276
2271
mc := metrics .NewMetricContext ("subnet" , "get" )
2277
- subnet , err := subnets .Get (lbaas .network , memberSubnetID ).Extract ()
2272
+ subnet , err := subnets .Get (lbaas .network , svcConf . lbMemberSubnetID ).Extract ()
2278
2273
if mc .ObserveRequest (err ) != nil {
2279
2274
return fmt .Errorf (
2280
- "failed to find subnet %s from openstack: %v" , memberSubnetID , err )
2275
+ "failed to find subnet %s from openstack: %v" , svcConf . lbMemberSubnetID , err )
2281
2276
}
2282
2277
2283
2278
etherType := rules .EtherType4
2284
2279
if netutils .IsIPv6CIDRString (subnet .CIDR ) {
2285
2280
etherType = rules .EtherType6
2286
2281
}
2282
+ cidrs := []string {subnet .CIDR }
2283
+ if lbaas .opts .LBProvider == "ovn" {
2284
+ // OVN keeps the source IP of the incoming traffic. This means that we cannot just open the LB range, but we
2285
+ // need to open for the whole world. This can be restricted by using the service.spec.loadBalancerSourceRanges.
2286
+ // svcConf.allowedCIDR will give us the ranges calculated by GetLoadBalancerSourceRanges() earlier.
2287
+ cidrs = svcConf .allowedCIDR
2288
+ }
2287
2289
2288
2290
existingRules , err := getSecurityGroupRules (lbaas .network , rules.ListOpts {SecGroupID : lbSecGroupID })
2289
2291
if err != nil {
@@ -2296,6 +2298,8 @@ func (lbaas *LbaasV2) ensureAndUpdateOctaviaSecurityGroup(clusterName string, ap
2296
2298
wantedRules := make ([]rules.CreateOpts , 0 , len (ports )+ 1 )
2297
2299
2298
2300
if apiService .Spec .HealthCheckNodePort != 0 {
2301
+ // TODO(dulek): How should this work with OVN…? Do we need to allow all?
2302
+ // Probably the traffic goes from the compute node?
2299
2303
wantedRules = append (wantedRules ,
2300
2304
rules.CreateOpts {
2301
2305
Direction : rules .DirIngress ,
@@ -2313,17 +2317,19 @@ func (lbaas *LbaasV2) ensureAndUpdateOctaviaSecurityGroup(clusterName string, ap
2313
2317
if port .NodePort == 0 { // It's 0 when AllocateLoadBalancerNodePorts=False
2314
2318
continue
2315
2319
}
2316
- wantedRules = append (wantedRules ,
2317
- rules.CreateOpts {
2318
- Direction : rules .DirIngress ,
2319
- Protocol : rules .RuleProtocol (port .Protocol ),
2320
- EtherType : etherType ,
2321
- RemoteIPPrefix : subnet .CIDR ,
2322
- SecGroupID : lbSecGroupID ,
2323
- PortRangeMin : int (port .NodePort ),
2324
- PortRangeMax : int (port .NodePort ),
2325
- },
2326
- )
2320
+ for _ , cidr := range cidrs {
2321
+ wantedRules = append (wantedRules ,
2322
+ rules.CreateOpts {
2323
+ Direction : rules .DirIngress ,
2324
+ Protocol : rules .RuleProtocol (port .Protocol ),
2325
+ EtherType : etherType ,
2326
+ RemoteIPPrefix : cidr ,
2327
+ SecGroupID : lbSecGroupID ,
2328
+ PortRangeMin : int (port .NodePort ),
2329
+ PortRangeMax : int (port .NodePort ),
2330
+ },
2331
+ )
2332
+ }
2327
2333
}
2328
2334
2329
2335
toCreate , toDelete := getRulesToCreateAndDelete (wantedRules , existingRules )
@@ -2357,11 +2363,6 @@ func (lbaas *LbaasV2) ensureAndUpdateOctaviaSecurityGroup(clusterName string, ap
2357
2363
return nil
2358
2364
}
2359
2365
2360
- // updateSecurityGroup updating security group for specific loadbalancer service.
2361
- func (lbaas * LbaasV2 ) updateSecurityGroup (clusterName string , apiService * corev1.Service , nodes []* corev1.Node , memberSubnetID string ) error {
2362
- return lbaas .ensureAndUpdateOctaviaSecurityGroup (clusterName , apiService , nodes , memberSubnetID )
2363
- }
2364
-
2365
2366
// EnsureLoadBalancerDeleted deletes the specified load balancer
2366
2367
func (lbaas * LbaasV2 ) EnsureLoadBalancerDeleted (ctx context.Context , clusterName string , service * corev1.Service ) error {
2367
2368
mc := metrics .NewMetricContext ("loadbalancer" , "delete" )
0 commit comments