Skip to content

Commit

Permalink
Add revision to print columns
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Prodan <[email protected]>
  • Loading branch information
stefanprodan committed May 31, 2024
1 parent ecfe18b commit c5e6181
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions api/v1/fluxinstance_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions config/crd/bases/fluxcd.controlplane.io_fluxinstances.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 9 additions & 1 deletion internal/controller/fluxinstance_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
}
}
2 changes: 1 addition & 1 deletion internal/controller/fluxinstance_uninstaller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit c5e6181

Please sign in to comment.