Skip to content
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

Feature/regex matching #105

Draft
wants to merge 27 commits into
base: main
Choose a base branch
from

Conversation

notrepo05
Copy link
Contributor

@notrepo05 notrepo05 commented Jun 15, 2021

We would like to be able to match using regex. I'm opening this as a draft since we plan to continue working / redesigning before trying to get our changes merged in :).

Example use case:

nrohn-a01 nr $ BBL_IAAS=aws ./leftovers -f "pull-1408.*security" --aws-secret-access-key=*** --aws-access-key-id=***  --aws-region=*** --dry-run --filter-as-regex
[EC2 Security Group: nat_security_group (Name:pull-1408-nat-security-group, Environment:pull-1408, Application:Cloud Foundry)]
[EC2 Security Group: ops_manager_security_group (Environment:pull-1408, Application:Cloud Foundry, Name:pull-1408-ops-manager-security-group)]
[EC2 Security Group: web_lb_security_group (Name:pull-1408-lb-security-group, Environment:pull-1408, Application:Cloud Foundry)]
[EC2 Security Group: rds_security_group (Application:Cloud Foundry, Name:pull-1408-rds-security-group, Environment:pull-1408)]
[EC2 Security Group: tcp_lb_security_group (Environment:pull-1408, Application:Cloud Foundry, Name:pull-1408-tcp-lb-security-group)]
[EC2 Security Group: ssh_lb_security_group (Name:pull-1408-ssh-lb-security-group, Environment:pull-1408, Application:Cloud Foundry)]
...

This PR also reorders some AWS resource deletion by their type, and adds waits to a couple resources so we don't fail improperly (especially important for RDS, which takes ~10 minutes to delete)

Thanks!

cc @ciriarte

Authored-by: Nick Rohn <nrohn@vmware.com>
Authored-by: Nick Rohn <nrohn@vmware.com>
Authored-by: Nick Rohn <nrohn@vmware.com>
Authored-by: Nick Rohn <nrohn@vmware.com>
@notrepo05
Copy link
Contributor Author

notrepo05 commented Jun 15, 2021

TODOs

  • Remove debugging lines
  • Add test coverage for AWS reordering and waits

notrepo05 and others added 23 commits June 14, 2021 19:46
Authored-by: Nick Rohn <nrohn@vmware.com>
Authored-by: Nick Rohn <nrohn@vmware.com>
Authored-by: Nick Rohn <nrohn@vmware.com>
  we need to wait for rds_instances to actually be deleted before
  continuing with rds subnet deletion, because you cannot delete
  a subnet that contains an instance

Co-authored-by: Nick Rohn <nrohn@vmware.com>
Co-authored-by: Jhonathan Aristizabal <jhonathana@vmware.com>
  We believe that security groups need to be deleted after the db
  instance is. And that vpc should be deleted last

Co-authored-by: Nick Rohn <nrohn@vmware.com>
Co-authored-by: Jhonathan Aristizabal <jhonathana@vmware.com>
feature: wait for rds_instances to be deleted
Update help section with new command
  - remove vendor

Co-authored-by: Jhonathan Aristizabal <jhonathana@vmware.com>
Co-authored-by: Nick Rohn <nrohn@vmware.com>
  - revert openstack dependency

Authored-by: Nick Rohn <nrohn@vmware.com>
Authored-by: Nick Rohn <nrohn@vmware.com>
Authored-by: Nick Rohn <nrohn@vmware.com>
Authored-by: Nick Rohn <nrohn@vmware.com>
Authored-by: Nick Rohn <nrohn@vmware.com>
Authored-by: Nick Rohn <nrohn@vmware.com>
Authored-by: Nick Rohn <nrohn@vmware.com>
@notrepo05
Copy link
Contributor Author

Hi @genevieve, if we wanted to get this merged upstream I assume we'll need to reintroduce vendoring and add more test coverage? Would you also want us to refactor the regex filter flag? We can also maintain our own fork if that's preferable. Thank you!!

@genevieve
Copy link
Owner

Hey Nick! Yes, if you wouldnt mind reintroducing vendoring and adding more test coverage, we can merge these changes!

@notrepo05
Copy link
Contributor Author

Thanks! I'll try to get it ready to be merged in a couple weeks.

Copy link
Collaborator

@rowanjacobs rowanjacobs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good so far!

Has this been tested with invalid regex input yet? I didn't see any code catching the panic from MustCompile, but there were also 2205 file changes so I could have missed something.

@@ -27,7 +27,7 @@ func NewFolders(client client, logger logger) Folders {

// List not only lists top-level folders, it also lists child and grandchild
// folders, and all VMs within those folders.
func (v Folders) List(filter string, rType string) ([]common.Deletable, error) {
func (v Folders) List(filter string, rType string, regex bool) ([]common.Deletable, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I am no longer aware of any users who are using leftovers to delete folders on a multitenant vSphere cluster (since the Toolsmiths team no longer provides multitenant vSpheres to MAPBU). So I think you can safely implement deleting vSphere folders by regex, if that's something you want to do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing this out. I'll need to find a good way to deal with the potential panic in common/resource_filter.go before we merge.

@@ -32,6 +33,7 @@ func GetLeftovers(logger *app.Logger, o app.Options) (leftovers, error) {
case app.Azure:
l, err = azure.NewLeftovers(logger, o.AzureClientID, o.AzureClientSecret, o.AzureSubscriptionID, o.AzureTenantID)
case app.GCP:
fmt.Println("in gcp")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder to self and Gen: make sure this test line is gone before merging the PR

@notrepo05
Copy link
Contributor Author

Thank you for the review @rowanjacobs. I still need to get around to getting this ready for merge. I'm trying to find time

@nhsieh nhsieh force-pushed the feature/regex-matching branch from cc050b9 to 36e523c Compare October 1, 2021 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants