mirror of
https://github.com/kubernetes/node-problem-detector.git
synced 2026-08-23 22:26:27 +00:00
Make heartbeatPeriod const into a flag.
This commit is contained in:
@@ -36,8 +36,6 @@ const (
|
||||
updatePeriod = 1 * time.Second
|
||||
// resyncPeriod is the period at which condition manager does resync, only updates when needed.
|
||||
resyncPeriod = 10 * time.Second
|
||||
// heartbeatPeriod is the period at which condition manager does forcibly sync with apiserver.
|
||||
heartbeatPeriod = 1 * time.Minute
|
||||
)
|
||||
|
||||
// ConditionManager synchronizes node conditions with the apiserver with problem client.
|
||||
@@ -75,15 +73,18 @@ type conditionManager struct {
|
||||
client problemclient.Client
|
||||
updates map[string]types.Condition
|
||||
conditions map[string]types.Condition
|
||||
// heartbeatPeriod is the period at which condition manager does forcibly sync with apiserver.
|
||||
heartbeatPeriod time.Duration
|
||||
}
|
||||
|
||||
// NewConditionManager creates a condition manager.
|
||||
func NewConditionManager(client problemclient.Client, clock clock.Clock) ConditionManager {
|
||||
func NewConditionManager(client problemclient.Client, clock clock.Clock, heartbeatPeriod time.Duration) ConditionManager {
|
||||
return &conditionManager{
|
||||
client: client,
|
||||
clock: clock,
|
||||
updates: make(map[string]types.Condition),
|
||||
conditions: make(map[string]types.Condition),
|
||||
client: client,
|
||||
clock: clock,
|
||||
updates: make(map[string]types.Condition),
|
||||
conditions: make(map[string]types.Condition),
|
||||
heartbeatPeriod: heartbeatPeriod,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,7 +146,7 @@ func (c *conditionManager) needResync() bool {
|
||||
|
||||
// needHeartbeat checks whether a forcible heartbeat is needed.
|
||||
func (c *conditionManager) needHeartbeat() bool {
|
||||
return c.clock.Now().Sub(c.latestTry) >= heartbeatPeriod
|
||||
return c.clock.Now().Sub(c.latestTry) >= c.heartbeatPeriod
|
||||
}
|
||||
|
||||
// sync synchronizes node conditions with the apiserver.
|
||||
|
||||
@@ -31,10 +31,12 @@ import (
|
||||
"k8s.io/apimachinery/pkg/util/clock"
|
||||
)
|
||||
|
||||
const heartbeatPeriod = 1 * time.Minute
|
||||
|
||||
func newTestManager() (*conditionManager, *problemclient.FakeProblemClient, *clock.FakeClock) {
|
||||
fakeClient := problemclient.NewFakeProblemClient()
|
||||
fakeClock := clock.NewFakeClock(time.Now())
|
||||
manager := NewConditionManager(fakeClient, fakeClock)
|
||||
manager := NewConditionManager(fakeClient, fakeClock, heartbeatPeriod)
|
||||
return manager.(*conditionManager), fakeClient, fakeClock
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ func NewExporterOrDie(npdo *options.NodeProblemDetectorOptions) types.Exporter {
|
||||
|
||||
ke := k8sExporter{
|
||||
client: c,
|
||||
conditionManager: condition.NewConditionManager(c, clock.RealClock{}),
|
||||
conditionManager: condition.NewConditionManager(c, clock.RealClock{}, npdo.K8sExporterHeartbeatPeriod),
|
||||
}
|
||||
|
||||
ke.startHTTPReporting(npdo)
|
||||
|
||||
Reference in New Issue
Block a user