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

Cleaning up resources that don't match the filter #80

Open
mjj209 opened this issue Mar 29, 2019 · 5 comments
Open

Cleaning up resources that don't match the filter #80

mjj209 opened this issue Mar 29, 2019 · 5 comments

Comments

@mjj209
Copy link

mjj209 commented Mar 29, 2019

The CF-Toolsmiths have implemented logic that cleans up GCP objects that don't match the explicit filter string. We wanted to recommend pushing this logic upstream into Leftovers. Would you consider cleaning up these GCP objects with Leftovers?

Specifically, we look for:

  1. Any Addresses attached to the network matching the filter
  2. Any routes attached to the network matching the filter
  3. Any DNS Record sets inside of the top level DNS zone matching the filter
  4. Any Firewall rules attached to the network matching the filter

Any of the 4 objects listed above could cause Leftovers to fail. We've found that it's safe to delete these objects, even if they do not match the filter string. I think for some objects, such as VMs, Leftovers will delete all VMs that are attached to the network in question, even if the VM name does not contain the filter. I'm curious if you would want to add more GCP objects to have this same behavior?

@genevieve
Copy link
Owner

@mjj209 That logic sounds great. I can't imagine a user passing a filter knowing it would match some network and not want to delete the things in that network. Would the team be able to make a PR with the current GCP objects they've updated to follow this logic and then we can see what other objects make sense after that?

@genevieve
Copy link
Owner

@nmahoney-pivotal @rowanjacobs Any thing y'all want to add?

@genevieve
Copy link
Owner

Hey @mjj209 @rowanjacobs! Are you still interested in merging this functionality upstream?

@genevieve
Copy link
Owner

Hi @mjj209.

I was reviewing the point about record sets in a dns zone. If a dns zone contains the filter, leftovers does delete the record sets inside of it.

err := m.recordSets.Delete(m.name)

func (r RecordSets) Delete(managedZone string) error {
r.logger.Debugln("Listing DNS Record Sets...")
recordSets, err := r.client.ListRecordSets(managedZone)
if err != nil {
return fmt.Errorf("Listing DNS Record Sets: %s", err)
}
deletions := []*gcpdns.ResourceRecordSet{}
for _, record := range recordSets.Rrsets {
if record.Type == "NS" || record.Type == "SOA" {
continue
}
deletions = append(deletions, record)
}
if len(deletions) > 0 {
err = r.client.DeleteRecordSets(managedZone, &gcpdns.Change{
Deletions: deletions,
})
if err != nil {
return fmt.Errorf("Delete record sets: %s", err)
}
}
return nil
}

I'm curious under what cases you've seen this cause leftovers to fail to clean up the gcp dns zone.

@genevieve
Copy link
Owner

genevieve commented Jan 6, 2020

Status:

  • Any Addresses attached to the network matching the filter
  • Any routes attached to the network matching the filter
  • Any DNS Record sets inside of the top level DNS zone matching the filter
  • Any Firewall rules attached to the network matching the filter
  • VMs
  • Routes
  • Subnets

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants