Skip to content

Conversation

@kurlov
Copy link
Contributor

@kurlov kurlov commented Oct 20, 2025

Follow up for #459

Add test for WithSelector using controller manager to emulate reconcile lifecycle

@codecov-commenter
Copy link

codecov-commenter commented Oct 23, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.71%. Comparing base (08ab7fb) to head (0a43969).
⚠️ Report is 124 commits behind head on main.

❗ There is a different number of reports uploaded between BASE (08ab7fb) and HEAD (0a43969). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (08ab7fb) HEAD (0a43969)
2 1
Additional details and impacted files
@@             Coverage Diff             @@
##             main     #496       +/-   ##
===========================================
- Coverage   85.06%   74.71%   -10.35%     
===========================================
  Files          19       31       +12     
  Lines        1346     2037      +691     
===========================================
+ Hits         1145     1522      +377     
- Misses        125      433      +308     
- Partials       76       82        +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@porridge porridge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is much better than the previous one, and it will actually fail when we accidentally stop passing the predicate, so it's useful.

However, I'm afraid that this test passing does not guarantee much. AFAICT there is no way to be sure whether the controller will never schedule the unwanted CR for reconciliation, or if it just did not get round to doing that yet. 🤔

Perhaps we can improve our confidence a bit by creating the unlabeled CR before the labeled one?

Comment on lines +1544 to +1553
controllerName := fmt.Sprintf("%v-controller", strings.ToLower(gvk.Kind))
Expect(r.addDefaults(mgr, controllerName)).To(Succeed())
r.setupScheme(mgr)

c, err := controller.New(controllerName, mgr, controller.Options{
Reconciler: reconciler,
MaxConcurrentReconciles: 1,
})
Expect(err).ToNot(HaveOccurred())
Expect(r.setupWatches(mgr, c)).To(Succeed())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This duplicates a bunch of code from SetupWithManager. I don't think we should be doing this, it makes the test brittle. I guess the reason is that you want to append to reconciledCRs? Perhaps consider using a hook for this instead?

Comment on lines +1633 to +1638
By("verifying the previously unlabeled CR was reconciled after label change", func() {
reconciledCRsMutex.Lock()
defer reconciledCRsMutex.Unlock()
Expect(reconciledCRs).To(ContainElement(unlabeledObjKey.String()))
})
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think once the above By passes, this one is superfluous, since it checks the same thing?

Eventually(func() []string {
reconciledCRsMutex.Lock()
defer reconciledCRsMutex.Unlock()
return reconciledCRs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that since this returns a slice pointing at the same backing array, the caller will race with other accesses 🤔
Perhaps instead check the existence of desired element in the Eventually, in the scope of the lock, and then make Should just check for true return value?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants