Change a type of collection of strategies for NodePreparer

This commit is contained in:
gmarek 2016-10-24 11:42:08 +02:00
parent 40b66e178b
commit aeba0f1dc4
6 changed files with 21 additions and 16 deletions

View File

@ -463,7 +463,7 @@ var _ = framework.KubeDescribe("Density", func() {
It(name, func() {
nodePreparer := framework.NewE2ETestNodePreparer(
f.ClientSet,
map[int]testutils.PrepareNodeStrategy{nodeCount: &testutils.TrivialNodePrepareStrategy{}},
[]testutils.CountToStrategy{{Count: nodeCount, Strategy: &testutils.TrivialNodePrepareStrategy{}}},
)
framework.ExpectNoError(nodePreparer.PrepareNodes())
defer nodePreparer.CleanupNodes()

View File

@ -4522,11 +4522,11 @@ type E2ETestNodePreparer struct {
// Specifies how many nodes should be modified using the given strategy.
// Only one strategy can be applied to a single Node, so there needs to
// be at least <sum_of_keys> Nodes in the cluster.
countToStrategy map[int]testutils.PrepareNodeStrategy
countToStrategy []testutils.CountToStrategy
nodeToAppliedStrategy map[string]testutils.PrepareNodeStrategy
}
func NewE2ETestNodePreparer(client clientset.Interface, countToStrategy map[int]testutils.PrepareNodeStrategy) testutils.TestNodePreparer {
func NewE2ETestNodePreparer(client clientset.Interface, countToStrategy []testutils.CountToStrategy) testutils.TestNodePreparer {
return &E2ETestNodePreparer{
client: client,
countToStrategy: countToStrategy,
@ -4545,14 +4545,14 @@ func (p *E2ETestNodePreparer) PrepareNodes() error {
}
index := 0
sum := 0
for k, strategy := range p.countToStrategy {
sum += k
for _, v := range p.countToStrategy {
sum += v.Count
for ; index < sum; index++ {
if err := testutils.DoPrepareNode(p.client, &nodes.Items[index], strategy); err != nil {
if err := testutils.DoPrepareNode(p.client, &nodes.Items[index], v.Strategy); err != nil {
glog.Errorf("Aborting node preparation: %v", err)
return err
}
p.nodeToAppliedStrategy[nodes.Items[index].Name] = strategy
p.nodeToAppliedStrategy[nodes.Items[index].Name] = v.Strategy
}
}
return nil

View File

@ -32,11 +32,11 @@ const (
type IntegrationTestNodePreparer struct {
client clientset.Interface
countToStrategy map[int]testutils.PrepareNodeStrategy
countToStrategy []testutils.CountToStrategy
nodeNamePrefix string
}
func NewIntegrationTestNodePreparer(client clientset.Interface, countToStrategy map[int]testutils.PrepareNodeStrategy, nodeNamePrefix string) testutils.TestNodePreparer {
func NewIntegrationTestNodePreparer(client clientset.Interface, countToStrategy []testutils.CountToStrategy, nodeNamePrefix string) testutils.TestNodePreparer {
return &IntegrationTestNodePreparer{
client: client,
countToStrategy: countToStrategy,
@ -46,8 +46,8 @@ func NewIntegrationTestNodePreparer(client clientset.Interface, countToStrategy
func (p *IntegrationTestNodePreparer) PrepareNodes() error {
numNodes := 0
for k := range p.countToStrategy {
numNodes += k
for _, v := range p.countToStrategy {
numNodes += v.Count
}
glog.Infof("Making %d nodes", numNodes)
@ -80,10 +80,10 @@ func (p *IntegrationTestNodePreparer) PrepareNodes() error {
nodes := e2eframework.GetReadySchedulableNodesOrDie(p.client)
index := 0
sum := 0
for k, strategy := range p.countToStrategy {
sum += k
for _, v := range p.countToStrategy {
sum += v.Count
for ; index < sum; index++ {
if err := testutils.DoPrepareNode(p.client, &nodes.Items[index], strategy); err != nil {
if err := testutils.DoPrepareNode(p.client, &nodes.Items[index], v.Strategy); err != nil {
glog.Errorf("Aborting node preparation: %v", err)
return err
}

View File

@ -60,7 +60,7 @@ func benchmarkScheduling(numNodes, numScheduledPods int, b *testing.B) {
nodePreparer := framework.NewIntegrationTestNodePreparer(
c,
map[int]testutils.PrepareNodeStrategy{numNodes: &testutils.TrivialNodePrepareStrategy{}},
[]testutils.CountToStrategy{{Count: numNodes, Strategy: &testutils.TrivialNodePrepareStrategy{}}},
"scheduler-perf-",
)
if err := nodePreparer.PrepareNodes(); err != nil {

View File

@ -83,7 +83,7 @@ func schedulePods(numNodes, numPods int) int32 {
nodePreparer := framework.NewIntegrationTestNodePreparer(
c,
map[int]testutils.PrepareNodeStrategy{numNodes: &testutils.TrivialNodePrepareStrategy{}},
[]testutils.CountToStrategy{{Count: numNodes, Strategy: &testutils.TrivialNodePrepareStrategy{}}},
"scheduler-perf-",
)
if err := nodePreparer.PrepareNodes(); err != nil {

View File

@ -608,6 +608,11 @@ waitLoop:
return nil
}
type CountToStrategy struct {
Count int
Strategy PrepareNodeStrategy
}
type TestNodePreparer interface {
PrepareNodes() error
CleanupNodes() error