From a84e54f7377e16250ed60cb60eb71d8ddeb44db8 Mon Sep 17 00:00:00 2001 From: Joseph Chen Date: Wed, 20 Mar 2024 18:39:52 +0000 Subject: [PATCH] Add vpc-id to leaked eni filters --- pkg/awsutils/awsutils.go | 6 ++++++ pkg/awsutils/awsutils_test.go | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/pkg/awsutils/awsutils.go b/pkg/awsutils/awsutils.go index bccbf4b869..db14e34b75 100644 --- a/pkg/awsutils/awsutils.go +++ b/pkg/awsutils/awsutils.go @@ -1886,6 +1886,12 @@ func (cache *EC2InstanceMetadataCache) getLeakedENIs() ([]*ec2.NetworkInterface, aws.String(ec2.NetworkInterfaceStatusAvailable), }, }, + { + Name: aws.String("vpc-id"), + Values: []*string{ + aws.String(cache.vpcID), + }, + }, } if cache.clusterName != "" { leakedENIFilters = append(leakedENIFilters, &ec2.Filter{ diff --git a/pkg/awsutils/awsutils_test.go b/pkg/awsutils/awsutils_test.go index 30cbe5669a..cf93040526 100644 --- a/pkg/awsutils/awsutils_test.go +++ b/pkg/awsutils/awsutils_test.go @@ -1261,6 +1261,10 @@ func TestEC2InstanceMetadataCache_getLeakedENIs(t *testing.T) { Name: aws.String("status"), Values: []*string{aws.String("available")}, }, + { + Name: aws.String("vpc-id"), + Values: []*string{aws.String(vpcID)}, + }, }, MaxResults: aws.Int64(1000), }, @@ -1290,6 +1294,10 @@ func TestEC2InstanceMetadataCache_getLeakedENIs(t *testing.T) { Name: aws.String("status"), Values: []*string{aws.String("available")}, }, + { + Name: aws.String("vpc-id"), + Values: []*string{aws.String(vpcID)}, + }, }, MaxResults: aws.Int64(1000), }, @@ -1351,6 +1359,10 @@ func TestEC2InstanceMetadataCache_getLeakedENIs(t *testing.T) { Name: aws.String("status"), Values: []*string{aws.String("available")}, }, + { + Name: aws.String("vpc-id"), + Values: []*string{aws.String(vpcID)}, + }, }, MaxResults: aws.Int64(1000), }, @@ -1396,6 +1408,10 @@ func TestEC2InstanceMetadataCache_getLeakedENIs(t *testing.T) { Name: aws.String("status"), Values: []*string{aws.String("available")}, }, + { + Name: aws.String("vpc-id"), + Values: []*string{aws.String(vpcID)}, + }, }, MaxResults: aws.Int64(1000), }, @@ -1441,6 +1457,10 @@ func TestEC2InstanceMetadataCache_getLeakedENIs(t *testing.T) { Name: aws.String("status"), Values: []*string{aws.String("available")}, }, + { + Name: aws.String("vpc-id"), + Values: []*string{aws.String(vpcID)}, + }, }, MaxResults: aws.Int64(1000), }, @@ -1470,6 +1490,10 @@ func TestEC2InstanceMetadataCache_getLeakedENIs(t *testing.T) { Name: aws.String("status"), Values: []*string{aws.String("available")}, }, + { + Name: aws.String("vpc-id"), + Values: []*string{aws.String(vpcID)}, + }, { Name: aws.String("tag:cluster.k8s.amazonaws.com/name"), Values: []*string{aws.String("awesome-cluster")}, @@ -1543,6 +1567,10 @@ func TestEC2InstanceMetadataCache_getLeakedENIs(t *testing.T) { Name: aws.String("status"), Values: []*string{aws.String("available")}, }, + { + Name: aws.String("vpc-id"), + Values: []*string{aws.String(vpcID)}, + }, { Name: aws.String("tag:cluster.k8s.amazonaws.com/name"), Values: []*string{aws.String("awesome-cluster")}, @@ -1596,6 +1624,10 @@ func TestEC2InstanceMetadataCache_getLeakedENIs(t *testing.T) { Name: aws.String("status"), Values: []*string{aws.String("available")}, }, + { + Name: aws.String("vpc-id"), + Values: []*string{aws.String(vpcID)}, + }, { Name: aws.String("tag:cluster.k8s.amazonaws.com/name"), Values: []*string{aws.String("awesome-cluster")}, @@ -1653,7 +1685,7 @@ func TestEC2InstanceMetadataCache_getLeakedENIs(t *testing.T) { return nil }) } - cache := &EC2InstanceMetadataCache{ec2SVC: mockEC2, clusterName: tt.fields.clusterName} + cache := &EC2InstanceMetadataCache{ec2SVC: mockEC2, clusterName: tt.fields.clusterName, vpcID: vpcID} got, err := cache.getLeakedENIs() if tt.wantErr != nil { assert.EqualError(t, err, tt.wantErr.Error())