-
Notifications
You must be signed in to change notification settings - Fork 753
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
Clean up leaked ENIs in the background #624
Conversation
Logs:
|
e56efa2
to
24c5d17
Compare
24c5d17
to
2824a32
Compare
2e76098
to
0512000
Compare
@@ -62,6 +64,9 @@ const ( | |||
|
|||
// UnknownInstanceType indicates that the instance type is not yet supported | |||
UnknownInstanceType = "vpc ip resource(eni ip limit): unknown instance type" | |||
|
|||
// Stagger cleanup start time to avoid calling EC2 too much. Time in seconds. | |||
eniCleanupStartupDelayMax = 300 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make the value 300 * time.Second
to make the units clear instead of just saying that in a comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it's used in a call to rand, so it can't be a duration. It's just a random upper limit.
startupDelay := time.Duration(rand.Intn(eniCleanupStartupDelayMax)) * time.Second
Cleaned up the printing a bit.
pkg/awsutils/awsutils.go
Outdated
} | ||
// Sleep one hour before checking again | ||
time.Sleep(1 * time.Hour) | ||
log.Debug("Checking for leaked AWS CNI ENIs.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move this log line to the top of the for loop to make it more accurate?
pkg/awsutils/awsutils.go
Outdated
// Clean up all the leaked ones we found | ||
for _, networkInterface := range networkInterfaces { | ||
// Verify the description starts with "aws-K8S-" | ||
if !strings.HasPrefix(aws.StringValue(networkInterface.Description), eniDescriptionPrefix) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move this filtering into the getFilteredListOfNetworkInterfaces()
to keep the logic clean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, will do :)
pkg/awsutils/awsutils.go
Outdated
@@ -223,6 +228,10 @@ func New() (*EC2InstanceMetadataCache, error) { | |||
if err != nil { | |||
return nil, err | |||
} | |||
|
|||
// Clean up leaked ENIs in the background | |||
go cache.cleanUpLeakedENIs() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of running a goroutine which infinitely loops with sleep in each iteration, you can do it a bit more cleanly as follows:
go wait.Until(cache.cleanUpLeakedENIs, time.Hour, wait.NeverStop)
And then the function itself can be a one-off operation:
func (cache *EC2InstanceMetadataCache) cleanUpLeakedENIs() {
// list enis
// delete enis
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found this:
go wait.Forever(cache.cleanUpLeakedENIs, time.Hour)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2019-09-27T18:59:25.632Z [INFO] Will attempt to clean up AWS CNI leaked ENIs after waiting 3m1s.
2019-09-27T19:02:26.633Z [DEBUG] Checking for leaked AWS CNI ENIs.
2019-09-27T19:02:26.934Z [DEBUG] No AWS CNI leaked ENIs found.
2019-09-27T20:02:26.934Z [INFO] Will attempt to clean up AWS CNI leaked ENIs after waiting 2m9s.
2019-09-27T20:04:35.934Z [DEBUG] Checking for leaked AWS CNI ENIs.
2019-09-27T20:04:36.057Z [DEBUG] No AWS CNI leaked ENIs found.
0512000
to
3fd6cb4
Compare
Issue #, if available: #608
Description of changes:
available
node.k8s.amazonaws.com/instance_id
aws-K8S-
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.