Merge pull request #999 from googs1025/refactor/custom_plugin
Some checks failed
CodeQL / Analyze (go) (push) Failing after 11m30s
Scorecard supply-chain security / Scorecard analysis (push) Failing after 2m12s

chore: refactor custom plugin monitor method
This commit is contained in:
Kubernetes Prow Robot
2024-12-28 14:24:13 +01:00
committed by GitHub
2 changed files with 14 additions and 10 deletions

View File

@@ -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)

View File

@@ -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.