Introduce topology into the runtimeClass API
Co-authored-by: Tim Allclair <tallclair@google.com>
This commit is contained in:
committed by
Tim Allclair
parent
6049253aae
commit
009658d643
@@ -18,6 +18,7 @@ package validation
|
||||
|
||||
import (
|
||||
apivalidation "k8s.io/apimachinery/pkg/api/validation"
|
||||
unversionedvalidation "k8s.io/apimachinery/pkg/apis/meta/v1/validation"
|
||||
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||
"k8s.io/kubernetes/pkg/apis/core"
|
||||
corevalidation "k8s.io/kubernetes/pkg/apis/core/validation"
|
||||
@@ -35,6 +36,9 @@ func ValidateRuntimeClass(rc *node.RuntimeClass) field.ErrorList {
|
||||
if rc.Overhead != nil {
|
||||
allErrs = append(allErrs, validateOverhead(rc.Overhead, field.NewPath("overhead"))...)
|
||||
}
|
||||
if rc.Scheduling != nil {
|
||||
allErrs = append(allErrs, validateScheduling(rc.Scheduling, field.NewPath("scheduling"))...)
|
||||
}
|
||||
|
||||
return allErrs
|
||||
}
|
||||
@@ -52,3 +56,33 @@ func validateOverhead(overhead *node.Overhead, fldPath *field.Path) field.ErrorL
|
||||
// reuse the ResourceRequirements validation logic
|
||||
return corevalidation.ValidateResourceRequirements(&core.ResourceRequirements{Limits: overhead.PodFixed}, fldPath)
|
||||
}
|
||||
|
||||
func validateScheduling(s *node.Scheduling, fldPath *field.Path) field.ErrorList {
|
||||
var allErrs field.ErrorList
|
||||
if s.NodeSelector != nil {
|
||||
allErrs = append(allErrs, unversionedvalidation.ValidateLabels(s.NodeSelector, fldPath.Child("nodeSelector"))...)
|
||||
}
|
||||
allErrs = append(allErrs, validateTolerations(s.Tolerations, fldPath.Child("tolerations"))...)
|
||||
return allErrs
|
||||
}
|
||||
|
||||
func validateTolerations(tolerations []core.Toleration, fldPath *field.Path) field.ErrorList {
|
||||
allErrs := corevalidation.ValidateTolerations(tolerations, fldPath.Child("tolerations"))
|
||||
// Ensure uniquenes of tolerations.
|
||||
tolerationSet := map[core.Toleration]bool{}
|
||||
for i, t := range tolerations {
|
||||
// listKey includes the toleration fields identified as listKeys in the API.
|
||||
listKey := core.Toleration{
|
||||
Key: t.Key,
|
||||
Operator: t.Operator,
|
||||
Value: t.Value,
|
||||
Effect: t.Effect,
|
||||
}
|
||||
if tolerationSet[listKey] {
|
||||
allErrs = append(allErrs, field.Duplicate(fldPath.Index(i), t))
|
||||
} else {
|
||||
tolerationSet[listKey] = true
|
||||
}
|
||||
}
|
||||
return allErrs
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user