Skip to content

Commit 053539e

Browse files
authored
Merge pull request #999 from googs1025/refactor/custom_plugin
chore: refactor custom plugin monitor method
2 parents 334a857 + cf0870f commit 053539e

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

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)

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)