Skip to content

Commit 1a7adeb

Browse files
committed
Fix helmrepo reconciler unfinished worker bug
Although all the APIs had interval as a required field, when tests objects were created, they had the zero value of interval, which the API server accepts. A zero interval value results in the test objects to reconcile only once when they are created and never reconcile again unless there's an update to the object. Most of the tests worked with this behavior. With HelmRepository removing the interval requirement and adding an internal default, all the HelmRepository objects created in the tests without any interval have a default interval value which results in objects to reconcile automatically if they are not cleaned up after running tests. TestHelmRepositoryReconciler_InMemoryCaching and TestHelmChartReconciler_Reconcile create HelmRepository but doesn't delete it at the end. This leads to a reconciliation of HelmRepository outside of the test in the envtest environment. It just happened to be that the reconciliation time matches with the end of test time. At the end of the test run, the reconcilers receive shutdown signal and any test server, like helmrepository server, are stopped. A HelmRepository reconciliation triggered just before the shutdown signal gets stuck in the reconciliation. HelmRepository can't download the index as the test index server has stopped and hangs for some time. The HelmRepository reconciler worker remains in active state, unlike other reconciler workers that shut down, resulting in the test to timeout at the end. The is fixed by deleting the HelmRepository object created in TestHelmRepositoryReconciler_InMemoryCaching and TestHelmChartReconciler_Reconcile at the end of the test similar to other tests. Signed-off-by: Sunny <[email protected]>
1 parent 3dacb31 commit 1a7adeb

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

internal/controller/helmchart_controller_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ func TestHelmChartReconciler_Reconcile(t *testing.T) {
293293
}
294294

295295
g.Expect(testEnv.CreateAndWait(ctx, &repository)).To(Succeed())
296+
defer func() { g.Expect(testEnv.Delete(ctx, &repository)).To(Succeed()) }()
296297

297298
obj := helmv1.HelmChart{
298299
ObjectMeta: metav1.ObjectMeta{

internal/controller/helmrepository_controller_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -1703,6 +1703,16 @@ func TestHelmRepositoryReconciler_InMemoryCaching(t *testing.T) {
17031703
g.Expect(err).ToNot(HaveOccurred())
17041704
_, cacheHit := testCache.Get(helmRepo.GetArtifact().Path)
17051705
g.Expect(cacheHit).To(BeTrue())
1706+
1707+
g.Expect(testEnv.Delete(ctx, helmRepo)).To(Succeed())
1708+
1709+
// Wait for HelmRepository to be deleted
1710+
g.Eventually(func() bool {
1711+
if err := testEnv.Get(ctx, key, helmRepo); err != nil {
1712+
return apierrors.IsNotFound(err)
1713+
}
1714+
return false
1715+
}, timeout).Should(BeTrue())
17061716
}
17071717

17081718
func TestHelmRepositoryReconciler_ociMigration(t *testing.T) {

0 commit comments

Comments
 (0)