mirror of https://github.com/kubernetes/kops.git
upup: detach internet gateway if vpc is to be deleted
This commit is contained in:
parent
3ede6c1f4a
commit
1e7159a923
|
@ -183,6 +183,32 @@ func (c *DeleteCluster) ListResources() (map[string]DeletableResource, error) {
|
|||
}
|
||||
}
|
||||
|
||||
{
|
||||
glog.V(2).Infof("Listing all Internet Gateways")
|
||||
|
||||
request := &ec2.DescribeInternetGatewaysInput{}
|
||||
response, err := cloud.EC2.DescribeInternetGateways(request)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error listing InternetGateways: %v", err)
|
||||
}
|
||||
|
||||
for _, igw := range response.InternetGateways {
|
||||
for _, attachment := range igw.Attachments {
|
||||
vpcID := aws.StringValue(attachment.VpcId)
|
||||
if vpcID == "" {
|
||||
continue
|
||||
}
|
||||
if resources["vpc:"+vpcID] != nil {
|
||||
r := &DetachableInternetGateway{
|
||||
ID: aws.StringValue(igw.InternetGatewayId),
|
||||
VPCID: vpcID,
|
||||
}
|
||||
resources["detach-igw:"+aws.StringValue(igw.InternetGatewayId)] = r
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return resources, nil
|
||||
}
|
||||
|
||||
|
@ -747,6 +773,34 @@ func (r *DeletableInternetGateway) String() string {
|
|||
return "InternetGateway:" + r.ID
|
||||
}
|
||||
|
||||
type DetachableInternetGateway struct {
|
||||
ID string
|
||||
VPCID string
|
||||
}
|
||||
|
||||
func (r *DetachableInternetGateway) Delete(cloud fi.Cloud) error {
|
||||
c := cloud.(*awsup.AWSCloud)
|
||||
|
||||
glog.V(2).Infof("Detaching EC2 InternetGateway %q", r.ID)
|
||||
request := &ec2.DetachInternetGatewayInput{
|
||||
InternetGatewayId: &r.ID,
|
||||
VpcId: &r.VPCID,
|
||||
}
|
||||
_, err := c.EC2.DetachInternetGateway(request)
|
||||
if err != nil {
|
||||
if IsDependencyViolation(err) {
|
||||
return err
|
||||
}
|
||||
return fmt.Errorf("error detaching InternetGateway %q: %v", r.ID, err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *DetachableInternetGateway) String() string {
|
||||
return "DetachInternetGateway:" + r.ID
|
||||
}
|
||||
|
||||
type DeletableVPC struct {
|
||||
ID string
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue