Skip to content

Commit

Permalink
Add vpc-id to leaked eni filters
Browse files Browse the repository at this point in the history
  • Loading branch information
Joseph Chen committed Mar 21, 2024
1 parent 6bf43c9 commit a84e54f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
6 changes: 6 additions & 0 deletions pkg/awsutils/awsutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
34 changes: 33 additions & 1 deletion pkg/awsutils/awsutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
Expand Down Expand Up @@ -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),
},
Expand Down Expand Up @@ -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),
},
Expand Down Expand Up @@ -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),
},
Expand Down Expand Up @@ -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),
},
Expand Down Expand Up @@ -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")},
Expand Down Expand Up @@ -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")},
Expand Down Expand Up @@ -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")},
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit a84e54f

Please sign in to comment.