mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Fixing test case to remove dependency on algorithm provider
This commit is contained in:
parent
a04e600f16
commit
5e096fed34
@ -49,6 +49,8 @@ func TestCreate(t *testing.T) {
|
|||||||
factory.Create()
|
factory.Create()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test configures a scheduler from a policies defined in a file
|
||||||
|
// It combines some configurable predicate/priorities with some pre-defined ones
|
||||||
func TestCreateFromConfig(t *testing.T) {
|
func TestCreateFromConfig(t *testing.T) {
|
||||||
var configData []byte
|
var configData []byte
|
||||||
var policy schedulerapi.Policy
|
var policy schedulerapi.Policy
|
||||||
@ -63,16 +65,11 @@ func TestCreateFromConfig(t *testing.T) {
|
|||||||
client := client.NewOrDie(&client.Config{Host: server.URL, Version: testapi.Version()})
|
client := client.NewOrDie(&client.Config{Host: server.URL, Version: testapi.Version()})
|
||||||
factory := NewConfigFactory(client)
|
factory := NewConfigFactory(client)
|
||||||
|
|
||||||
// Register the predicate and priority functions
|
// Pre-register some predicate and priority functions
|
||||||
// These would be registered by the DefaultProvider in regular operation
|
RegisterFitPredicate("PredicateOne", PredicateOne)
|
||||||
RegisterFitPredicate("PodFitsPorts", algorithm.PodFitsPorts)
|
RegisterFitPredicate("PredicateTwo", PredicateTwo)
|
||||||
RegisterFitPredicate("PodFitsResources", algorithm.NewResourceFitPredicate(MinionLister))
|
RegisterPriorityFunction("PriorityOne", PriorityOne, 1)
|
||||||
RegisterFitPredicate("NoDiskConflict", algorithm.NoDiskConflict)
|
RegisterPriorityFunction("PriorityTwo", PriorityTwo, 1)
|
||||||
RegisterFitPredicate("MatchNodeSelector", algorithm.NewSelectorMatchPredicate(MinionLister))
|
|
||||||
RegisterFitPredicate("HostName", algorithm.PodFitsHost)
|
|
||||||
RegisterPriorityFunction("LeastRequestedPriority", algorithm.LeastRequestedPriority, 1)
|
|
||||||
RegisterPriorityFunction("ServiceSpreadingPriority", algorithm.NewServiceSpreadPriority(ServiceLister), 1)
|
|
||||||
RegisterPriorityFunction("EqualPriority", algorithm.EqualPriority, 0)
|
|
||||||
|
|
||||||
configData = []byte(`{
|
configData = []byte(`{
|
||||||
"kind" : "Policy",
|
"kind" : "Policy",
|
||||||
@ -80,13 +77,13 @@ func TestCreateFromConfig(t *testing.T) {
|
|||||||
"predicates" : [
|
"predicates" : [
|
||||||
{"name" : "TestZoneAffinity", "argument" : {"serviceAffinity" : {"labels" : ["zone"]}}},
|
{"name" : "TestZoneAffinity", "argument" : {"serviceAffinity" : {"labels" : ["zone"]}}},
|
||||||
{"name" : "TestRequireZone", "argument" : {"labelsPresence" : {"labels" : ["zone"], "presence" : true}}},
|
{"name" : "TestRequireZone", "argument" : {"labelsPresence" : {"labels" : ["zone"], "presence" : true}}},
|
||||||
{"name" : "PodFitsPorts"},
|
{"name" : "PredicateOne"},
|
||||||
{"name" : "MatchNodeSelector"}
|
{"name" : "PredicateTwo"}
|
||||||
],
|
],
|
||||||
"priorities" : [
|
"priorities" : [
|
||||||
{"name" : "RackSpread", "weight" : 2, "argument" : {"serviceAntiAffinity" : {"label" : "rack"}}},
|
{"name" : "RackSpread", "weight" : 3, "argument" : {"serviceAntiAffinity" : {"label" : "rack"}}},
|
||||||
{"name" : "ServiceSpreadingPriority", "weight" : 1}
|
{"name" : "PriorityOne", "weight" : 2},
|
||||||
]
|
{"name" : "PriorityTwo", "weight" : 1} ]
|
||||||
}`)
|
}`)
|
||||||
err := latestschedulerapi.Codec.DecodeInto(configData, &policy)
|
err := latestschedulerapi.Codec.DecodeInto(configData, &policy)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -119,6 +116,22 @@ func TestCreateFromEmptyConfig(t *testing.T) {
|
|||||||
factory.CreateFromConfig(policy)
|
factory.CreateFromConfig(policy)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func PredicateOne(pod api.Pod, existingPods []api.Pod, node string) (bool, error) {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func PredicateTwo(pod api.Pod, existingPods []api.Pod, node string) (bool, error) {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func PriorityOne(pod api.Pod, podLister algorithm.PodLister, minionLister algorithm.MinionLister) (algorithm.HostPriorityList, error) {
|
||||||
|
return []algorithm.HostPriority{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func PriorityTwo(pod api.Pod, podLister algorithm.PodLister, minionLister algorithm.MinionLister) (algorithm.HostPriorityList, error) {
|
||||||
|
return []algorithm.HostPriority{}, nil
|
||||||
|
}
|
||||||
|
|
||||||
func TestPollMinions(t *testing.T) {
|
func TestPollMinions(t *testing.T) {
|
||||||
table := []struct {
|
table := []struct {
|
||||||
minions []api.Node
|
minions []api.Node
|
||||||
|
Loading…
Reference in New Issue
Block a user