Validate topology
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
||||
"testing"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/kubernetes/pkg/apis/core"
|
||||
"k8s.io/kubernetes/pkg/apis/node"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -126,3 +127,91 @@ func TestValidateRuntimeUpdate(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateTopology(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
topology *node.Topology
|
||||
expectErrs int
|
||||
}{{
|
||||
name: "valid topology",
|
||||
topology: &node.Topology{
|
||||
NodeSelector: &core.NodeSelector{
|
||||
NodeSelectorTerms: []core.NodeSelectorTerm{{
|
||||
MatchExpressions: []core.NodeSelectorRequirement{{
|
||||
Key: "valid",
|
||||
Operator: core.NodeSelectorOpExists,
|
||||
}},
|
||||
}},
|
||||
},
|
||||
Tolerations: []core.Toleration{{
|
||||
Key: "valid",
|
||||
Operator: core.TolerationOpExists,
|
||||
Effect: core.TaintEffectNoSchedule,
|
||||
}},
|
||||
},
|
||||
}, {
|
||||
name: "empty topology",
|
||||
topology: &node.Topology{},
|
||||
}, {
|
||||
name: "invalid nodeSelector",
|
||||
topology: &node.Topology{
|
||||
NodeSelector: &core.NodeSelector{
|
||||
NodeSelectorTerms: []core.NodeSelectorTerm{{
|
||||
MatchExpressions: []core.NodeSelectorRequirement{{
|
||||
Key: "not a valid key!!!",
|
||||
Operator: core.NodeSelectorOpExists,
|
||||
}},
|
||||
}},
|
||||
},
|
||||
},
|
||||
expectErrs: 1,
|
||||
}, {
|
||||
name: "invalid toleration",
|
||||
topology: &node.Topology{
|
||||
Tolerations: []core.Toleration{{
|
||||
Key: "valid",
|
||||
Operator: core.TolerationOpExists,
|
||||
Effect: core.TaintEffectNoSchedule,
|
||||
}, {
|
||||
Key: "not a valid key!!!",
|
||||
Operator: core.TolerationOpExists,
|
||||
Effect: core.TaintEffectNoSchedule,
|
||||
}},
|
||||
},
|
||||
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,
|
||||
}},
|
||||
}},
|
||||
},
|
||||
Tolerations: []core.Toleration{{
|
||||
Key: "valid",
|
||||
Operator: core.TolerationOpExists,
|
||||
Effect: core.TaintEffectNoSchedule,
|
||||
}, {
|
||||
Key: "not a valid toleration key!!!",
|
||||
Operator: core.TolerationOpExists,
|
||||
Effect: core.TaintEffectNoSchedule,
|
||||
}},
|
||||
},
|
||||
expectErrs: 2,
|
||||
}}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
rc := &node.RuntimeClass{
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "foo"},
|
||||
Handler: "bar",
|
||||
Topology: test.topology,
|
||||
}
|
||||
assert.Len(t, ValidateRuntimeClass(rc), test.expectErrs)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user