Skip to content

Commit

Permalink
Set default value for scale cache config values (#7666)
Browse files Browse the repository at this point in the history
* Set default value for scale cache values

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>

* Update pkg/scheduler/scheduler.go

---------

Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
  • Loading branch information
pierDipi authored Feb 9, 2024
1 parent bcb6100 commit 6f2eaed
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ type ScaleCacheConfig struct {
RefreshPeriod time.Duration `json:"refreshPeriod"`
}

func (c ScaleCacheConfig) withDefaults() ScaleCacheConfig {
n := ScaleCacheConfig{RefreshPeriod: c.RefreshPeriod}
if c.RefreshPeriod == 0 {
n.RefreshPeriod = 5 * time.Minute
}
return n
}

type ScaleCache struct {
entriesMu sync.RWMutex // protects access to entries, entries itself is concurrency safe, so we only need to ensure that we correctly access the pointer
entries *cache.Expiring
Expand All @@ -149,7 +157,7 @@ func NewScaleCache(ctx context.Context, namespace string, scaleClient ScaleClien
entries: cache.NewExpiring(),
scaleClient: scaleClient,
statefulSetNamespace: namespace,
config: config,
config: config.withDefaults(),
}
}

Expand Down

0 comments on commit 6f2eaed

Please sign in to comment.