validate ipvs scheduler

This commit is contained in:
m1093782566
2017-10-16 18:08:03 +08:00
parent 02f0d92160
commit 518936fb5f
2 changed files with 73 additions and 0 deletions

View File

@@ -38,6 +38,7 @@ func Validate(config *componentconfig.KubeProxyConfiguration) field.ErrorList {
allErrs = append(allErrs, validateKubeProxyConntrackConfiguration(config.Conntrack, newPath.Child("KubeProxyConntrackConfiguration"))...)
allErrs = append(allErrs, validateProxyMode(config.Mode, newPath.Child("Mode"))...)
allErrs = append(allErrs, validateClientConnectionConfiguration(config.ClientConnection, newPath.Child("ClientConnection"))...)
allErrs = append(allErrs, validateIPVSSchedulerMethod(config.IPVS.Scheduler, newPath.Child("KubeProxyIPVSConfiguration").Child("Scheduler"))...)
if config.OOMScoreAdj != nil && (*config.OOMScoreAdj < -1000 || *config.OOMScoreAdj > 1000) {
allErrs = append(allErrs, field.Invalid(newPath.Child("OOMScoreAdj"), *config.OOMScoreAdj, "must be within the range [-1000, 1000]"))
@@ -156,3 +157,33 @@ func validateHostPort(input string, fldPath *field.Path) field.ErrorList {
return allErrs
}
func validateIPVSSchedulerMethod(scheduler string, fldPath *field.Path) field.ErrorList {
supportedMethod := []string{
string(componentconfig.RoundRobin),
string(componentconfig.WeightedRoundRobin),
string(componentconfig.LeastConnection),
string(componentconfig.WeightedLeastConnection),
string(componentconfig.LocalityBasedLeastConnection),
string(componentconfig.LocalityBasedLeastConnectionWithReplication),
string(componentconfig.SourceHashing),
string(componentconfig.DestinationHashing),
string(componentconfig.ShortestExpectedDelay),
string(componentconfig.NeverQueue),
"",
}
allErrs := field.ErrorList{}
var found bool
for i := range supportedMethod {
if scheduler == supportedMethod[i] {
found = true
break
}
}
// Not found
if !found {
errMsg := fmt.Sprintf("must be in %v, blank means the default algorithm method (currently rr)", supportedMethod)
allErrs = append(allErrs, field.Invalid(fldPath.Child("Scheduler"), string(scheduler), errMsg))
}
return allErrs
}