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() { It(name, func() {
nodePreparer := framework.NewE2ETestNodePreparer( nodePreparer := framework.NewE2ETestNodePreparer(
f.ClientSet, f.ClientSet,
map[int]testutils.PrepareNodeStrategy{nodeCount: &testutils.TrivialNodePrepareStrategy{}}, []testutils.CountToStrategy{{Count: nodeCount, Strategy: &testutils.TrivialNodePrepareStrategy{}}},
) )
framework.ExpectNoError(nodePreparer.PrepareNodes()) framework.ExpectNoError(nodePreparer.PrepareNodes())
defer nodePreparer.CleanupNodes() defer nodePreparer.CleanupNodes()

View File

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

View File

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

View File

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

View File

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

View File

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