Skip to content

Commit

Permalink
round durations to the second in events, errors and status conditions…
Browse files Browse the repository at this point in the history
… messages

Signed-off-by: Thomas Morin <thomas.morin@orange.com>
  • Loading branch information
tmmorin committed Feb 12, 2024
1 parent 4de0503 commit 167587d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions internal/controller/kustomization_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (r *KustomizationReconciler) Reconcile(ctx context.Context, req ctrl.Reques
// Log and emit success event.
if conditions.IsReady(obj) {
msg := fmt.Sprintf("Reconciliation finished in %s, next run in %s",
time.Since(reconcileStart).String(),
formatDurationSince(reconcileStart),
obj.Spec.Interval.Duration.String())
log.Info(msg, "revision", obj.Status.LastAttemptedRevision)
r.event(obj, obj.Status.LastAppliedRevision, eventv1.EventSeverityInfo, msg,
Expand Down Expand Up @@ -274,7 +274,7 @@ func (r *KustomizationReconciler) Reconcile(ctx context.Context, req ctrl.Reques
// Broadcast the reconciliation failure and requeue at the specified retry interval.
if reconcileErr != nil {
log.Error(reconcileErr, fmt.Sprintf("Reconciliation failed after %s, next try in %s",
time.Since(reconcileStart).String(),
formatDurationSince(reconcileStart),
obj.GetRetryInterval().String()),
"revision",
artifactSource.GetArtifact().Revision)
Expand Down Expand Up @@ -896,11 +896,11 @@ func (r *KustomizationReconciler) checkHealth(ctx context.Context,
}); err != nil {
conditions.MarkFalse(obj, meta.ReadyCondition, kustomizev1.HealthCheckFailedReason, err.Error())
conditions.MarkFalse(obj, kustomizev1.HealthyCondition, kustomizev1.HealthCheckFailedReason, err.Error())
return fmt.Errorf("health check failed after %s: %w", time.Since(checkStart).String(), err)
return fmt.Errorf("health check failed after %s: %w", formatDurationSince(checkStart), err)
}

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

return nil
}

func formatDurationSince(t time.Time) string {
return time.Since(t).Round(time.Second).String()
}

0 comments on commit 167587d

Please sign in to comment.