mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #77576 from Huang-Wei/sched-ut-escape
prevent `predicatesOrdering` from escaping from UT
This commit is contained in:
commit
3ab338dfd3
@ -173,11 +173,6 @@ func Ordering() []string {
|
|||||||
return predicatesOrdering
|
return predicatesOrdering
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetPredicatesOrdering sets the ordering of predicates.
|
|
||||||
func SetPredicatesOrdering(names []string) {
|
|
||||||
predicatesOrdering = names
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetPersistentVolumeInfo returns a persistent volume object by PV ID.
|
// GetPersistentVolumeInfo returns a persistent volume object by PV ID.
|
||||||
func (c *CachedPersistentVolumeInfo) GetPersistentVolumeInfo(pvID string) (*v1.PersistentVolume, error) {
|
func (c *CachedPersistentVolumeInfo) GetPersistentVolumeInfo(pvID string) (*v1.PersistentVolume, error) {
|
||||||
return c.Get(pvID)
|
return c.Get(pvID)
|
||||||
|
@ -77,3 +77,13 @@ func portsConflict(existingPorts schedulernodeinfo.HostPortInfo, wantPorts []*v1
|
|||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetPredicatesOrderingDuringTest sets the predicatesOrdering to the specified
|
||||||
|
// value, and returns a function that restores the original value.
|
||||||
|
func SetPredicatesOrderingDuringTest(value []string) func() {
|
||||||
|
origVal := predicatesOrdering
|
||||||
|
predicatesOrdering = value
|
||||||
|
return func() {
|
||||||
|
predicatesOrdering = origVal
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -217,7 +217,7 @@ func TestSelectHost(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGenericScheduler(t *testing.T) {
|
func TestGenericScheduler(t *testing.T) {
|
||||||
algorithmpredicates.SetPredicatesOrdering(order)
|
defer algorithmpredicates.SetPredicatesOrderingDuringTest(order)()
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
predicates map[string]algorithmpredicates.FitPredicate
|
predicates map[string]algorithmpredicates.FitPredicate
|
||||||
@ -479,7 +479,6 @@ func TestGenericScheduler(t *testing.T) {
|
|||||||
|
|
||||||
// makeScheduler makes a simple genericScheduler for testing.
|
// makeScheduler makes a simple genericScheduler for testing.
|
||||||
func makeScheduler(predicates map[string]algorithmpredicates.FitPredicate, nodes []*v1.Node) *genericScheduler {
|
func makeScheduler(predicates map[string]algorithmpredicates.FitPredicate, nodes []*v1.Node) *genericScheduler {
|
||||||
algorithmpredicates.SetPredicatesOrdering(order)
|
|
||||||
cache := internalcache.New(time.Duration(0), wait.NeverStop)
|
cache := internalcache.New(time.Duration(0), wait.NeverStop)
|
||||||
fwk, _ := framework.NewFramework(EmptyPluginRegistry, nil)
|
fwk, _ := framework.NewFramework(EmptyPluginRegistry, nil)
|
||||||
for _, n := range nodes {
|
for _, n := range nodes {
|
||||||
@ -503,6 +502,7 @@ func makeScheduler(predicates map[string]algorithmpredicates.FitPredicate, nodes
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFindFitAllError(t *testing.T) {
|
func TestFindFitAllError(t *testing.T) {
|
||||||
|
defer algorithmpredicates.SetPredicatesOrderingDuringTest(order)()
|
||||||
predicates := map[string]algorithmpredicates.FitPredicate{"true": truePredicate, "matches": matchesPredicate}
|
predicates := map[string]algorithmpredicates.FitPredicate{"true": truePredicate, "matches": matchesPredicate}
|
||||||
nodes := makeNodeList([]string{"3", "2", "1"})
|
nodes := makeNodeList([]string{"3", "2", "1"})
|
||||||
scheduler := makeScheduler(predicates, nodes)
|
scheduler := makeScheduler(predicates, nodes)
|
||||||
@ -531,6 +531,7 @@ func TestFindFitAllError(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFindFitSomeError(t *testing.T) {
|
func TestFindFitSomeError(t *testing.T) {
|
||||||
|
defer algorithmpredicates.SetPredicatesOrderingDuringTest(order)()
|
||||||
predicates := map[string]algorithmpredicates.FitPredicate{"true": truePredicate, "matches": matchesPredicate}
|
predicates := map[string]algorithmpredicates.FitPredicate{"true": truePredicate, "matches": matchesPredicate}
|
||||||
nodes := makeNodeList([]string{"3", "2", "1"})
|
nodes := makeNodeList([]string{"3", "2", "1"})
|
||||||
scheduler := makeScheduler(predicates, nodes)
|
scheduler := makeScheduler(predicates, nodes)
|
||||||
@ -846,7 +847,7 @@ var startTime20190107 = metav1.Date(2019, 1, 7, 1, 1, 1, 0, time.UTC)
|
|||||||
// TestSelectNodesForPreemption tests selectNodesForPreemption. This test assumes
|
// TestSelectNodesForPreemption tests selectNodesForPreemption. This test assumes
|
||||||
// that podsFitsOnNode works correctly and is tested separately.
|
// that podsFitsOnNode works correctly and is tested separately.
|
||||||
func TestSelectNodesForPreemption(t *testing.T) {
|
func TestSelectNodesForPreemption(t *testing.T) {
|
||||||
algorithmpredicates.SetPredicatesOrdering(order)
|
defer algorithmpredicates.SetPredicatesOrderingDuringTest(order)()
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
predicates map[string]algorithmpredicates.FitPredicate
|
predicates map[string]algorithmpredicates.FitPredicate
|
||||||
@ -1005,7 +1006,7 @@ func TestSelectNodesForPreemption(t *testing.T) {
|
|||||||
|
|
||||||
// TestPickOneNodeForPreemption tests pickOneNodeForPreemption.
|
// TestPickOneNodeForPreemption tests pickOneNodeForPreemption.
|
||||||
func TestPickOneNodeForPreemption(t *testing.T) {
|
func TestPickOneNodeForPreemption(t *testing.T) {
|
||||||
algorithmpredicates.SetPredicatesOrdering(order)
|
defer algorithmpredicates.SetPredicatesOrderingDuringTest(order)()
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
predicates map[string]algorithmpredicates.FitPredicate
|
predicates map[string]algorithmpredicates.FitPredicate
|
||||||
@ -1321,6 +1322,7 @@ func TestNodesWherePreemptionMightHelp(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPreempt(t *testing.T) {
|
func TestPreempt(t *testing.T) {
|
||||||
|
defer algorithmpredicates.SetPredicatesOrderingDuringTest(order)()
|
||||||
failedPredMap := FailedPredicateMap{
|
failedPredMap := FailedPredicateMap{
|
||||||
"machine1": []algorithmpredicates.PredicateFailureReason{algorithmpredicates.NewInsufficientResourceError(v1.ResourceMemory, 1000, 500, 300)},
|
"machine1": []algorithmpredicates.PredicateFailureReason{algorithmpredicates.NewInsufficientResourceError(v1.ResourceMemory, 1000, 500, 300)},
|
||||||
"machine2": []algorithmpredicates.PredicateFailureReason{algorithmpredicates.ErrDiskConflict},
|
"machine2": []algorithmpredicates.PredicateFailureReason{algorithmpredicates.ErrDiskConflict},
|
||||||
|
Loading…
Reference in New Issue
Block a user