Skip to content

Commit b5b61e4

Browse files
committed
Validate that permanent problem has preset default condition
1 parent 4d8fc30 commit b5b61e4

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

pkg/custompluginmonitor/types/config.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,5 +141,22 @@ func (cpc CustomPluginConfig) Validate() error {
141141
}
142142
}
143143

144+
for _, rule := range cpc.Rules {
145+
if rule.Type != types.Perm {
146+
continue
147+
}
148+
conditionType := rule.Condition
149+
defaultConditionExists := false
150+
for _, cond := range cpc.DefaultConditions {
151+
if conditionType == cond.Type {
152+
defaultConditionExists = true
153+
break
154+
}
155+
}
156+
if !defaultConditionExists {
157+
return fmt.Errorf("Permanent problem %s does not have preset default condition.", conditionType)
158+
}
159+
}
160+
144161
return nil
145162
}

pkg/custompluginmonitor/types/config_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import (
2020
"reflect"
2121
"testing"
2222
"time"
23+
24+
"k8s.io/node-problem-detector/pkg/types"
2325
)
2426

2527
func TestCustomPluginConfigApplyConfiguration(t *testing.T) {
@@ -279,6 +281,55 @@ func TestCustomPluginConfigValidate(t *testing.T) {
279281
},
280282
IsError: true,
281283
},
284+
"permanent problem has preset default condition": {
285+
Conf: CustomPluginConfig{
286+
Plugin: customPluginName,
287+
PluginGlobalConfig: pluginGlobalConfig{
288+
InvokeInterval: &defaultInvokeInterval,
289+
Timeout: &defaultGlobalTimeout,
290+
MaxOutputLength: &defaultMaxOutputLength,
291+
Concurrency: &defaultConcurrency,
292+
},
293+
DefaultConditions: []types.Condition{
294+
{
295+
Type: "TestCondition",
296+
Reason: "TestConditionOK",
297+
Message: "Test condition is OK.",
298+
},
299+
},
300+
Rules: []*CustomRule{
301+
{
302+
Type: types.Perm,
303+
Condition: "TestCondition",
304+
Reason: "TestConditionFail",
305+
Path: "../plugin/test-data/ok.sh",
306+
Timeout: &normalRuleTimeout,
307+
},
308+
},
309+
},
310+
IsError: false,
311+
},
312+
"permanent problem does not have preset default condition": {
313+
Conf: CustomPluginConfig{
314+
Plugin: customPluginName,
315+
PluginGlobalConfig: pluginGlobalConfig{
316+
InvokeInterval: &defaultInvokeInterval,
317+
Timeout: &defaultGlobalTimeout,
318+
MaxOutputLength: &defaultMaxOutputLength,
319+
Concurrency: &defaultConcurrency,
320+
},
321+
Rules: []*CustomRule{
322+
{
323+
Type: types.Perm,
324+
Condition: "TestCondition",
325+
Reason: "TestConditionFail",
326+
Path: "../plugin/test-data/ok.sh",
327+
Timeout: &normalRuleTimeout,
328+
},
329+
},
330+
},
331+
IsError: true,
332+
},
282333
}
283334

284335
for desp, utMeta := range utMetas {

0 commit comments

Comments
 (0)