-
Notifications
You must be signed in to change notification settings - Fork 3
/
watchScalingObject.go
58 lines (46 loc) · 1.57 KB
/
watchScalingObject.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package scaler
import "strconv"
// countMeetsExpectations returns false in case the current count does not match the
// expectations. This could either be the case if the current deployed amount
// of allocations is "out of bounds" regarding the defined min/ max of the scalingObject.
// Or if a the current count does not correlate to the desired amount of allocations
// being deployed.
func countMeetsExpectations(current uint, min uint, max uint, desired optionalValue) (asExpected bool, expectedCount uint) {
asExpected = true
expectedCount = current
if desired.isKnown {
expectedCount = desired.value
}
if current != expectedCount {
asExpected = false
}
if current < min {
expectedCount = min
asExpected = false
}
if current > max {
expectedCount = max
asExpected = false
}
return asExpected, expectedCount
}
func (s *Scaler) ensureScalingObjectCount() error {
count, err := s.GetCount()
if err != nil {
return err
}
asExpected, expected := countMeetsExpectations(count, s.scalingObject.minCount, s.scalingObject.maxCount, s.desiredScale)
if !asExpected {
s.logger.Warn().Msgf("The scalingObject count (%d) was not as expected. Thus the scalingObject had to be rescaled to %d.", count, expected)
if err := s.openScalingTicket(expected, false); err != nil {
return err
}
} else {
desiredStr := "n/a"
if s.desiredScale.isKnown {
desiredStr = strconv.Itoa(int(s.desiredScale.value))
}
s.logger.Debug().Uint("count", count).Str("desired", desiredStr).Uint("expected", expected).Msg("Count as expected, no adjustment needed.")
}
return nil
}