mirror of
https://github.com/kubernetes/node-problem-detector.git
synced 2026-08-19 20:26:32 +00:00
Validate that permanent problem has preset default condition
This commit is contained in:
@@ -141,5 +141,22 @@ func (cpc CustomPluginConfig) Validate() error {
|
||||
}
|
||||
}
|
||||
|
||||
for _, rule := range cpc.Rules {
|
||||
if rule.Type != types.Perm {
|
||||
continue
|
||||
}
|
||||
conditionType := rule.Condition
|
||||
defaultConditionExists := false
|
||||
for _, cond := range cpc.DefaultConditions {
|
||||
if conditionType == cond.Type {
|
||||
defaultConditionExists = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !defaultConditionExists {
|
||||
return fmt.Errorf("Permanent problem %s does not have preset default condition.", conditionType)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"k8s.io/node-problem-detector/pkg/types"
|
||||
)
|
||||
|
||||
func TestCustomPluginConfigApplyConfiguration(t *testing.T) {
|
||||
@@ -279,6 +281,55 @@ func TestCustomPluginConfigValidate(t *testing.T) {
|
||||
},
|
||||
IsError: true,
|
||||
},
|
||||
"permanent problem has preset default condition": {
|
||||
Conf: CustomPluginConfig{
|
||||
Plugin: customPluginName,
|
||||
PluginGlobalConfig: pluginGlobalConfig{
|
||||
InvokeInterval: &defaultInvokeInterval,
|
||||
Timeout: &defaultGlobalTimeout,
|
||||
MaxOutputLength: &defaultMaxOutputLength,
|
||||
Concurrency: &defaultConcurrency,
|
||||
},
|
||||
DefaultConditions: []types.Condition{
|
||||
{
|
||||
Type: "TestCondition",
|
||||
Reason: "TestConditionOK",
|
||||
Message: "Test condition is OK.",
|
||||
},
|
||||
},
|
||||
Rules: []*CustomRule{
|
||||
{
|
||||
Type: types.Perm,
|
||||
Condition: "TestCondition",
|
||||
Reason: "TestConditionFail",
|
||||
Path: "../plugin/test-data/ok.sh",
|
||||
Timeout: &normalRuleTimeout,
|
||||
},
|
||||
},
|
||||
},
|
||||
IsError: false,
|
||||
},
|
||||
"permanent problem does not have preset default condition": {
|
||||
Conf: CustomPluginConfig{
|
||||
Plugin: customPluginName,
|
||||
PluginGlobalConfig: pluginGlobalConfig{
|
||||
InvokeInterval: &defaultInvokeInterval,
|
||||
Timeout: &defaultGlobalTimeout,
|
||||
MaxOutputLength: &defaultMaxOutputLength,
|
||||
Concurrency: &defaultConcurrency,
|
||||
},
|
||||
Rules: []*CustomRule{
|
||||
{
|
||||
Type: types.Perm,
|
||||
Condition: "TestCondition",
|
||||
Reason: "TestConditionFail",
|
||||
Path: "../plugin/test-data/ok.sh",
|
||||
Timeout: &normalRuleTimeout,
|
||||
},
|
||||
},
|
||||
},
|
||||
IsError: true,
|
||||
},
|
||||
}
|
||||
|
||||
for desp, utMeta := range utMetas {
|
||||
|
||||
Reference in New Issue
Block a user