Skip to content

Commit

Permalink
Merge pull request #999 from googs1025/refactor/custom_plugin
Browse files Browse the repository at this point in the history
chore: refactor custom plugin monitor method
  • Loading branch information
k8s-ci-robot authored Dec 28, 2024
2 parents 334a857 + cf0870f commit 053539e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
22 changes: 13 additions & 9 deletions pkg/custompluginmonitor/custom_plugin_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -296,18 +296,22 @@ 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,
Conditions: c.conditions,
}
}

// 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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/custompluginmonitor/types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 053539e

Please sign in to comment.