From c5e61819689c664c2399e94eb1996544acc09e2e Mon Sep 17 00:00:00 2001 From: Stefan Prodan Date: Fri, 31 May 2024 12:37:42 +0300 Subject: [PATCH] Add revision to print columns Signed-off-by: Stefan Prodan --- api/v1/fluxinstance_types.go | 1 + .../bases/fluxcd.controlplane.io_fluxinstances.yaml | 3 +++ internal/controller/fluxinstance_controller.go | 10 +++++++++- internal/controller/fluxinstance_uninstaller.go | 2 +- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/api/v1/fluxinstance_types.go b/api/v1/fluxinstance_types.go index 4652582..2a031a0 100644 --- a/api/v1/fluxinstance_types.go +++ b/api/v1/fluxinstance_types.go @@ -267,6 +267,7 @@ func (in *FluxInstance) GetTimeout() time.Duration { // +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="" // +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type==\"Ready\")].status",description="" // +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.conditions[?(@.type==\"Ready\")].message",description="" +// +kubebuilder:printcolumn:name="Revision",type="string",JSONPath=".status.lastAttemptedRevision",description="" // FluxInstance is the Schema for the fluxinstances API type FluxInstance struct { diff --git a/config/crd/bases/fluxcd.controlplane.io_fluxinstances.yaml b/config/crd/bases/fluxcd.controlplane.io_fluxinstances.yaml index 1d7de08..2ce27dc 100644 --- a/config/crd/bases/fluxcd.controlplane.io_fluxinstances.yaml +++ b/config/crd/bases/fluxcd.controlplane.io_fluxinstances.yaml @@ -24,6 +24,9 @@ spec: - jsonPath: .status.conditions[?(@.type=="Ready")].message name: Status type: string + - jsonPath: .status.lastAttemptedRevision + name: Revision + type: string name: v1 schema: openAPIV3Schema: diff --git a/internal/controller/fluxinstance_controller.go b/internal/controller/fluxinstance_controller.go index 57145b9..614ac10 100644 --- a/internal/controller/fluxinstance_controller.go +++ b/internal/controller/fluxinstance_controller.go @@ -154,7 +154,7 @@ func (r *FluxInstanceReconciler) reconcile(ctx context.Context, // Mark the object as ready. obj.Status.LastAppliedRevision = obj.Status.LastAttemptedRevision - msg = fmt.Sprintf("Reconciliation finished in %s", time.Since(reconcileStart).String()) + msg = fmt.Sprintf("Reconciliation finished in %s", fmtDuration(reconcileStart)) conditions.MarkTrue(obj, meta.ReadyCondition, meta.ReconciliationSucceededReason, @@ -467,3 +467,11 @@ func requeueAfter(obj *fluxcdv1.FluxInstance) ctrl.Result { return result } + +func fmtDuration(t time.Time) string { + if time.Since(t) < time.Second { + return time.Since(t).Round(time.Millisecond).String() + } else { + return time.Since(t).Round(time.Second).String() + } +} diff --git a/internal/controller/fluxinstance_uninstaller.go b/internal/controller/fluxinstance_uninstaller.go index afd67f5..6f3d392 100644 --- a/internal/controller/fluxinstance_uninstaller.go +++ b/internal/controller/fluxinstance_uninstaller.go @@ -60,7 +60,7 @@ func (r *FluxInstanceReconciler) uninstall(ctx context.Context, } controllerutil.RemoveFinalizer(obj, fluxcdv1.Finalizer) - msg := fmt.Sprintf("Uninstallation completed in %v", time.Since(reconcileStart).String()) + msg := fmt.Sprintf("Uninstallation completed in %v", fmtDuration(reconcileStart)) log.Info(msg, "output", changeSet.ToMap()) // Stop reconciliation as the object is being deleted.