Commit 2d9d8c40 authored by Bobby (Babak) Salamat's avatar Bobby (Babak) Salamat

Add validation for percentage-of-nodes-to-score of the scheduler config

parent a7da82fb
......@@ -44,6 +44,10 @@ func ValidateKubeSchedulerConfiguration(cc *config.KubeSchedulerConfiguration) f
if cc.BindTimeoutSeconds == nil {
allErrs = append(allErrs, field.Required(field.NewPath("bindTimeoutSeconds"), ""))
}
if cc.PercentageOfNodesToScore < 0 || cc.PercentageOfNodesToScore > 100 {
allErrs = append(allErrs, field.Invalid(field.NewPath("percentageOfNodesToScore"),
cc.PercentageOfNodesToScore, "not in valid range 0-100"))
}
return allErrs
}
......
......@@ -58,7 +58,8 @@ func TestValidateKubeSchedulerConfiguration(t *testing.T) {
RetryPeriod: metav1.Duration{Duration: 5 * time.Second},
},
},
BindTimeoutSeconds: &testTimeout,
BindTimeoutSeconds: &testTimeout,
PercentageOfNodesToScore: 35,
}
HardPodAffinitySymmetricWeightGt100 := validConfig.DeepCopy()
......@@ -92,6 +93,9 @@ func TestValidateKubeSchedulerConfiguration(t *testing.T) {
bindTimeoutUnset := validConfig.DeepCopy()
bindTimeoutUnset.BindTimeoutSeconds = nil
percentageOfNodesToScore101 := validConfig.DeepCopy()
percentageOfNodesToScore101.PercentageOfNodesToScore = int32(101)
scenarios := map[string]struct {
expectedToFail bool
config *config.KubeSchedulerConfiguration
......@@ -136,6 +140,10 @@ func TestValidateKubeSchedulerConfiguration(t *testing.T) {
expectedToFail: true,
config: bindTimeoutUnset,
},
"bad-percentage-of-nodes-to-score": {
expectedToFail: true,
config: percentageOfNodesToScore101,
},
}
for name, scenario := range scenarios {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment