Skip to content

Commit c6b4a7c

Browse files
committed
fix(controller): stale child list, second-granular names, Owns watch, clock rebase
1 parent bf348a0 commit c6b4a7c

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

internal/controller/impvmsnapshot_controller.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ func (r *ImpVMSnapshotReconciler) Reconcile(ctx context.Context, req ctrl.Reques
122122
// Design rule 3 & 4: decide whether to create a new child.
123123
if snap.Spec.Schedule == "" {
124124
// One-shot: create child only if no children exist at all.
125-
if len(childList.Items) == 0 {
125+
if len(children) == 0 {
126126
if err := r.createChild(ctx, snap); err != nil {
127127
return ctrl.Result{}, err
128128
}
@@ -147,7 +147,8 @@ func (r *ImpVMSnapshotReconciler) Reconcile(ctx context.Context, req ctrl.Reques
147147
return ctrl.Result{}, err
148148
}
149149
// Requeue after the next scheduled slot.
150-
next = sched.Next(time.Now())
150+
now = time.Now()
151+
next = sched.Next(now)
151152
untilNext = time.Until(next)
152153
}
153154

@@ -168,7 +169,7 @@ func (r *ImpVMSnapshotReconciler) Reconcile(ctx context.Context, req ctrl.Reques
168169
func (r *ImpVMSnapshotReconciler) createChild(ctx context.Context, parent *impv1alpha1.ImpVMSnapshot) error {
169170
log := logf.FromContext(ctx)
170171

171-
childName := parent.Name + "-" + time.Now().UTC().Format("20060102-1504")
172+
childName := parent.Name + "-" + time.Now().UTC().Format("20060102-150405")
172173

173174
childSpec := parent.Spec.DeepCopy()
174175
childSpec.Schedule = "" // clear schedule on child
@@ -207,5 +208,6 @@ func (r *ImpVMSnapshotReconciler) createChild(ctx context.Context, parent *impv1
207208
func (r *ImpVMSnapshotReconciler) SetupWithManager(mgr ctrl.Manager) error {
208209
return ctrl.NewControllerManagedBy(mgr).
209210
For(&impv1alpha1.ImpVMSnapshot{}).
211+
Owns(&impv1alpha1.ImpVMSnapshot{}).
210212
Complete(r)
211213
}

internal/controller/impvmsnapshot_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ var _ = Describe("ImpVMSnapshot controller", func() {
168168
names[i] = c.Name
169169
}
170170
Expect(names).NotTo(ContainElement(fmt.Sprintf("%s-exec-0", parentName)))
171-
Expect(len(children.Items)).To(BeNumerically("<=", 3))
171+
Expect(len(children.Items)).To(BeNumerically("<=", 2))
172172
})
173173

174174
It("TestOperatorSnapshotReconciler_skipsIfActiveChild — does not create when active child exists", func() {

0 commit comments

Comments
 (0)