Skip to content

Commit 3409f56

Browse files
committed
keeping cluster tag same as vpc-cni
1 parent 9b48a15 commit 3409f56

File tree

5 files changed

+15
-13
lines changed

5 files changed

+15
-13
lines changed

pkg/aws/ec2/api/cleanup/eni_cleanup.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ func (e *ENICleaner) DeleteLeakedResources() error {
133133
describeNetworkInterfaceIp := &ec2.DescribeNetworkInterfacesInput{
134134
Filters: filters,
135135
}
136-
137136
networkInterfaces, err := e.EC2Wrapper.DescribeNetworkInterfacesPagesWithRetry(describeNetworkInterfaceIp)
138137
if err != nil {
139138
e.Log.Error(err, "failed to describe network interfaces, cleanup will be retried in next cycle")
@@ -169,9 +168,12 @@ func (e *ENICleaner) DeleteLeakedResources() error {
169168
}
170169
continue
171170
}
172-
e.Log.Info("deleted leaked ENI successfully",
173-
"eniID", nwInterface.NetworkInterfaceId,
174-
"instanceID", lo.TernaryF(nwInterface.Attachment == nil, func() *string { return lo.ToPtr("") }, func() *string { return nwInterface.Attachment.InstanceId }))
171+
// It is possible for eni attachment to be nil, if it was never attached to instance
172+
instanceID := ""
173+
if nwInterface.Attachment != nil && nwInterface.Attachment.InstanceId != nil {
174+
instanceID = aws.ToString(nwInterface.Attachment.InstanceId)
175+
}
176+
e.Log.Info("deleted leaked ENI successfully", "eni id", *nwInterface.NetworkInterfaceId, "instance id", instanceID)
175177
} else {
176178
// Seeing the ENI for the first time, add it to the new list of available network interfaces
177179
availableENIs[*nwInterface.NetworkInterfaceId] = struct{}{}
@@ -184,11 +186,11 @@ func (e *ENICleaner) DeleteLeakedResources() error {
184186
}
185187

186188
func (e *ClusterENICleaner) GetENITagFilters() []ec2types.Filter {
187-
clusterNameTagKey := fmt.Sprintf(config.ClusterNameTagKeyFormat, e.ClusterName)
189+
clusterNameTagKey := config.CNINodeClusterNameKey
188190
return []ec2types.Filter{
189191
{
190192
Name: aws.String("tag:" + clusterNameTagKey),
191-
Values: []string{config.ClusterNameTagValue},
193+
Values: []string{e.ClusterName},
192194
},
193195
}
194196
}

pkg/aws/ec2/api/cleanup/eni_cleanup_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ package cleanup
1515

1616
import (
1717
"context"
18-
"fmt"
1918
"reflect"
2019
"testing"
2120

@@ -33,7 +32,7 @@ import (
3332
var (
3433
mockClusterName = "cluster-name"
3534
mockNodeID = "i-00000000000000001"
36-
mockClusterNameTagKey = fmt.Sprintf(config.ClusterNameTagKeyFormat, mockClusterName)
35+
mockClusterNameTagKey = config.CNINodeClusterNameKey
3736

3837
mockNetworkInterfaceId1 = "eni-000000000000000"
3938
mockNetworkInterfaceId2 = "eni-000000000000001"
@@ -60,7 +59,7 @@ var (
6059
},
6160
{
6261
Name: aws.String("tag:" + mockClusterNameTagKey),
63-
Values: []string{config.ClusterNameTagValue},
62+
Values: []string{mockClusterName},
6463
},
6564
},
6665
}

pkg/aws/ec2/api/helper.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ func NewEC2APIHelper(ec2Wrapper EC2Wrapper, clusterName string) EC2APIHelper {
6969
// Set the key and value of the cluster name tag which will be used to tag all the network interfaces created by
7070
// the controller
7171
clusterNameTag = ec2types.Tag{
72-
Key: aws.String(fmt.Sprintf(config.ClusterNameTagKeyFormat, clusterName)),
73-
Value: aws.String(config.ClusterNameTagValue),
72+
Key: aws.String(config.CNINodeClusterNameKey),
73+
Value: aws.String(clusterName),
7474
}
7575
return &ec2APIHelper{ec2Wrapper: ec2Wrapper}
7676
}

pkg/aws/ec2/api/helper_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ var (
8383
}
8484

8585
defaultClusterNameTag = ec2types.Tag{
86-
Key: aws.String(fmt.Sprintf(config.ClusterNameTagKeyFormat, clusterName)),
87-
Value: aws.String(config.ClusterNameTagValue),
86+
Key: aws.String(config.CNINodeClusterNameKey),
87+
Value: aws.String(clusterName),
8888
}
8989

9090
createNetworkInterfaceInput = &ec2.CreateNetworkInterfaceInput{

pkg/aws/ec2/api/wrapper.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,7 @@ func (e *ec2Wrapper) DescribeNetworkInterfacesPagesWithRetry(input *ec2.Describe
761761
attemptInterfaces = append(attemptInterfaces, &ec2types.NetworkInterface{
762762
NetworkInterfaceId: nwInterface.NetworkInterfaceId,
763763
TagSet: nwInterface.TagSet,
764+
Attachment: nwInterface.Attachment,
764765
})
765766
}
766767

0 commit comments

Comments
 (0)