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

Filter ENIs based on VPC CNI applied tag #417

Merged
merged 1 commit into from
Jan 10, 2024
Merged
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
14 changes: 12 additions & 2 deletions kubetest2/internal/deployers/eksapi/infra.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ const (
networkInterfaceDetachmentTimeout = time.Minute * 5
)

const (
// the VPC CNI will always add this tag to ENI's that it creates
vpcCNIENITagKey = "node.k8s.amazonaws.com/createdAt"
)

// eksEndpointURLTag is the key for an optional tag on the infrastructure CloudFormation stack,
// which indicates which EKS environment is associated with the stack's resources.
// The tag is only added when --endpoint-url is passed to the deployer.
Expand Down Expand Up @@ -182,7 +187,7 @@ func (m *InfrastructureManager) deleteLeakedENIs() error {
}
return fmt.Errorf("failed to get infrastructure stack resources: %w", err)
}
enis, err := m.getNetworkInterfaceIds(infra.vpc)
enis, err := m.getVPCCNINetworkInterfaceIds(infra.vpc)
if err != nil {
return err
}
Expand All @@ -208,7 +213,8 @@ func (m *InfrastructureManager) deleteLeakedENIs() error {
return nil
}

func (m *InfrastructureManager) getNetworkInterfaceIds(vpcId string) ([]string, error) {
// getVPCCNINetworkInterfaceIds returns the IDs of ENIs in the specified VPC that were created by the VPC CNI
func (m *InfrastructureManager) getVPCCNINetworkInterfaceIds(vpcId string) ([]string, error) {
paginator := ec2.NewDescribeNetworkInterfacesPaginator(m.clients.EC2(), &ec2.DescribeNetworkInterfacesInput{
Filters: []ec2types.Filter{
{
Expand All @@ -219,6 +225,10 @@ func (m *InfrastructureManager) getNetworkInterfaceIds(vpcId string) ([]string,
Name: aws.String("interface-type"),
Values: []string{"interface"},
},
{
Name: aws.String("tag-key"),
Values: []string{vpcCNIENITagKey},
},
},
})
var enis []string
Expand Down