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

ENI Cleanup Improvements #15884

Merged
merged 3 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cloudmock/aws/mockec2/eni.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ func (m *MockEC2) DescribeNetworkInterfaces(input *ec2.DescribeNetworkInterfaces
output := &ec2.DescribeNetworkInterfacesOutput{}
return output, nil
}

func (m *MockEC2) DescribeNetworkInterfacesPages(*ec2.DescribeNetworkInterfacesInput, func(*ec2.DescribeNetworkInterfacesOutput, bool) bool) error {
return nil
}
24 changes: 14 additions & 10 deletions pkg/resources/aws/eni.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,28 @@ func DumpENI(op *resources.DumpOperation, r *resources.Resource) error {
func DescribeENIs(cloud fi.Cloud, clusterName string) (map[string]*ec2.NetworkInterface, error) {
c := cloud.(awsup.AWSCloud)

statusFilter := &ec2.Filter{
Name: aws.String("status"),
Values: []*string{
aws.String(ec2.NetworkInterfaceStatusDetaching),
Copy link
Member

Choose a reason for hiding this comment

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

Do we care about the detaching interfaces in our case?
I think the List function is called again and again, so those detaching ENIs will become available at some point.

Copy link
Member

Choose a reason for hiding this comment

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

No, ENIs that aren't returned won't get a resource tracker assigned. I suppose the assumption is that ENIs that are attached will be implicitly deleted once the thing they're attached to is deleted.

aws.String(ec2.NetworkInterfaceStatusAvailable),
},
}
enis := make(map[string]*ec2.NetworkInterface)
klog.V(2).Info("Listing ENIs")
for _, filters := range buildEC2FiltersForCluster(clusterName) {
request := &ec2.DescribeNetworkInterfacesInput{
Filters: filters,
Filters: append(filters, statusFilter),
}
response, err := c.EC2().DescribeNetworkInterfaces(request)
err := c.EC2().DescribeNetworkInterfacesPages(request, func(dnio *ec2.DescribeNetworkInterfacesOutput, b bool) bool {
for _, eni := range dnio.NetworkInterfaces {
enis[aws.StringValue(eni.NetworkInterfaceId)] = eni
}
return true
})
if err != nil {
return nil, fmt.Errorf("error listing ENIs: %v", err)
}

for _, eni := range response.NetworkInterfaces {
// Skip ENIs that are attached
if eni.Attachment != nil {
continue
}
enis[aws.StringValue(eni.NetworkInterfaceId)] = eni
}
}

return enis, nil
Expand Down
Loading