Skip to content

Commit 32f8a10

Browse files
committed
chore: refactor custom plugin monitor method
1 parent 334a857 commit 32f8a10

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

Diff for: pkg/custompluginmonitor/custom_plugin_monitor.go

+13-9
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ func (c *customPluginMonitor) Stop() {
123123
// there is one customPluginMonitor, one plugin instance for each configPath.
124124
// each runs rules in parallel at pre-configured concurrency, and interval.
125125
func (c *customPluginMonitor) monitorLoop() {
126-
if !*c.config.PluginGlobalConfig.SkipInitialStatus {
127-
c.initializeStatus()
126+
c.initializeConditions()
127+
if *c.config.PluginGlobalConfig.SkipInitialStatus {
128+
klog.Infof("Skipping sending initial status. Using default conditions: %+v", c.conditions)
128129
} else {
129-
c.conditions = initialConditions(c.config.DefaultConditions)
130-
klog.Infof("Skipping condition initialization: %+v", c.conditions)
130+
c.sendInitialStatus()
131131
}
132132

133133
resultChan := c.plugin.GetResultChan()
@@ -296,18 +296,22 @@ func toConditionStatus(s cpmtypes.Status) types.ConditionStatus {
296296
}
297297
}
298298

299-
// initializeStatus initializes the internal condition and also reports it to the node problem detector.
300-
func (c *customPluginMonitor) initializeStatus() {
301-
// Initialize the default node conditions
302-
c.conditions = initialConditions(c.config.DefaultConditions)
303-
klog.Infof("Initialize condition generated: %+v", c.conditions)
299+
// sendInitialStatus sends the initial status to the node problem detector.
300+
func (c *customPluginMonitor) sendInitialStatus() {
301+
klog.Infof("Sending initial status for %s with conditions: %+v", c.config.Source, c.conditions)
304302
// Update the initial status
305303
c.statusChan <- &types.Status{
306304
Source: c.config.Source,
307305
Conditions: c.conditions,
308306
}
309307
}
310308

309+
// initializeConditions initializes the internal node conditions.
310+
func (c *customPluginMonitor) initializeConditions() {
311+
c.conditions = initialConditions(c.config.DefaultConditions)
312+
klog.Infof("Initialized conditions for %s: %+v", c.configPath, c.conditions)
313+
}
314+
311315
func initialConditions(defaults []types.Condition) []types.Condition {
312316
conditions := make([]types.Condition, len(defaults))
313317
copy(conditions, defaults)

Diff for: pkg/custompluginmonitor/plugin/plugin.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ func (p *Plugin) run(rule cpmtypes.CustomRule) (exitStatus cpmtypes.Status, outp
266266
return cpmtypes.NonOK, output
267267
default:
268268
logPluginStderr(rule, string(stderr), 0)
269-
return cpmtypes.Unknown, output
269+
return cpmtypes.Unknown, fmt.Sprintf("Plugin exited with unexpected code %d. "+
270+
"Please check the error log: %s", exitCode, output)
270271
}
271272
}
272273

Diff for: pkg/custompluginmonitor/types/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ type pluginGlobalConfig struct {
5757
SkipInitialStatus *bool `json:"skip_initial_status,omitempty"`
5858
}
5959

60-
// Custom plugin config is the configuration of custom plugin monitor.
60+
// CustomPluginConfig is the configuration of custom plugin monitor.
6161
type CustomPluginConfig struct {
6262
// Plugin is the name of plugin which is currently used.
6363
// Currently supported: custom.

0 commit comments

Comments
 (0)