@@ -1992,20 +2008,54 @@ func (s *AWSCloud) EnsureTCPLoadBalancerDeleted(name, region string) error {
...
@@ -1992,20 +2008,54 @@ func (s *AWSCloud) EnsureTCPLoadBalancerDeleted(name, region string) error {
}
}
{
{
// Delete the security group
// Delete the security group(s) for the load balancer
for_,securityGroupId:=rangelb.SecurityGroups{
// Note that this is annoying: the load balancer disappears from the API immediately, but it is still
ifisNilOrEmpty(securityGroupId){
// deleting in the background. We get a DependencyViolation until the load balancer has deleted itself
// Collect the security groups to delete
securityGroupIDs:=map[string]struct{}{}
for_,securityGroupID:=rangelb.SecurityGroups{
ifisNilOrEmpty(securityGroupID){
glog.Warning("Ignoring empty security group in ",name)
glog.Warning("Ignoring empty security group in ",name)
continue
continue
}
}
securityGroupIDs[*securityGroupID]=struct{}{}
}
// Loop through and try to delete them
timeoutAt:=time.Now().Add(time.Second*300)
for{
forsecurityGroupID:=rangesecurityGroupIDs{
request:=&ec2.DeleteSecurityGroupInput{}
request.GroupID=&securityGroupID
_,err:=s.ec2.DeleteSecurityGroup(request)
iferr==nil{
delete(securityGroupIDs,securityGroupID)
}else{
ignore:=false
ifawsError,ok:=err.(awserr.Error);ok{
ifawsError.Code()=="DependencyViolation"{
glog.V(2).Infof("ignoring DependencyViolation while deleting load-balancer security group (%s), assuming because LB is in process of deleting",securityGroupID)
ignore=true
}
}
if!ignore{
returnfmt.Errorf("error while deleting load balancer security group (%s): %v",securityGroupID,err)
}
}
}
request:=&ec2.DeleteSecurityGroupInput{}
iflen(securityGroupIDs)==0{
request.GroupID=securityGroupId
break
_,err:=s.ec2.DeleteSecurityGroup(request)
iferr!=nil{
glog.Errorf("error deleting security group (%s): %v",orEmpty(securityGroupId),err)
returnerr
}
}
iftime.Now().After(timeoutAt){
returnfmt.Errorf("timed out waiting for load-balancer deletion: %s",name)
}
glog.V(2).Info("waiting for load-balancer to delete so we can delete security groups: ",name)