@@ -801,21 +801,6 @@ func disassociateSecurityGroupForLB(network *gophercloud.ServiceClient, sg strin
801
801
return nil
802
802
}
803
803
804
- // isSecurityGroupNotFound return true while 'err' is object of gophercloud.ErrResourceNotFound
805
- func isSecurityGroupNotFound (err error ) bool {
806
- errType := reflect .TypeOf (err ).String ()
807
- errTypeSlice := strings .Split (errType , "." )
808
- errTypeValue := ""
809
- if len (errTypeSlice ) != 0 {
810
- errTypeValue = errTypeSlice [len (errTypeSlice )- 1 ]
811
- }
812
- if errTypeValue == "ErrResourceNotFound" {
813
- return true
814
- }
815
-
816
- return false
817
- }
818
-
819
804
// deleteListeners deletes listeners and its default pool.
820
805
func (lbaas * LbaasV2 ) deleteListeners (lbID string , listenerList []listeners.Listener ) error {
821
806
for _ , listener := range listenerList {
@@ -2028,6 +2013,12 @@ func (lbaas *LbaasV2) ensureOctaviaLoadBalancer(ctx context.Context, clusterName
2028
2013
if err != nil {
2029
2014
return status , fmt .Errorf ("failed when reconciling security groups for LB service %v/%v: %v" , service .Namespace , service .Name , err )
2030
2015
}
2016
+ } else {
2017
+ // Attempt to delete the SG if `manage-security-groups` is disabled. When CPO is reconfigured to enable it we
2018
+ // will reconcile the LB and create the SG. This is to make sure it works the same in the opposite direction.
2019
+ if err := lbaas .EnsureSecurityGroupDeleted (clusterName , service ); err != nil {
2020
+ return status , err
2021
+ }
2031
2022
}
2032
2023
2033
2024
return status , nil
@@ -2154,6 +2145,9 @@ func (lbaas *LbaasV2) updateOctaviaLoadBalancer(ctx context.Context, clusterName
2154
2145
return fmt .Errorf ("failed to update Security Group for loadbalancer service %s: %v" , serviceName , err )
2155
2146
}
2156
2147
}
2148
+ // We don't try to lookup and delete the SG here when `manage-security-group=false` as `UpdateLoadBalancer()` is
2149
+ // only called on changes to the list of the Nodes. Deletion of the SG on reconfiguration will be handled by
2150
+ // EnsureLoadBalancer() that is the true LB reconcile function.
2157
2151
2158
2152
return nil
2159
2153
}
@@ -2222,7 +2216,7 @@ func (lbaas *LbaasV2) ensureAndUpdateOctaviaSecurityGroup(clusterName string, ap
2222
2216
lbSecGroupID , err := secgroups .IDFromName (lbaas .network , lbSecGroupName )
2223
2217
if err != nil {
2224
2218
// If the security group of LB not exist, create it later
2225
- if isSecurityGroupNotFound (err ) {
2219
+ if cpoerrors . IsNotFound (err ) {
2226
2220
lbSecGroupID = ""
2227
2221
} else {
2228
2222
return fmt .Errorf ("error occurred finding security group: %s: %v" , lbSecGroupName , err )
@@ -2522,11 +2516,10 @@ func (lbaas *LbaasV2) ensureLoadBalancerDeleted(ctx context.Context, clusterName
2522
2516
klog .InfoS ("Updated load balancer tags" , "lbID" , loadbalancer .ID )
2523
2517
}
2524
2518
2525
- // Delete the Security Group
2526
- if lbaas .opts .ManageSecurityGroups {
2527
- if err := lbaas .EnsureSecurityGroupDeleted (clusterName , service ); err != nil {
2528
- return err
2529
- }
2519
+ // Delete the Security Group. We're doing that even if `manage-security-groups` is disabled to make sure we don't
2520
+ // orphan created SGs even if CPO got reconfigured.
2521
+ if err := lbaas .EnsureSecurityGroupDeleted (clusterName , service ); err != nil {
2522
+ return err
2530
2523
}
2531
2524
2532
2525
return nil
@@ -2538,7 +2531,7 @@ func (lbaas *LbaasV2) EnsureSecurityGroupDeleted(_ string, service *corev1.Servi
2538
2531
lbSecGroupName := getSecurityGroupName (service )
2539
2532
lbSecGroupID , err := secgroups .IDFromName (lbaas .network , lbSecGroupName )
2540
2533
if err != nil {
2541
- if isSecurityGroupNotFound (err ) {
2534
+ if cpoerrors . IsNotFound (err ) {
2542
2535
// It is OK when the security group has been deleted by others.
2543
2536
return nil
2544
2537
}
0 commit comments