@@ -41,6 +41,7 @@ import (
41
41
"k8s.io/client-go/informers"
42
42
"k8s.io/client-go/kubernetes/fake"
43
43
cgotesting "k8s.io/client-go/testing"
44
+ "k8s.io/client-go/tools/cache"
44
45
"k8s.io/client-go/tools/events"
45
46
resourceslicetracker "k8s.io/dynamic-resource-allocation/resourceslice/tracker"
46
47
kubeschedulerconfigv1 "k8s.io/kube-scheduler/config/v1"
@@ -2062,7 +2063,21 @@ func setup(t *testing.T, args *config.DynamicResourcesArgs, nodes []*v1.Node, cl
2062
2063
}
2063
2064
resourceSliceTracker , err := resourceslicetracker .StartTracker (tCtx , resourceSliceTrackerOpts )
2064
2065
require .NoError (t , err , "couldn't start resource slice tracker" )
2065
- tc .draManager = NewDRAManager (tCtx , assumecache .NewAssumeCache (tCtx .Logger (), tc .informerFactory .Resource ().V1 ().ResourceClaims ().Informer (), "resource claim" , "" , nil ), resourceSliceTracker , tc .informerFactory )
2066
+
2067
+ claimsCache := assumecache .NewAssumeCache (tCtx .Logger (), tc .informerFactory .Resource ().V1 ().ResourceClaims ().Informer (), "resource claim" , "" , nil )
2068
+ // NewAssumeCache calls the informer's AddEventHandler method to register
2069
+ // a handler in order to stay in sync with the informer's store, but
2070
+ // NewAssumeCache does not return the ResourceEventHandlerRegistration.
2071
+ // We call AddEventHandler of the assume cache, passing it a noop
2072
+ // ResourceEventHandler in order to get access to the
2073
+ // ResourceEventHandlerRegistration returned by the informer.
2074
+ //
2075
+ // This is not the registered handler that is used by the DRA
2076
+ // manager, but it is close enough because the assume cache
2077
+ // uses a single boolean for "is synced" for all handlers.
2078
+ registeredHandler := claimsCache .AddEventHandler (cache.ResourceEventHandlerFuncs {})
2079
+
2080
+ tc .draManager = NewDRAManager (tCtx , claimsCache , resourceSliceTracker , tc .informerFactory )
2066
2081
opts := []runtime.Option {
2067
2082
runtime .WithClientSet (tc .client ),
2068
2083
runtime .WithInformerFactory (tc .informerFactory ),
@@ -2103,6 +2118,11 @@ func setup(t *testing.T, args *config.DynamicResourcesArgs, nodes []*v1.Node, cl
2103
2118
})
2104
2119
2105
2120
tc .informerFactory .WaitForCacheSync (tc .ctx .Done ())
2121
+ // The above does not tell us if the registered handler (from NewAssumeCache)
2122
+ // is synced, we need to wait until HasSynced of the handler returns
2123
+ // true, this ensures that the assume cache is in sync with the informer's
2124
+ // store which has been informed by at least one full LIST of the underlying storage.
2125
+ cache .WaitForCacheSync (tc .ctx .Done (), registeredHandler .HasSynced )
2106
2126
2107
2127
for _ , node := range nodes {
2108
2128
nodeInfo := framework .NewNodeInfo ()
0 commit comments