Skip to content

Commit 167587d

Browse files
committed
round durations to the second in events, errors and status conditions messages
Signed-off-by: Thomas Morin <[email protected]>
1 parent 4de0503 commit 167587d

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

internal/controller/kustomization_controller.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ func (r *KustomizationReconciler) Reconcile(ctx context.Context, req ctrl.Reques
188188
// Log and emit success event.
189189
if conditions.IsReady(obj) {
190190
msg := fmt.Sprintf("Reconciliation finished in %s, next run in %s",
191-
time.Since(reconcileStart).String(),
191+
formatDurationSince(reconcileStart),
192192
obj.Spec.Interval.Duration.String())
193193
log.Info(msg, "revision", obj.Status.LastAttemptedRevision)
194194
r.event(obj, obj.Status.LastAppliedRevision, eventv1.EventSeverityInfo, msg,
@@ -274,7 +274,7 @@ func (r *KustomizationReconciler) Reconcile(ctx context.Context, req ctrl.Reques
274274
// Broadcast the reconciliation failure and requeue at the specified retry interval.
275275
if reconcileErr != nil {
276276
log.Error(reconcileErr, fmt.Sprintf("Reconciliation failed after %s, next try in %s",
277-
time.Since(reconcileStart).String(),
277+
formatDurationSince(reconcileStart),
278278
obj.GetRetryInterval().String()),
279279
"revision",
280280
artifactSource.GetArtifact().Revision)
@@ -896,11 +896,11 @@ func (r *KustomizationReconciler) checkHealth(ctx context.Context,
896896
}); err != nil {
897897
conditions.MarkFalse(obj, meta.ReadyCondition, kustomizev1.HealthCheckFailedReason, err.Error())
898898
conditions.MarkFalse(obj, kustomizev1.HealthyCondition, kustomizev1.HealthCheckFailedReason, err.Error())
899-
return fmt.Errorf("health check failed after %s: %w", time.Since(checkStart).String(), err)
899+
return fmt.Errorf("health check failed after %s: %w", formatDurationSince(checkStart), err)
900900
}
901901

902902
// Emit recovery event if the previous health check failed.
903-
msg := fmt.Sprintf("Health check passed in %s", time.Since(checkStart).String())
903+
msg := fmt.Sprintf("Health check passed in %s", formatDurationSince(checkStart))
904904
if !wasHealthy || (isNewRevision && drifted) {
905905
r.event(obj, revision, eventv1.EventSeverityInfo, msg, nil)
906906
}
@@ -1094,3 +1094,7 @@ func (r *KustomizationReconciler) patch(ctx context.Context,
10941094

10951095
return nil
10961096
}
1097+
1098+
func formatDurationSince(t time.Time) string {
1099+
return time.Since(t).Round(time.Second).String()
1100+
}

0 commit comments

Comments
 (0)