mirror of
https://github.com/kubernetes/node-problem-detector.git
synced 2026-08-28 01:47:20 +00:00
untangle plugin runner a bit
add some docs and make it clearer what is actually going on (parallel rule execution on start and then on timer)
This commit is contained in:
@@ -61,13 +61,32 @@ func (p *Plugin) Run() {
|
|||||||
runTicker := time.NewTicker(*p.config.PluginGlobalConfig.InvokeInterval)
|
runTicker := time.NewTicker(*p.config.PluginGlobalConfig.InvokeInterval)
|
||||||
defer runTicker.Stop()
|
defer runTicker.Stop()
|
||||||
|
|
||||||
runner := func() {
|
// on boot run once
|
||||||
|
select {
|
||||||
|
case <-p.tomb.Stopping():
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
p.runRules()
|
||||||
|
}
|
||||||
|
|
||||||
|
// run every InvokeInterval
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-runTicker.C:
|
||||||
|
p.runRules()
|
||||||
|
case <-p.tomb.Stopping():
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// run each rule in parallel and wait for them to complete
|
||||||
|
func (p *Plugin) runRules() {
|
||||||
glog.Info("Start to run custom plugins")
|
glog.Info("Start to run custom plugins")
|
||||||
|
|
||||||
for _, rule := range p.config.Rules {
|
for _, rule := range p.config.Rules {
|
||||||
p.syncChan <- struct{}{}
|
p.syncChan <- struct{}{}
|
||||||
p.Add(1)
|
p.Add(1)
|
||||||
|
|
||||||
go func(rule *cpmtypes.CustomRule) {
|
go func(rule *cpmtypes.CustomRule) {
|
||||||
defer p.Done()
|
defer p.Done()
|
||||||
defer func() {
|
defer func() {
|
||||||
@@ -96,23 +115,6 @@ func (p *Plugin) Run() {
|
|||||||
glog.Info("Finish running custom plugins")
|
glog.Info("Finish running custom plugins")
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
|
||||||
case <-p.tomb.Stopping():
|
|
||||||
return
|
|
||||||
default:
|
|
||||||
runner()
|
|
||||||
}
|
|
||||||
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-runTicker.C:
|
|
||||||
runner()
|
|
||||||
case <-p.tomb.Stopping():
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Plugin) run(rule cpmtypes.CustomRule) (exitStatus cpmtypes.Status, output string) {
|
func (p *Plugin) run(rule cpmtypes.CustomRule) (exitStatus cpmtypes.Status, output string) {
|
||||||
var ctx context.Context
|
var ctx context.Context
|
||||||
var cancel context.CancelFunc
|
var cancel context.CancelFunc
|
||||||
|
|||||||
Reference in New Issue
Block a user