Skip to content

Commit 0e4a077

Browse files
k8s-ci-robotnitrag
authored andcommitted
Merge pull request kubernetes#3308 from bruecktech/fix-fallback
Fix priority expander falling back to random although higher priority matches
1 parent db76938 commit 0e4a077

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

cluster-autoscaler/expander/priority/priority.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ func (p *priority) BestOption(expansionOptions []expander.Option, nodeInfo map[s
148148
}
149149
best = append(best, option)
150150
found = true
151-
break
152151
}
153152
if !found {
154153
msg := fmt.Sprintf("Priority expander: node group %s not found in priority expander configuration. "+

cluster-autoscaler/expander/priority/priority_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ var (
6262
10:
6363
- ".*t\\.large.*"
6464
`
65+
wildcardMatchConfig = `
66+
5:
67+
- ".*"
68+
10:
69+
- ".t2\\.large.*"
70+
`
71+
6572
eoT2Micro = expander.Option{
6673
Debug: "t2.micro",
6774
NodeGroup: test.NewTestNodeGroup("my-asg.t2.micro", 10, 1, 1, true, false, "t2.micro", nil, nil),
@@ -109,6 +116,14 @@ func TestPriorityExpanderCorrecltySelectsSingleMatchingOptionOutOfMany(t *testin
109116
assert.Equal(t, *ret, eoM44XLarge)
110117
}
111118

119+
func TestPriorityExpanderDoesNotFallBackToRandomWhenHigherPriorityMatches(t *testing.T) {
120+
s, _, _, _ := getStrategyInstance(t, wildcardMatchConfig)
121+
for i := 0; i < 10; i++ {
122+
ret := s.BestOption([]expander.Option{eoT2Large, eoT2Micro}, nil)
123+
assert.Equal(t, *ret, eoT2Large)
124+
}
125+
}
126+
112127
func TestPriorityExpanderCorrecltySelectsOneOfTwoMatchingOptionsOutOfMany(t *testing.T) {
113128
s, _, _, _ := getStrategyInstance(t, config)
114129
for i := 0; i < 10; i++ {

0 commit comments

Comments
 (0)