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

handle EFA security group eni leakage #534

Merged
merged 6 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
57 changes: 57 additions & 0 deletions kubetest2/internal/deployers/eksapi/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,8 @@ func (m *nodeManager) createUnmanagedNodegroup(infra *Infrastructure, cluster *C
}

func (m *nodeManager) createUnmanagedNodegroupWithEFA(infra *Infrastructure, cluster *Cluster, opts *deployerOptions) error {
//update cluster default security group With EFA required ingress egress rule
m.updateDefaultSecurityGroupWithEFA(cluster.securityGroupId)
stackName := m.getUnmanagedNodegroupStackName()
klog.Infof("creating unmanaged nodegroup with EFA stack...")
userData, userDataIsMimePart, err := generateUserData(opts.UserDataFormat, cluster)
Expand Down Expand Up @@ -517,6 +519,60 @@ func (m *nodeManager) createUnmanagedNodegroupWithEFA(infra *Infrastructure, clu
return nil
}

func (m *nodeManager) updateDefaultSecurityGroupWithEFA(defaultSGID string) error {
// Add ingress rules
ingressInput := &ec2.AuthorizeSecurityGroupIngressInput{
GroupId: aws.String(defaultSGID),
IpPermissions: []ec2types.IpPermission{
{
IpProtocol: aws.String("tcp"),
FromPort: aws.Int32(443),
ToPort: aws.Int32(443),
UserIdGroupPairs: []ec2types.UserIdGroupPair{
{
GroupId: aws.String(defaultSGID),
},
},
},
{
IpProtocol: aws.String("tcp"),
FromPort: aws.Int32(1025),
ToPort: aws.Int32(65535),
UserIdGroupPairs: []ec2types.UserIdGroupPair{
{
GroupId: aws.String(defaultSGID),
},
},
},
},
}
_, err := m.clients.EC2().AuthorizeSecurityGroupIngress(context.TODO(), ingressInput)
if err != nil {
return fmt.Errorf("failed to authorize security group ingress: %v", err)
}

// Add egress rules
egressInput := &ec2.AuthorizeSecurityGroupEgressInput{
GroupId: aws.String(defaultSGID),
IpPermissions: []ec2types.IpPermission{
{
IpProtocol: aws.String("-1"),
UserIdGroupPairs: []ec2types.UserIdGroupPair{
{
GroupId: aws.String(defaultSGID),
},
},
},
},
}
_, err = m.clients.EC2().AuthorizeSecurityGroupEgress(context.TODO(), egressInput)
if err != nil {
return fmt.Errorf("failed to authorize security group egress: %v", err)
}

return nil
}

func (m *nodeManager) deleteNodes() error {
if err := m.deleteUnmanagedNodegroup(); err != nil {
return err
Expand Down Expand Up @@ -567,6 +623,7 @@ func (m *nodeManager) deleteUnmanagedNodegroup() error {
}
return fmt.Errorf("failed to delete unmanaged nodegroup stack: %w", err)
}

klog.Infof("waiting for unmanaged nodegroup stack to be deleted: %s", stackName)
err = cloudformation.NewStackDeleteCompleteWaiter(m.clients.CFN()).
Wait(context.TODO(),
Expand Down
Loading
Loading