Validate that permanent problem has preset default condition

This commit is contained in:
Zhen Wang
2019-08-01 23:40:16 -07:00
parent 2f5d03280a
commit 30e20c6a20
2 changed files with 68 additions and 0 deletions
+17
View File
@@ -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 {