Skip to content

Commit d0e1d89

Browse files
committed
Plumb metav1.Duration through healthchecks for more consistency
1 parent 28edd73 commit d0e1d89

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

controllers/machinehealthcheck_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ func (r *MachineHealthCheckReconciler) reconcile(ctx context.Context, logger log
210210
sort.Strings(m.Status.Targets)
211211

212212
// health check all targets and reconcile mhc status
213-
healthy, unhealthy, nextCheckTimes := r.healthCheckTargets(targets, logger, m.Spec.NodeStartupTimeout.Duration)
213+
healthy, unhealthy, nextCheckTimes := r.healthCheckTargets(targets, logger, *m.Spec.NodeStartupTimeout)
214214
m.Status.CurrentHealthy = int32(len(healthy))
215215

216216
var unhealthyLimitKey, unhealthyLimitValue interface{}

controllers/machinehealthcheck_targets.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func (t *healthCheckTarget) nodeName() string {
8686
// If the target doesn't currently need rememdiation, provide a duration after
8787
// which the target should next be checked.
8888
// The target should be requeued after this duration.
89-
func (t *healthCheckTarget) needsRemediation(logger logr.Logger, timeoutForMachineToHaveNode time.Duration) (bool, time.Duration) {
89+
func (t *healthCheckTarget) needsRemediation(logger logr.Logger, timeoutForMachineToHaveNode metav1.Duration) (bool, time.Duration) {
9090
var nextCheckTimes []time.Duration
9191
now := time.Now()
9292

@@ -146,14 +146,14 @@ func (t *healthCheckTarget) needsRemediation(logger logr.Logger, timeoutForMachi
146146
}
147147
logger.V(3).Info("Using comparison time", "time", comparisonTime)
148148

149-
if comparisonTime.Add(timeoutForMachineToHaveNode).Before(now) {
149+
if comparisonTime.Add(timeoutForMachineToHaveNode.Duration).Before(now) {
150150
conditions.MarkFalse(t.Machine, clusterv1.MachineHealthCheckSuccededCondition, clusterv1.NodeStartupTimeoutReason, clusterv1.ConditionSeverityWarning, "Node failed to report startup in %s", timeoutForMachineToHaveNode.String())
151151
logger.V(3).Info("Target is unhealthy: machine has no node", "duration", timeoutForMachineToHaveNode.String())
152152
return true, time.Duration(0)
153153
}
154154

155155
durationUnhealthy := now.Sub(comparisonTime)
156-
nextCheck := timeoutForMachineToHaveNode - durationUnhealthy + time.Second
156+
nextCheck := timeoutForMachineToHaveNode.Duration - durationUnhealthy + time.Second
157157

158158
return false, nextCheck
159159
}
@@ -272,7 +272,7 @@ func (r *MachineHealthCheckReconciler) getNodeFromMachine(ctx context.Context, c
272272

273273
// healthCheckTargets health checks a slice of targets
274274
// and gives a data to measure the average health.
275-
func (r *MachineHealthCheckReconciler) healthCheckTargets(targets []healthCheckTarget, logger logr.Logger, timeoutForMachineToHaveNode time.Duration) ([]healthCheckTarget, []healthCheckTarget, []time.Duration) {
275+
func (r *MachineHealthCheckReconciler) healthCheckTargets(targets []healthCheckTarget, logger logr.Logger, timeoutForMachineToHaveNode metav1.Duration) ([]healthCheckTarget, []healthCheckTarget, []time.Duration) {
276276
var nextCheckTimes []time.Duration
277277
var unhealthy []healthCheckTarget
278278
var healthy []healthCheckTarget

controllers/machinehealthcheck_targets_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,9 +389,9 @@ func TestHealthCheckTargets(t *testing.T) {
389389
}
390390

391391
// Allow individual test cases to override the timeoutForMachineToHaveNode.
392-
timeout := timeoutForMachineToHaveNode
392+
timeout := metav1.Duration{Duration: timeoutForMachineToHaveNode}
393393
if tc.timeoutForMachineToHaveNode != nil {
394-
timeout = *tc.timeoutForMachineToHaveNode
394+
timeout.Duration = *tc.timeoutForMachineToHaveNode
395395
}
396396

397397
healthy, unhealthy, nextCheckTimes := reconciler.healthCheckTargets(tc.targets, ctrl.LoggerFrom(ctx), timeout)

0 commit comments

Comments
 (0)