Tag ENI with creation timestamp and avoid cleanup if created in last … #1109
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…5 mins
Issue #, if available:
Description of changes:
Tag EKS created ENI with creation timestamp. While checking for leaked ENIs we prevent deletes of ENIs created in the last 5 minutes. Also for scenarios where Cx has one cluster with 1.5. x and another with 1.6.x - The cleanup function in 1.6.x looks for ENIs that are created by the CNI, but not attached to any instance. In 1.6.0 we tag the ENI with the instance name after it has been attached. In 1.5.x, we tag the nodes first, then attach them. If we find any such ENIs then we update with new time preventing those to be deleted.
Issue logs debugged by internal support team->
Due to a change introduced since 1.6.0 (clean up ENIs), with both version running at the same time, it will cause the ENI created with pre 1.6.0 version randomly got deleted by CNI running 1.6.0.
getFilteredListOfNetworkInterfaces
will check tag keynode.k8s.amazonaws.com/instance_id
and the ENI status. The ENI status needs to beavailable
, to be included to clean up:Create ENI
Attach ENI
Tag ENI
Since ENI will only be tagged after attached, this ensures the newly created ENI will not meet the filter above, so this ensures newly created ENI won't get cleaned up.
The order is different:
Create ENI
Tag ENI
Attach ENI
So in this case, CNI 1.5.5 from instance i-0dd659cd2b0acd35e created ENI eni-08cec64239ece5335 and tagged it immediately not yet attaching it:
This newly created ENI, has the tag key, and it is available status, perfectly matches the filter for CNI 1.6.0 to delete, so CNI 1.6.0 from instance i-0c91507c3fa5a862a deleted this ENI.
CNI 1.5.5/7 from instance i-0dd659cd2b0acd35e then tried to attach the ENI, and failed, because ENI has been deleted:
Logs after fix ->
Thanks to @mogren
Updated the Unit test to simulate ENI create TS to be 10 mins before the the current time.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.