-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
Send events before adding watchers in traversePluginDir #75110
Conversation
5bb7b99
to
4a6ee18
Compare
/retest |
4a6ee18
to
162ad75
Compare
4728f40
to
b7c93d2
Compare
CC @kubernetes/sig-node-pr-reviews |
/skip |
all the required CI jobs are green on this PR, ready for node/storage review |
/remove-label do-not-merge/work-in-progress |
Op: fsnotify.Create, | ||
} | ||
//TODO: Handle errors by taking corrective measures | ||
if err := w.handleCreateEvent(event); err != nil { |
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.
Looking at the implementation of handleCreateEvent, I think it's more direct to just do:
if !w.containsBlacklistedDir(path) {
return w.traversePluginDir(path)
}
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.
Not sure if I follow, do you mean inside handleCreateEvent
? If so, then it wouldn't call handlePluginRegistration
... or am I missing somehting?
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.
I mean "handle create event" doesn't really seem like what this is doing, unless I'm not following the control flow. If you look at what handle create event is doing, the snippet I commented above is all that gets hit in that function, so I'm suggesting to just inline that piece here.
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.
Ah, OK... I understand now...
This part of the code creates "synthetic create events" if we find a socket file. Then we "handle" this event right here (as opposed to sending it to a processing goroutine like it was before).
Since we're dealing with a socket file, we don't really want to traversePluginDir()
it, but instead we want to register the plugin that's listening to this unix domain socket file (i.e., handlePluginRegistration()
).
However, we also need to make sure that we ignore black-listed directories (like you pointed in the snippet above) and files prefixed with a "."; this would do it:
if !w.containsBlacklistedDir(path) {
if !strings.HasPrefix(path, ".") {
// TODO: Handle errors by taking corrective measures
if err := w.handlePluginRegistration(path); err != nil {
klog.Errorf("error %v when handling create event for file: %s", err, path)
}
}
}
IMO handleCreateEvent()
looks like would be a better fit though (since we're almost re-implementing it in-line).
Does this make sense?
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.
Ah, sorry, I completely misread what handleCreateEvent
was doing.
select { | ||
case <-c: | ||
return | ||
case <-time.After(2 * time.Second): |
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.
case <-time.After(2 * time.Second): | |
case <-time.After(wait.ForeverTestTimeout): |
You can't wait timeout before that in a unit test, as it will flake in the CI environment.
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.
Fixed. I took the chance and fixed the other time.After
calls from this file.
defer close(c) | ||
require.True(t, waitForEvent(t, exampleEventValidate, hdlr.EventChan(p.pluginName))) | ||
require.False(t, waitForPluginRegistrationStatus(t, p.registrationStatus)) | ||
}() |
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.
alternatively, you can just do this serially at the end of the test and rely on the whole test timing out for the failure condition.
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.
Since we're processing plugins serially now, newWatcherWithHandler
below would block forever trying to write to the event/registration channels. This goroutine prevents that by receiving info from these channels beforehand.
5f01ebb
to
9d99c7f
Compare
/skip |
/retest |
9d99c7f
to
5a32553
Compare
Currently, the method `pluginwatcher.traversePluginDir` descends into a directory adding filesystem watchers and creating synthetic `create` events when it finds sockets files. However, a race condition might happen when a recently-added watcher observes a `delete` event in a socket file before `pluginwatcher.traversePlugindir` itself notices this file. This patch changes this behavior by registering watchers on directories, enqueueing and processing `create` events from sockets found, and only then processing the events from the registered watchers.
5a32553
to
f564557
Compare
@bertinatto: The following tests failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
/skip |
/retest |
/assign @derekwaynecarr |
/lgtm |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: bertinatto, tallclair The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Op: fsnotify.Create, | ||
} | ||
//TODO: Handle errors by taking corrective measures | ||
if err := w.handleCreateEvent(event); err != nil { |
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.
Shouldn't the err be returned, in the same way error is returned for mode.IsDir() case ?
I created PR #77244
What type of PR is this?
/kind bug
What this PR does / why we need it:
This PR changes the function
devicemanager.traversePluginDir
in order to send events before adding watchers to directories.Which issue(s) this PR fixes:
Fixes #75097
Does this PR introduce a user-facing change?:
/sig storage
/sig node
/assign @liggitt