Skip to content

Commit a3aa12a

Browse files
authored
fix: Interpret negative or 0 half life values as disabled (#831)
* Interpret negative or 0 half life values as disabled
1 parent 1092aef commit a3aa12a

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
1818
- Fixed pod controller logging to use request namespace/name instead of empty pod object fields when pod is not found
1919
- Fixed a bug where topology constrains with equal required and preferred levels would cause preferred level not to be found.
2020
- Fixed GPU memory pods Fair Share and Queue Order calculations
21+
- Interpret negative or zero half-life value as disabled [#818](https://github.com/NVIDIA/KAI-Scheduler/pull/818) [itsomri](https://github.com/itsomri)
2122

2223
## [v0.12.0] - 2025-12-24
2324

pkg/scheduler/cache/usagedb/api/defaults.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ func (p *UsageParams) SetDefaults() {
1313
if p.HalfLifePeriod == nil {
1414
// noop: disabled by default
1515
}
16+
if p.HalfLifePeriod != nil && p.HalfLifePeriod.Duration <= 0 {
17+
p.HalfLifePeriod = nil
18+
}
1619
if p.WindowSize == nil {
1720
p.WindowSize = &metav1.Duration{Duration: time.Hour * 24 * 7}
1821
}

pkg/scheduler/cache/usagedb/api/usage_params_test.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,28 @@ func TestUsageParams_SetDefaults(t *testing.T) {
2727
WindowType: &[]WindowType{SlidingWindow}[0],
2828
},
2929
},
30+
{
31+
name: "negative half life period should be disabled",
32+
input: &UsageParams{
33+
HalfLifePeriod: &metav1.Duration{Duration: -3 * time.Minute},
34+
},
35+
expected: &UsageParams{
36+
HalfLifePeriod: nil,
37+
WindowSize: &metav1.Duration{Duration: time.Hour * 24 * 7},
38+
WindowType: &[]WindowType{SlidingWindow}[0],
39+
},
40+
},
41+
{
42+
name: "zero half life period should be disabled",
43+
input: &UsageParams{
44+
HalfLifePeriod: &metav1.Duration{Duration: 0 * time.Minute},
45+
},
46+
expected: &UsageParams{
47+
HalfLifePeriod: nil,
48+
WindowSize: &metav1.Duration{Duration: time.Hour * 24 * 7},
49+
WindowType: &[]WindowType{SlidingWindow}[0],
50+
},
51+
},
3052
{
3153
name: "params with half life set should preserve it",
3254
input: &UsageParams{
@@ -290,10 +312,9 @@ func TestUsageParams_ZeroValues(t *testing.T) {
290312

291313
params.SetDefaults()
292314

293-
// Zero values should be preserved, not replaced with defaults
294-
require.NotNil(t, params.HalfLifePeriod)
295-
assert.Equal(t, time.Duration(0), params.HalfLifePeriod.Duration)
315+
require.Nil(t, params.HalfLifePeriod)
296316

317+
// Zero values should be preserved, not replaced with defaults
297318
require.NotNil(t, params.WindowSize)
298319
assert.Equal(t, time.Duration(0), params.WindowSize.Duration)
299320

0 commit comments

Comments
 (0)