@@ -34,6 +34,7 @@ import (
3434
3535const (
3636 informerResyncPeriod = 10 * time .Minute
37+ mutationCacheTTL = time .Hour
3738)
3839
3940// GetComputeDomainFunc is a function type for getting a ComputeDomain by UID.
@@ -54,7 +55,8 @@ type ComputeDomainManager struct {
5455 previousNodes []* nvapi.ComputeDomainNode
5556 updatedNodesChan chan []* nvapi.ComputeDomainNode
5657
57- podManager * PodManager
58+ podManager * PodManager
59+ mutationCache cache.MutationCache
5860}
5961
6062// NewComputeDomainManager creates a new ComputeDomainManager instance.
@@ -101,6 +103,15 @@ func (m *ComputeDomainManager) Start(ctx context.Context) (rerr error) {
101103 return fmt .Errorf ("error adding indexer for ComputeDomain UID: %w" , err )
102104 }
103105
106+ // Create mutation cache to track our own updates
107+ m .mutationCache = cache .NewIntegerResourceVersionMutationCache (
108+ klog .Background (),
109+ m .informer .GetStore (),
110+ m .informer .GetIndexer (),
111+ mutationCacheTTL ,
112+ true ,
113+ )
114+
104115 _ , err = m .informer .AddEventHandler (cache.ResourceEventHandlerFuncs {
105116 AddFunc : func (obj any ) {
106117 m .config .workQueue .Enqueue (obj , m .onAddOrUpdate )
@@ -157,23 +168,19 @@ func (m *ComputeDomainManager) Stop() error {
157168 return nil
158169}
159170
160- // Get gets the ComputeDomain by UID from the informer cache.
171+ // Get gets the ComputeDomain by UID from the mutation cache.
161172func (m * ComputeDomainManager ) Get (uid string ) (* nvapi.ComputeDomain , error ) {
162- objs , err := m . informer . GetIndexer (). ByIndex ( "uid" , uid )
173+ cds , err := getByComputeDomainUID [ * nvapi. ComputeDomain ]( m . mutationCache , uid )
163174 if err != nil {
164175 return nil , fmt .Errorf ("error retrieving ComputeDomain by UID: %w" , err )
165176 }
166- if len (objs ) == 0 {
177+ if len (cds ) == 0 {
167178 return nil , nil
168179 }
169- if len (objs ) != 1 {
180+ if len (cds ) != 1 {
170181 return nil , fmt .Errorf ("multiple ComputeDomains with the same UID" )
171182 }
172- cd , ok := objs [0 ].(* nvapi.ComputeDomain )
173- if ! ok {
174- return nil , fmt .Errorf ("error casting to ComputeDomain" )
175- }
176- return cd , nil
183+ return cds [0 ], nil
177184}
178185
179186// onAddOrUpdate handles the addition or update of a ComputeDomain.
@@ -266,6 +273,9 @@ func (m *ComputeDomainManager) UpdateComputeDomainNodeInfo(ctx context.Context,
266273 return fmt .Errorf ("error updating nodes in ComputeDomain status: %w" , err )
267274 }
268275
276+ // Add the updated ComputeDomain to the mutation cache
277+ m .mutationCache .Mutation (newCD )
278+
269279 return nil
270280}
271281
0 commit comments