Revert "DRA ResourceClaim controller: updated mutation cache based on events"

This reverts commit 03c34ede46.

The additional informer event handling seems to have had a performance
impact (https://github.com/kubernetes/kubernetes/issues/140877).
Let's try without this optional enhancement, the code should be
correct also without it.
This commit is contained in:
Patrick Ohly
2026-07-23 18:08:07 +02:00
parent f99d91b885
commit cd1f19ca7e
2 changed files with 0 additions and 79 deletions

View File

@@ -764,15 +764,6 @@ func (ec *Controller) enqueueResourceClaim(logger klog.Logger, oldObj, newObj an
if claim == nil {
claim = oldClaim
}
// Inform the mutation cache before triggering sync operations (via enqueue
// below) so that syncs observe a current view of the claim.
if deleted {
ec.claimCache.OnDelete(claim)
} else {
ec.claimCache.OnAddOrUpdate(claim)
}
if !deleted {
// When starting up, we have to check all claims to find those with
// stale pods in ReservedFor. During an update, a pod might get added

View File

@@ -1178,76 +1178,6 @@ func testSyncHandler(tCtx ktesting.TContext) {
}
}
// TestControllerCreateDeleteRecreate verifies that a ResourceClaim which is
// deleted immediately after being created by the controller gets recreated on
// the next sync. Without the OnDelete call in enqueueResourceClaim the
// MutationCache keeps the stale "just-created" entry for up to its TTL
// (one hour), causing findPodResourceClaim to return it and skipping the
// recreate for that entire duration.
func TestControllerCreateDeleteRecreate(t *testing.T) {
ktesting.Init(t).SyncTest("", testControllerCreateDeleteRecreate)
}
func testControllerCreateDeleteRecreate(tCtx ktesting.TContext) {
setupMetrics()
fakeKubeClient := createTestClient(testPodWithResource, template)
informerFactory := informers.NewSharedInformerFactory(fakeKubeClient, controller.NoResyncPeriodFunc())
podInformer := informerFactory.Core().V1().Pods()
podGroupInformer := informerFactory.Scheduling().V1beta1().PodGroups()
claimInformer := informerFactory.Resource().V1().ResourceClaims()
templateInformer := informerFactory.Resource().V1().ResourceClaimTemplates()
ec, err := newControllerWithFeatures(tCtx.Logger(), fakeKubeClient, podInformer, podGroupInformer, claimInformer, templateInformer, controllerFeatures{})
tCtx.ExpectNoError(err, "creating controller")
tCtx.Cleanup(ec.queue.ShutDown)
informerFactory.Start(tCtx.Done())
tCtx.Cleanup(func() {
tCtx.Cancel("stopping informers")
informerFactory.Shutdown()
})
// Let informer goroutines process the initial list so the cache is warm.
tCtx.Wait()
// First sync: finds no existing claim, creates one, stores it in the
// mutation cache via claimCache.Mutation.
tCtx.ExpectNoError(ec.syncHandler(tCtx, podKey(testPodWithResource)))
claims, err := fakeKubeClient.ResourceV1().ResourceClaims(testNamespace).List(tCtx, metav1.ListOptions{})
tCtx.ExpectNoError(err)
if len(claims.Items) != 1 {
tCtx.Fatalf("expected 1 claim after first sync, got %d", len(claims.Items))
}
createdClaimName := claims.Items[0].Name
// Simulate an unexpected deletion (e.g. the claim was removed by an
// admin or a race between controller and GC).
tCtx.ExpectNoError(fakeKubeClient.ResourceV1().ResourceClaims(testNamespace).Delete(tCtx, createdClaimName, metav1.DeleteOptions{}))
// Wait for the informer goroutines to process the watch event and call
// enqueueResourceClaim with deleted=true. That call must invoke
// claimCache.OnDelete to clear the stale mutation — the code path under test.
tCtx.Wait()
// The mutation cache must be clear now.
mutClaims, err := ec.claimCache.ByIndex(claimPodOwnerIndex, string(testPodWithResource.UID))
tCtx.ExpectNoError(err)
if len(mutClaims) != 0 {
tCtx.Fatalf("expected empty mutation cache after delete, got %d entries", len(mutClaims))
}
// Second sync: must create a new claim because the mutation cache no
// longer holds the stale entry for the deleted claim.
tCtx.ExpectNoError(ec.syncHandler(tCtx, podKey(testPodWithResource)))
claims, err = fakeKubeClient.ResourceV1().ResourceClaims(testNamespace).List(tCtx, metav1.ListOptions{})
tCtx.ExpectNoError(err)
if len(claims.Items) != 1 {
tCtx.Fatalf("expected 1 claim after second sync (recreate), got %d", len(claims.Items))
}
}
// TestClaimExists covering the three places it looks for a claim
// (mutation cache, underlay informer store, storeapiserver), and a optional owner check.
func TestClaimExists(t *testing.T) { testClaimExists(ktesting.Init(t)) }