Skip to content

Commit d5a3db0

Browse files
authored
Merge pull request kubernetes#74311 from hpedrorodrigues/fix-lb-sg-deletion
Ensure ownership when deleting a load balancer security group
2 parents dfa25fc + eb4087d commit d5a3db0

File tree

1 file changed

+27
-6
lines changed
  • pkg/cloudprovider/providers/aws

1 file changed

+27
-6
lines changed

pkg/cloudprovider/providers/aws/aws.go

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4212,18 +4212,39 @@ func (c *Cloud) EnsureLoadBalancerDeleted(ctx context.Context, clusterName strin
42124212
// Note that this is annoying: the load balancer disappears from the API immediately, but it is still
42134213
// deleting in the background. We get a DependencyViolation until the load balancer has deleted itself
42144214

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+
42154227
// Collect the security groups to delete
42164228
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.
42204235
continue
42214236
}
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)
42244239
continue
42254240
}
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{}{}
42274248
}
42284249

42294250
// Loop through and try to delete them

0 commit comments

Comments
 (0)