-
Notifications
You must be signed in to change notification settings - Fork 655
Run custom plugins immediately on startup #288
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
Conversation
Welcome @yguo0905! |
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.
Thanks for providing the reference!
@@ -55,41 +55,53 @@ func (p *Plugin) GetResultChan() <-chan cpmtypes.Result { | |||
func (p *Plugin) Run() { | |||
runTicker := time.NewTicker(*p.config.PluginGlobalConfig.InvokeInterval) |
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 think it's good to also clean up this code a little bit.
We could add a defer runTicker.Stop()
line after the initialization of runTicker:
runTicker := time.NewTicker(*p.config.PluginGlobalConfig.InvokeInterval)
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 catch.
select { | ||
case <-p.tomb.Stopping(): | ||
glog.Info("Stopping plugin execution") | ||
p.tomb.Done() |
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.
Perhaps it's better to just move this one p.tomb.Done()
and the one below to the top, as a defer p.tomb.Done()
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 don't see Stop()
is invoked anywhere. Do we support graceful shutdown?
But I changed it to use defer.
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.
Seems like tomb.Stop()
is called at here:
https://github.com/kubernetes/node-problem-detector/blame/v0.6.3/pkg/custompluginmonitor/custom_plugin_monitor.go#L84
+cc @andyxning for the context, as he wrote the code.
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 meant the customPluginMonitor
's Stop()
doesn't seem to be used anywhere
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.
Sorry for the late response. Actually customPluginMonitor
's Stop()
is not invoked anywhere. It is just to meet the requirement about implementing Monitor
interface.
Stop
should be called once p.Run
in node_problem_detector.go errors and is about to exit. @yguo0905 Could you take a look at this?
for { | ||
select { | ||
case <-runTicker.C: | ||
runner() | ||
case <-p.tomb.Stopping(): | ||
glog.Info("Stopping plugin execution") | ||
p.tomb.Done() |
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.
This is the second p.tomb.Done()
I'd prefer to be defer
-ed
/test pull-npd-test |
/lgtm This PR looks good to me. Although I probably don't have permission to approve. This is just FTR. |
@xueweiz: changing LGTM is restricted to assignees, and only kubernetes/node-problem-detector repo collaborators may be assigned issues. In response to this:
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. |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Random-Liu, xueweiz, yguo0905 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 |
/hold wait for @wangzhen127 to take a look |
/lgtm |
time.Ticker
doesn't fire instantly so the custom plugins are not run immediately on NPD startup. Some plugins may be configured with long pull interval.We'd like to see their first run when the cluster is just created, so changing it accordingly.
Following the advice on golang/go#17601 (comment).
/assign @Random-Liu
/assign @wangzhen127