@@ -4212,18 +4212,39 @@ func (c *Cloud) EnsureLoadBalancerDeleted(ctx context.Context, clusterName strin
4212
4212
// Note that this is annoying: the load balancer disappears from the API immediately, but it is still
4213
4213
// deleting in the background. We get a DependencyViolation until the load balancer has deleted itself
4214
4214
4215
+ var loadBalancerSGs = aws .StringValueSlice (lb .SecurityGroups )
4216
+
4217
+ describeRequest := & ec2.DescribeSecurityGroupsInput {}
4218
+ filters := []* ec2.Filter {
4219
+ newEc2Filter ("group-id" , loadBalancerSGs ... ),
4220
+ }
4221
+ describeRequest .Filters = c .tagging .addFilters (filters )
4222
+ response , err := c .ec2 .DescribeSecurityGroups (describeRequest )
4223
+ if err != nil {
4224
+ return fmt .Errorf ("error querying security groups for ELB: %q" , err )
4225
+ }
4226
+
4215
4227
// Collect the security groups to delete
4216
4228
securityGroupIDs := map [string ]struct {}{}
4217
- for _ , securityGroupID := range lb .SecurityGroups {
4218
- if * securityGroupID == c .cfg .Global .ElbSecurityGroup {
4219
- //We don't want to delete a security group that was defined in the Cloud Configurationn.
4229
+
4230
+ for _ , sg := range response {
4231
+ sgID := aws .StringValue (sg .GroupId )
4232
+
4233
+ if sgID == c .cfg .Global .ElbSecurityGroup {
4234
+ //We don't want to delete a security group that was defined in the Cloud Configuration.
4220
4235
continue
4221
4236
}
4222
- if aws . StringValue ( securityGroupID ) == "" {
4223
- klog .Warning ("Ignoring empty security group in " , service .Name )
4237
+ if sgID == "" {
4238
+ klog .Warningf ("Ignoring empty security group in %s " , service .Name )
4224
4239
continue
4225
4240
}
4226
- securityGroupIDs [* securityGroupID ] = struct {}{}
4241
+
4242
+ if ! c .tagging .hasClusterTag (sg .Tags ) {
4243
+ klog .Warningf ("Ignoring security group with no cluster tag in %s" , service .Name )
4244
+ continue
4245
+ }
4246
+
4247
+ securityGroupIDs [sgID ] = struct {}{}
4227
4248
}
4228
4249
4229
4250
// Loop through and try to delete them
0 commit comments