Repository navigation
pkg/destroy/aws: Skip direct tag deletion for network interfaces #1704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -140,16 +140,28 @@ func (o *ClusterUninstaller) Run() error { | |
| &resourcegroupstaggingapi.GetResourcesInput{TagFilters: tagFilters}, | ||
| func(results *resourcegroupstaggingapi.GetResourcesOutput, lastPage bool) bool { | ||
| for _, resource := range results.ResourceTagMappingList { | ||
| arn := *resource.ResourceARN | ||
| if _, ok := deleted[arn]; !ok { | ||
| arnString := *resource.ResourceARN | ||
| if _, ok := deleted[arnString]; !ok { | ||
| arnLogger := o.Logger.WithField("arn", arnString) | ||
| matched = true | ||
| err := deleteARN(awsSession, arn, filter, o.Logger) | ||
| parsed, err := arn.Parse(arnString) | ||
| if err != nil { | ||
| err = errors.Wrapf(err, "deleting %s", arn) | ||
| o.Logger.Debug(err) | ||
| arnLogger.Debug(err) | ||
| continue | ||
| } | ||
| deleted[arn] = exists | ||
|
|
||
| if parsed.Service == "ec2" && strings.HasPrefix(parsed.Resource, "network-interface/") { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is this not handled in the deleteARN function? we could easily skip here https://github.com/wking/openshift-installer/blob/fc70eb221cd211402c6f0c13e679cbee9d071ae4/pkg/destroy/aws/aws.go#L522 i don' think we should keep these conditionals in main loop..
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Because I want
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move this into deleteTaggedResource like func which does conditional before calling delete ARN. the main loop is not correct place to keep this conditional |
||
| arnLogger.Debug("skip direct tag deletion, deleting the VPC should catch this") | ||
| continue | ||
| } | ||
|
|
||
| err = deleteARN(awsSession, parsed, filter, arnLogger) | ||
| if err != nil { | ||
| arnLogger.Debug(err) | ||
| err = errors.Wrapf(err, "deleting %s", arnString) | ||
| continue | ||
| } | ||
| deleted[arnString] = exists | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -190,16 +202,24 @@ func (o *ClusterUninstaller) Run() error { | |
| if len(arns) > 0 { | ||
| o.Logger.Debug("delete IAM roles and users") | ||
| } | ||
| for _, arn := range arns { | ||
| if _, ok := deleted[arn]; !ok { | ||
| err = deleteARN(awsSession, arn, nil, o.Logger) | ||
| for _, arnString := range arns { | ||
| if _, ok := deleted[arnString]; !ok { | ||
| arnLogger := o.Logger.WithField("arn", arnString) | ||
| parsed, err := arn.Parse(arnString) | ||
| if err != nil { | ||
| arnLogger.Debug(err) | ||
| loopError = err | ||
| continue | ||
| } | ||
|
|
||
| err = deleteARN(awsSession, parsed, nil, arnLogger) | ||
| if err != nil { | ||
| err = errors.Wrapf(err, "deleting %s", arn) | ||
| o.Logger.Debug(err) | ||
| arnLogger.Debug(err) | ||
| err = errors.Wrapf(err, "deleting %s", arnString) | ||
| loopError = err | ||
| continue | ||
| } | ||
| deleted[arn] = exists | ||
| deleted[arnString] = exists | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -454,27 +474,20 @@ func findPublicRoute53(client *route53.Route53, dnsName string, logger logrus.Fi | |
| return "", nil | ||
| } | ||
|
|
||
| func deleteARN(session *session.Session, arnString string, filter Filter, logger logrus.FieldLogger) error { | ||
| logger = logger.WithField("arn", arnString) | ||
|
|
||
| parsed, err := arn.Parse(arnString) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| switch parsed.Service { | ||
| func deleteARN(session *session.Session, arn arn.ARN, filter Filter, logger logrus.FieldLogger) error { | ||
| switch arn.Service { | ||
| case "ec2": | ||
| return deleteEC2(session, parsed, filter, logger) | ||
| return deleteEC2(session, arn, filter, logger) | ||
| case "elasticloadbalancing": | ||
| return deleteElasticLoadBalancing(session, parsed, logger) | ||
| return deleteElasticLoadBalancing(session, arn, logger) | ||
| case "iam": | ||
| return deleteIAM(session, parsed, logger) | ||
| return deleteIAM(session, arn, logger) | ||
| case "route53": | ||
| return deleteRoute53(session, parsed, logger) | ||
| return deleteRoute53(session, arn, logger) | ||
| case "s3": | ||
| return deleteS3(session, parsed, logger) | ||
| return deleteS3(session, arn, logger) | ||
| default: | ||
| return errors.Errorf("unrecognized ARN service %s (%s)", parsed.Service, arnString) | ||
| return errors.Errorf("unrecognized ARN service %s (%s)", arn.Service, arn) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -706,7 +719,7 @@ func deleteEC2NATGateway(client *ec2.EC2, id string, logger logrus.FieldLogger) | |
| return nil | ||
| } | ||
|
|
||
| func deleteEC2NATGatewaysByVPC(client *ec2.EC2, vpc string, logger logrus.FieldLogger) error { | ||
| func deleteEC2NATGatewaysByVPC(client *ec2.EC2, vpc string, failFast bool, logger logrus.FieldLogger) error { | ||
| var lastError error | ||
| err := client.DescribeNatGatewaysPages( | ||
| &ec2.DescribeNatGatewaysInput{ | ||
|
|
@@ -725,6 +738,9 @@ func deleteEC2NATGatewaysByVPC(client *ec2.EC2, vpc string, logger logrus.FieldL | |
| logger.Debug(err) | ||
| } | ||
| lastError = errors.Wrapf(err, "deleting EC2 NAT gateway %s", *gateway.NatGatewayId) | ||
| if failFast { | ||
| return false | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -793,7 +809,7 @@ func deleteEC2RouteTableObject(client *ec2.EC2, table *ec2.RouteTable, logger lo | |
| return nil | ||
| } | ||
|
|
||
| func deleteEC2RouteTablesByVPC(client *ec2.EC2, vpc string, logger logrus.FieldLogger) error { | ||
| func deleteEC2RouteTablesByVPC(client *ec2.EC2, vpc string, failFast bool, logger logrus.FieldLogger) error { | ||
| var lastError error | ||
| err := client.DescribeRouteTablesPages( | ||
| &ec2.DescribeRouteTablesInput{ | ||
|
|
@@ -812,6 +828,9 @@ func deleteEC2RouteTablesByVPC(client *ec2.EC2, vpc string, logger logrus.FieldL | |
| logger.Debug(err) | ||
| } | ||
| lastError = errors.Wrapf(err, "deleting EC2 route table %s", *table.RouteTableId) | ||
| if failFast { | ||
| return false | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -904,7 +923,7 @@ func deleteEC2NetworkInterface(client *ec2.EC2, id string, logger logrus.FieldLo | |
| return nil | ||
| } | ||
|
|
||
| func deleteEC2NetworkInterfaceByVPC(client *ec2.EC2, vpc string, logger logrus.FieldLogger) error { | ||
| func deleteEC2NetworkInterfaceByVPC(client *ec2.EC2, vpc string, failFast bool, logger logrus.FieldLogger) error { | ||
| var lastError error | ||
| err := client.DescribeNetworkInterfacesPages( | ||
| &ec2.DescribeNetworkInterfacesInput{ | ||
|
|
@@ -923,6 +942,9 @@ func deleteEC2NetworkInterfaceByVPC(client *ec2.EC2, vpc string, logger logrus.F | |
| logger.Debug(lastError) | ||
| } | ||
| lastError = errors.Wrapf(err, "deleting EC2 network interface %s", *networkInterface.NetworkInterfaceId) | ||
| if failFast { | ||
| return false | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -979,13 +1001,13 @@ func deleteEC2VPC(ec2Client *ec2.EC2, elbClient *elb.ELB, elbv2Client *elbv2.ELB | |
| return v2lbError | ||
| } | ||
|
|
||
| for _, helper := range [](func(client *ec2.EC2, vpc string, logger logrus.FieldLogger) error){ | ||
| for _, helper := range [](func(client *ec2.EC2, vpc string, failFast bool, logger logrus.FieldLogger) error){ | ||
| deleteEC2NATGatewaysByVPC, // not always tagged | ||
| deleteEC2NetworkInterfaceByVPC, // not always tagged | ||
| deleteEC2RouteTablesByVPC, // not always tagged | ||
| deleteEC2VPCEndpointsByVPC, // not taggable | ||
| } { | ||
| err := helper(ec2Client, id, logger) | ||
| err := helper(ec2Client, id, true, logger) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
@@ -1014,7 +1036,7 @@ func deleteEC2VPCEndpoint(client *ec2.EC2, id string, logger logrus.FieldLogger) | |
| return nil | ||
| } | ||
|
|
||
| func deleteEC2VPCEndpointsByVPC(client *ec2.EC2, vpc string, logger logrus.FieldLogger) error { | ||
| func deleteEC2VPCEndpointsByVPC(client *ec2.EC2, vpc string, failFast bool, logger logrus.FieldLogger) error { | ||
| response, err := client.DescribeVpcEndpoints(&ec2.DescribeVpcEndpointsInput{ | ||
| Filters: []*ec2.Filter{ | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this change makes parsing ARN code exist in 2 different places
https://github.com/openshift/installer/pull/1704/files#diff-ab65f0e2ba0237c5cc1429673c22cc08R147
and
https://github.com/openshift/installer/pull/1704/files#diff-ab65f0e2ba0237c5cc1429673c22cc08R208
when we give that parseARN to deleteARN... IMO this is not ideal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup. I didn't think that was a big deal, it's not very complicated code.