mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 23:47:50 +00:00
Update types from api review
This commit is contained in:
@@ -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"
|
||||
corevalidation "k8s.io/kubernetes/pkg/apis/core/validation"
|
||||
"k8s.io/kubernetes/pkg/apis/node"
|
||||
@@ -31,8 +32,8 @@ 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"))...)
|
||||
if rc.Scheduling != nil {
|
||||
allErrs = append(allErrs, validateScheduling(rc.Scheduling, field.NewPath("scheduling"))...)
|
||||
}
|
||||
|
||||
return allErrs
|
||||
@@ -47,11 +48,11 @@ func ValidateRuntimeClassUpdate(new, old *node.RuntimeClass) field.ErrorList {
|
||||
return allErrs
|
||||
}
|
||||
|
||||
func validateTopology(t *node.Topology, fldPath *field.Path) field.ErrorList {
|
||||
func validateScheduling(s *node.Scheduling, fldPath *field.Path) field.ErrorList {
|
||||
var allErrs field.ErrorList
|
||||
if t.NodeSelector != nil {
|
||||
allErrs = append(allErrs, corevalidation.ValidateNodeSelector(t.NodeSelector, fldPath.Child("nodeSelector"))...)
|
||||
if s.NodeSelector != nil {
|
||||
allErrs = append(allErrs, unversionedvalidation.ValidateLabels(s.NodeSelector, fldPath.Child("nodeSelector"))...)
|
||||
}
|
||||
allErrs = append(allErrs, corevalidation.ValidateTolerations(t.Tolerations, fldPath.Child("tolerations"))...)
|
||||
allErrs = append(allErrs, corevalidation.ValidateTolerations(s.Tolerations, fldPath.Child("tolerations"))...)
|
||||
return allErrs
|
||||
}
|
||||
|
||||
@@ -128,22 +128,15 @@ func TestValidateRuntimeUpdate(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateTopology(t *testing.T) {
|
||||
func TestValidateScheduling(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
topology *node.Topology
|
||||
scheduling *node.Scheduling
|
||||
expectErrs int
|
||||
}{{
|
||||
name: "valid topology",
|
||||
topology: &node.Topology{
|
||||
NodeSelector: &core.NodeSelector{
|
||||
NodeSelectorTerms: []core.NodeSelectorTerm{{
|
||||
MatchExpressions: []core.NodeSelectorRequirement{{
|
||||
Key: "valid",
|
||||
Operator: core.NodeSelectorOpExists,
|
||||
}},
|
||||
}},
|
||||
},
|
||||
name: "valid scheduling",
|
||||
scheduling: &node.Scheduling{
|
||||
NodeSelector: map[string]string{"valid": "yes"},
|
||||
Tolerations: []core.Toleration{{
|
||||
Key: "valid",
|
||||
Operator: core.TolerationOpExists,
|
||||
@@ -151,24 +144,17 @@ func TestValidateTopology(t *testing.T) {
|
||||
}},
|
||||
},
|
||||
}, {
|
||||
name: "empty topology",
|
||||
topology: &node.Topology{},
|
||||
name: "empty scheduling",
|
||||
scheduling: &node.Scheduling{},
|
||||
}, {
|
||||
name: "invalid nodeSelector",
|
||||
topology: &node.Topology{
|
||||
NodeSelector: &core.NodeSelector{
|
||||
NodeSelectorTerms: []core.NodeSelectorTerm{{
|
||||
MatchExpressions: []core.NodeSelectorRequirement{{
|
||||
Key: "not a valid key!!!",
|
||||
Operator: core.NodeSelectorOpExists,
|
||||
}},
|
||||
}},
|
||||
},
|
||||
scheduling: &node.Scheduling{
|
||||
NodeSelector: map[string]string{"not a valid key!!!": "nope"},
|
||||
},
|
||||
expectErrs: 1,
|
||||
}, {
|
||||
name: "invalid toleration",
|
||||
topology: &node.Topology{
|
||||
scheduling: &node.Scheduling{
|
||||
Tolerations: []core.Toleration{{
|
||||
Key: "valid",
|
||||
Operator: core.TolerationOpExists,
|
||||
@@ -181,16 +167,9 @@ func TestValidateTopology(t *testing.T) {
|
||||
},
|
||||
expectErrs: 1,
|
||||
}, {
|
||||
name: "invalid topology",
|
||||
topology: &node.Topology{
|
||||
NodeSelector: &core.NodeSelector{
|
||||
NodeSelectorTerms: []core.NodeSelectorTerm{{
|
||||
MatchExpressions: []core.NodeSelectorRequirement{{
|
||||
Key: "not a valid label key!!!",
|
||||
Operator: core.NodeSelectorOpExists,
|
||||
}},
|
||||
}},
|
||||
},
|
||||
name: "invalid scheduling",
|
||||
scheduling: &node.Scheduling{
|
||||
NodeSelector: map[string]string{"not a valid key!!!": "nope"},
|
||||
Tolerations: []core.Toleration{{
|
||||
Key: "valid",
|
||||
Operator: core.TolerationOpExists,
|
||||
@@ -209,7 +188,7 @@ func TestValidateTopology(t *testing.T) {
|
||||
rc := &node.RuntimeClass{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "foo"},
|
||||
Handler: "bar",
|
||||
Topology: test.topology,
|
||||
Scheduling: test.scheduling,
|
||||
}
|
||||
assert.Len(t, ValidateRuntimeClass(rc), test.expectErrs)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user