-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
node pools: apply node pool scheduler configuration (#17598)
- Loading branch information
Showing
18 changed files
with
1,070 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package iterator | ||
|
||
// Iterator represents an object that can iterate over a set of values one at a | ||
// time. | ||
type Iterator interface { | ||
// Next returns the next element or nil if there are none left. | ||
Next() any | ||
} | ||
|
||
// Len consumes the iterator and returns the number of elements found. | ||
// | ||
// IMPORTANT: this method consumes the iterator, so it should not be used after | ||
// Len() returns. | ||
func Len(iter Iterator) int { | ||
count := 0 | ||
for raw := iter.Next(); raw != nil; raw = iter.Next() { | ||
count++ | ||
} | ||
return count | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package structs | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/nomad/ci" | ||
"github.com/hashicorp/nomad/helper/pointer" | ||
"github.com/shoenig/test/must" | ||
) | ||
|
||
func TestSchedulerConfiguration_WithNodePool(t *testing.T) { | ||
ci.Parallel(t) | ||
|
||
testCases := []struct { | ||
name string | ||
schedConfig *SchedulerConfiguration | ||
pool *NodePool | ||
expected *SchedulerConfiguration | ||
}{ | ||
{ | ||
name: "nil pool returns same config", | ||
schedConfig: &SchedulerConfiguration{ | ||
MemoryOversubscriptionEnabled: false, | ||
SchedulerAlgorithm: SchedulerAlgorithmSpread, | ||
}, | ||
pool: nil, | ||
expected: &SchedulerConfiguration{ | ||
MemoryOversubscriptionEnabled: false, | ||
SchedulerAlgorithm: SchedulerAlgorithmSpread, | ||
}, | ||
}, | ||
{ | ||
name: "nil pool scheduler config returns same config", | ||
schedConfig: &SchedulerConfiguration{ | ||
MemoryOversubscriptionEnabled: false, | ||
SchedulerAlgorithm: SchedulerAlgorithmSpread, | ||
}, | ||
pool: &NodePool{}, | ||
expected: &SchedulerConfiguration{ | ||
MemoryOversubscriptionEnabled: false, | ||
SchedulerAlgorithm: SchedulerAlgorithmSpread, | ||
}, | ||
}, | ||
{ | ||
name: "pool with memory oversubscription overwrites config", | ||
schedConfig: &SchedulerConfiguration{ | ||
MemoryOversubscriptionEnabled: false, | ||
}, | ||
pool: &NodePool{ | ||
SchedulerConfiguration: &NodePoolSchedulerConfiguration{ | ||
MemoryOversubscriptionEnabled: pointer.Of(true), | ||
}, | ||
}, | ||
expected: &SchedulerConfiguration{ | ||
MemoryOversubscriptionEnabled: true, | ||
}, | ||
}, | ||
{ | ||
name: "pool with scheduler algorithm overwrites config", | ||
schedConfig: &SchedulerConfiguration{ | ||
SchedulerAlgorithm: SchedulerAlgorithmBinpack, | ||
}, | ||
pool: &NodePool{ | ||
SchedulerConfiguration: &NodePoolSchedulerConfiguration{ | ||
SchedulerAlgorithm: SchedulerAlgorithmSpread, | ||
}, | ||
}, | ||
expected: &SchedulerConfiguration{ | ||
SchedulerAlgorithm: SchedulerAlgorithmSpread, | ||
}, | ||
}, | ||
{ | ||
name: "pool without memory oversubscription does not modify config", | ||
schedConfig: &SchedulerConfiguration{ | ||
MemoryOversubscriptionEnabled: false, | ||
}, | ||
pool: &NodePool{ | ||
SchedulerConfiguration: &NodePoolSchedulerConfiguration{}, | ||
}, | ||
expected: &SchedulerConfiguration{ | ||
MemoryOversubscriptionEnabled: false, | ||
}, | ||
}, | ||
{ | ||
name: "pool without scheduler algorithm does not modify config", | ||
schedConfig: &SchedulerConfiguration{ | ||
SchedulerAlgorithm: SchedulerAlgorithmSpread, | ||
}, | ||
pool: &NodePool{ | ||
SchedulerConfiguration: &NodePoolSchedulerConfiguration{}, | ||
}, | ||
expected: &SchedulerConfiguration{ | ||
SchedulerAlgorithm: SchedulerAlgorithmSpread, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
got := tc.schedConfig.WithNodePool(tc.pool) | ||
must.Eq(t, tc.expected, got) | ||
must.NotEqOp(t, tc.schedConfig, got) | ||
}) | ||
} | ||
} |
Oops, something went wrong.