Validate topology

This commit is contained in:
Tim Allclair
2019-05-06 18:38:56 -07:00
parent a7ca6fa728
commit d419bdfcd9
3 changed files with 105 additions and 0 deletions

View File

@@ -19,6 +19,7 @@ package validation
import (
apivalidation "k8s.io/apimachinery/pkg/api/validation"
"k8s.io/apimachinery/pkg/util/validation/field"
corevalidation "k8s.io/kubernetes/pkg/apis/core/validation"
"k8s.io/kubernetes/pkg/apis/node"
)
@@ -30,6 +31,10 @@ func ValidateRuntimeClass(rc *node.RuntimeClass) field.ErrorList {
allErrs = append(allErrs, field.Invalid(field.NewPath("handler"), rc.Handler, msg))
}
if rc.Topology != nil {
allErrs = append(allErrs, validateTopology(rc.Topology, field.NewPath("topology"))...)
}
return allErrs
}
@@ -41,3 +46,12 @@ func ValidateRuntimeClassUpdate(new, old *node.RuntimeClass) field.ErrorList {
return allErrs
}
func validateTopology(t *node.Topology, fldPath *field.Path) field.ErrorList {
var allErrs field.ErrorList
if t.NodeSelector != nil {
allErrs = append(allErrs, corevalidation.ValidateNodeSelector(t.NodeSelector, fldPath.Child("nodeSelector"))...)
}
allErrs = append(allErrs, corevalidation.ValidateTolerations(t.Tolerations, fldPath.Child("tolerations"))...)
return allErrs
}