Skip to content

Commit adca742

Browse files
authored
Renames nextSnapshot status to lastSnapshot (#16)
To more accurately reflect what this field is doing
1 parent b241f36 commit adca742

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

api/v1beta1/questdbsnapshotschedule_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type QuestDBSnapshotScheduleSpec struct {
2929

3030
// QuestDBSnapshotStatus defines the observed state of QuestDBSnapshot
3131
type QuestDBSnapshotScheduleStatus struct {
32-
NextSnapshot metav1.Time `json:"nextSnapshot,omitempty"`
32+
LastSnapshot metav1.Time `json:"lastSnapshot,omitempty"`
3333
SnapshotPhase QuestDBSnapshotPhase `json:"snapshotPhase,omitempty"`
3434
}
3535

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/crd.questdb.io_questdbsnapshotschedules.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ spec:
7373
status:
7474
description: QuestDBSnapshotStatus defines the observed state of QuestDBSnapshot
7575
properties:
76-
nextSnapshot:
76+
lastSnapshot:
7777
format: date-time
7878
type: string
7979
snapshotPhase:

internal/controller/questdbsnapshotschedule_controller.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,14 @@ func (r *QuestDBSnapshotScheduleReconciler) Reconcile(ctx context.Context, req c
9595
}
9696

9797
// Check if we are due for a snapshot
98-
nextSnapshotTime, err := r.getNextSnapshotTime(sched)
98+
lastSnapshotTime, err := r.getLastSnapshotTime(sched)
9999
if err != nil {
100100
return ctrl.Result{}, err
101101
}
102102

103-
if nextSnapshotTime.Compare(r.TimeSource.Now()) <= 0 {
103+
if lastSnapshotTime.Compare(r.TimeSource.Now()) <= 0 {
104104
// Update the next snapshot time
105-
sched.Status.NextSnapshot = metav1.NewTime(nextSnapshotTime)
105+
sched.Status.LastSnapshot = metav1.NewTime(lastSnapshotTime)
106106
if err = r.Status().Update(ctx, sched); err != nil {
107107
// If this update fails, re-reconcile immediately
108108
return ctrl.Result{}, err
@@ -134,7 +134,7 @@ func (r *QuestDBSnapshotScheduleReconciler) Reconcile(ctx context.Context, req c
134134
// Garbage collect old successful snapshots
135135
err = r.garbageCollect(ctx, childSnapshots, sched.Spec.Retention)
136136

137-
return ctrl.Result{RequeueAfter: nextSnapshotTime.Sub(r.TimeSource.Now())}, err
137+
return ctrl.Result{RequeueAfter: lastSnapshotTime.Sub(r.TimeSource.Now())}, err
138138
}
139139

140140
// SetupWithManager sets up the controller with the Manager.
@@ -217,14 +217,14 @@ func (r *QuestDBSnapshotScheduleReconciler) garbageCollect(ctx context.Context,
217217

218218
}
219219

220-
func (r *QuestDBSnapshotScheduleReconciler) getNextSnapshotTime(sched *crdv1beta1.QuestDBSnapshotSchedule) (time.Time, error) {
220+
func (r *QuestDBSnapshotScheduleReconciler) getLastSnapshotTime(sched *crdv1beta1.QuestDBSnapshotSchedule) (time.Time, error) {
221221
parser := cron.NewParser(cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.Dow)
222222
crontab, err := parser.Parse(sched.Spec.Schedule)
223223
if err != nil {
224224
return time.Time{}, err
225225
}
226226

227-
lastTime := sched.Status.NextSnapshot.Time
227+
lastTime := sched.Status.LastSnapshot.Time
228228
if lastTime.IsZero() {
229229
lastTime = sched.CreationTimestamp.Time
230230
}

0 commit comments

Comments
 (0)