Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: refactor custom plugin monitor method #999

Merged
merged 1 commit into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initializeStatus naming seems confusing, and the initialConditions does not need to be repeated

// 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
Loading