Skip to content

Commit

Permalink
Tag ENI with creation timestamp and avoid cleanup if created in last …
Browse files Browse the repository at this point in the history
…5 mins

Fix unit test cases

address CR comments
  • Loading branch information
jayanthvn committed Aug 6, 2020
1 parent 4c0c357 commit f39951c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pkg/awsutils/awsutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1325,7 +1325,7 @@ func (cache *EC2InstanceMetadataCache) tagENIcreateTS(eniID string, maxBackoffDe
awsAPILatency.WithLabelValues("CreateTags", fmt.Sprint(err != nil)).Observe(msSince(start))
if err != nil {
awsAPIErrInc("CreateTags", err)
log.Warnf("Failed to tag the newly created ENI %s:", eniID)
log.Warnf("Failed to add tag to ENI %s: %v", eniID, err)
return err
}
log.Debugf("Successfully tagged ENI: %s", eniID)
Expand Down Expand Up @@ -1371,15 +1371,18 @@ func (cache *EC2InstanceMetadataCache) getFilteredListOfNetworkInterfaces() ([]*
if value, ok := tags[eniCreatedAtTagKey]; ok {
parsedTime, err := time.Parse(time.RFC3339, value)
if err != nil {

log.Warnf("ParsedTime format %s is wrong so retagging with current TS", parsedTime)
cache.tagENIcreateTS(aws.StringValue(networkInterface.NetworkInterfaceId), maxENIBackoffDelay)
}
if time.Since(parsedTime) < (5 * time.Minute) {
log.Infof("Found ENI created less than 5 mins so not cleaning up")
log.Infof("Found an ENI created less than 5 mins so not cleaning it up")
continue
}
log.Debugf("%v", value)
} else {
//Set time if we didn't have one. This is to catch the v1.5.x or earlier CNI versions.
/* Set a time if we didn't find one. This is to prevent accidentally deleting ENIs that are in the
* process of being attached by CNI versions v1.5.x or earlier.
*/
cache.tagENIcreateTS(aws.StringValue(networkInterface.NetworkInterfaceId), maxENIBackoffDelay)
continue
}
Expand Down

0 comments on commit f39951c

Please sign in to comment.