Skip to content

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

Merged
merged 1 commit into from
Jun 4, 2019

Conversation

yguo0905
Copy link
Contributor

@yguo0905 yguo0905 commented Jun 4, 2019

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

@k8s-ci-robot
Copy link
Contributor

Welcome @yguo0905!

It looks like this is your first PR to kubernetes/node-problem-detector 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/node-problem-detector has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 4, 2019
Copy link
Contributor

@xueweiz xueweiz left a 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)
Copy link
Contributor

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)

Copy link
Contributor Author

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()
Copy link
Contributor

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()

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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

Copy link
Member

@andyxning andyxning Jun 5, 2019

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()
Copy link
Contributor

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

@yguo0905
Copy link
Contributor Author

yguo0905 commented Jun 4, 2019

/test pull-npd-test

@xueweiz
Copy link
Contributor

xueweiz commented Jun 4, 2019

/lgtm
/approve

This PR looks good to me. Although I probably don't have permission to approve. This is just FTR.

@k8s-ci-robot
Copy link
Contributor

@xueweiz: changing LGTM is restricted to assignees, and only kubernetes/node-problem-detector repo collaborators may be assigned issues.

In response to this:

/lgtm
/approve

This PR looks good to me. Although I probably don't have permission to approve. This is just FTR.

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.

@Random-Liu
Copy link
Member

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 4, 2019
@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 4, 2019
@Random-Liu
Copy link
Member

/hold wait for @wangzhen127 to take a look

@k8s-ci-robot k8s-ci-robot merged commit e2afd71 into kubernetes:master Jun 4, 2019
@wangzhen127
Copy link
Member

/lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants