mirror of
https://github.com/kubernetes/node-problem-detector.git
synced 2026-02-14 18:09:57 +00:00
chore: refactor custom plugin monitor method
This commit is contained in:
@@ -123,11 +123,11 @@ func (c *customPluginMonitor) Stop() {
|
||||
// there is one customPluginMonitor, one plugin instance for each configPath.
|
||||
// each runs rules in parallel at pre-configured concurrency, and interval.
|
||||
func (c *customPluginMonitor) monitorLoop() {
|
||||
if !*c.config.PluginGlobalConfig.SkipInitialStatus {
|
||||
c.initializeStatus()
|
||||
c.initializeConditions()
|
||||
if *c.config.PluginGlobalConfig.SkipInitialStatus {
|
||||
klog.Infof("Skipping sending initial status. Using default conditions: %+v", c.conditions)
|
||||
} else {
|
||||
c.conditions = initialConditions(c.config.DefaultConditions)
|
||||
klog.Infof("Skipping condition initialization: %+v", c.conditions)
|
||||
c.sendInitialStatus()
|
||||
}
|
||||
|
||||
resultChan := c.plugin.GetResultChan()
|
||||
@@ -296,11 +296,9 @@ func toConditionStatus(s cpmtypes.Status) types.ConditionStatus {
|
||||
}
|
||||
}
|
||||
|
||||
// initializeStatus initializes the internal condition and also reports it to the node problem detector.
|
||||
func (c *customPluginMonitor) initializeStatus() {
|
||||
// Initialize the default node conditions
|
||||
c.conditions = initialConditions(c.config.DefaultConditions)
|
||||
klog.Infof("Initialize condition generated: %+v", c.conditions)
|
||||
// sendInitialStatus sends the initial status to the node problem detector.
|
||||
func (c *customPluginMonitor) sendInitialStatus() {
|
||||
klog.Infof("Sending initial status for %s with conditions: %+v", c.config.Source, c.conditions)
|
||||
// Update the initial status
|
||||
c.statusChan <- &types.Status{
|
||||
Source: c.config.Source,
|
||||
@@ -308,6 +306,12 @@ func (c *customPluginMonitor) initializeStatus() {
|
||||
}
|
||||
}
|
||||
|
||||
// initializeConditions initializes the internal node conditions.
|
||||
func (c *customPluginMonitor) initializeConditions() {
|
||||
c.conditions = initialConditions(c.config.DefaultConditions)
|
||||
klog.Infof("Initialized conditions for %s: %+v", c.configPath, c.conditions)
|
||||
}
|
||||
|
||||
func initialConditions(defaults []types.Condition) []types.Condition {
|
||||
conditions := make([]types.Condition, len(defaults))
|
||||
copy(conditions, defaults)
|
||||
|
||||
@@ -57,7 +57,7 @@ type pluginGlobalConfig struct {
|
||||
SkipInitialStatus *bool `json:"skip_initial_status,omitempty"`
|
||||
}
|
||||
|
||||
// Custom plugin config is the configuration of custom plugin monitor.
|
||||
// CustomPluginConfig is the configuration of custom plugin monitor.
|
||||
type CustomPluginConfig struct {
|
||||
// Plugin is the name of plugin which is currently used.
|
||||
// Currently supported: custom.
|
||||
|
||||
Reference in New Issue
Block a user