@@ -797,21 +797,6 @@ func disassociateSecurityGroupForLB(network *gophercloud.ServiceClient, sg strin
797
797
return nil
798
798
}
799
799
800
- // isSecurityGroupNotFound return true while 'err' is object of gophercloud.ErrResourceNotFound
801
- func isSecurityGroupNotFound (err error ) bool {
802
- errType := reflect .TypeOf (err ).String ()
803
- errTypeSlice := strings .Split (errType , "." )
804
- errTypeValue := ""
805
- if len (errTypeSlice ) != 0 {
806
- errTypeValue = errTypeSlice [len (errTypeSlice )- 1 ]
807
- }
808
- if errTypeValue == "ErrResourceNotFound" {
809
- return true
810
- }
811
-
812
- return false
813
- }
814
-
815
800
// deleteListeners deletes listeners and its default pool.
816
801
func (lbaas * LbaasV2 ) deleteListeners (lbID string , listenerList []listeners.Listener ) error {
817
802
for _ , listener := range listenerList {
@@ -2059,6 +2044,12 @@ func (lbaas *LbaasV2) ensureOctaviaLoadBalancer(ctx context.Context, clusterName
2059
2044
if err != nil {
2060
2045
return status , fmt .Errorf ("failed when reconciling security groups for LB service %v/%v: %v" , service .Namespace , service .Name , err )
2061
2046
}
2047
+ } else {
2048
+ // Attempt to delete the SG if `manage-security-groups` is disabled. When CPO is reconfigured to enable it we
2049
+ // will reconcile the LB and create the SG. This is to make sure it works the same in the opposite direction.
2050
+ if err := lbaas .EnsureSecurityGroupDeleted (clusterName , service ); err != nil {
2051
+ return status , err
2052
+ }
2062
2053
}
2063
2054
2064
2055
return status , nil
@@ -2190,6 +2181,9 @@ func (lbaas *LbaasV2) updateOctaviaLoadBalancer(ctx context.Context, clusterName
2190
2181
return fmt .Errorf ("failed to update Security Group for loadbalancer service %s: %v" , serviceName , err )
2191
2182
}
2192
2183
}
2184
+ // We don't try to lookup and delete the SG here when `manage-security-group=false` as `UpdateLoadBalancer()` is
2185
+ // only called on changes to the list of the Nodes. Deletion of the SG on reconfiguration will be handled by
2186
+ // EnsureLoadBalancer() that is the true LB reconcile function.
2193
2187
2194
2188
return nil
2195
2189
}
@@ -2258,7 +2252,7 @@ func (lbaas *LbaasV2) ensureAndUpdateOctaviaSecurityGroup(clusterName string, ap
2258
2252
lbSecGroupID , err := secgroups .IDFromName (lbaas .network , lbSecGroupName )
2259
2253
if err != nil {
2260
2254
// If the security group of LB not exist, create it later
2261
- if isSecurityGroupNotFound (err ) {
2255
+ if cpoerrors . IsNotFound (err ) {
2262
2256
lbSecGroupID = ""
2263
2257
} else {
2264
2258
return fmt .Errorf ("error occurred finding security group: %s: %v" , lbSecGroupName , err )
@@ -2558,11 +2552,10 @@ func (lbaas *LbaasV2) ensureLoadBalancerDeleted(ctx context.Context, clusterName
2558
2552
klog .InfoS ("Updated load balancer tags" , "lbID" , loadbalancer .ID )
2559
2553
}
2560
2554
2561
- // Delete the Security Group
2562
- if lbaas .opts .ManageSecurityGroups {
2563
- if err := lbaas .EnsureSecurityGroupDeleted (clusterName , service ); err != nil {
2564
- return err
2565
- }
2555
+ // Delete the Security Group. We're doing that even if `manage-security-groups` is disabled to make sure we don't
2556
+ // orphan created SGs even if CPO got reconfigured.
2557
+ if err := lbaas .EnsureSecurityGroupDeleted (clusterName , service ); err != nil {
2558
+ return err
2566
2559
}
2567
2560
2568
2561
return nil
@@ -2574,7 +2567,7 @@ func (lbaas *LbaasV2) EnsureSecurityGroupDeleted(_ string, service *corev1.Servi
2574
2567
lbSecGroupName := getSecurityGroupName (service )
2575
2568
lbSecGroupID , err := secgroups .IDFromName (lbaas .network , lbSecGroupName )
2576
2569
if err != nil {
2577
- if isSecurityGroupNotFound (err ) {
2570
+ if cpoerrors . IsNotFound (err ) {
2578
2571
// It is OK when the security group has been deleted by others.
2579
2572
return nil
2580
2573
}
0 commit comments