@@ -12,6 +12,7 @@ import (
12
12
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
13
13
"k8s.io/apimachinery/pkg/labels"
14
14
"k8s.io/apimachinery/pkg/runtime"
15
+ kutilerrors "k8s.io/apimachinery/pkg/util/errors"
15
16
kubeinformers "k8s.io/client-go/informers"
16
17
corelistersv1 "k8s.io/client-go/listers/core/v1"
17
18
"k8s.io/client-go/util/workqueue"
@@ -88,7 +89,14 @@ func newNodeInformerController(
88
89
return controller
89
90
}
90
91
92
+ var once sync.Once
93
+
91
94
func (c * nodeInformerController ) sync (ctx context.Context , syncCtx factory.SyncContext ) error {
95
+ // Warm up controller's caches.
96
+ // This has to be called after informers caches have been synced and before the first event comes in.
97
+ // The existing openshift-library does not provide such a hook.
98
+ once .Do (c .initializeCachesNoErrors )
99
+
92
100
queueKey := syncCtx .QueueKey ()
93
101
klog .V (4 ).Infof ("NI :: Syncing with key %s" , queueKey )
94
102
@@ -194,6 +202,37 @@ func (c *nodeInformerController) sync(ctx context.Context, syncCtx factory.SyncC
194
202
return nil
195
203
}
196
204
205
+ func (c * nodeInformerController ) initializeCachesNoErrors () {
206
+ if err := c .initializeCaches (); err != nil {
207
+ klog .Errorf ("Failed to initialize caches: %v" , err )
208
+ }
209
+ }
210
+
211
+ func (c * nodeInformerController ) initializeCaches () error {
212
+ var errs []error
213
+
214
+ if pools , err := c .machineConfigPools .List (labels .Everything ()); err != nil {
215
+ errs = append (errs , err )
216
+ } else {
217
+ for _ , pool := range pools {
218
+ c .machineConfigPoolSelectorCache .ingest (pool )
219
+ }
220
+ }
221
+ klog .V (2 ).Infof ("Stored %d machineConfigPools in the cache" , c .machineConfigPoolSelectorCache .len ())
222
+
223
+ machineConfigs , err := c .machineConfigs .List (labels .Everything ())
224
+ if err != nil {
225
+ errs = append (errs , err )
226
+ } else {
227
+ for _ , mc := range machineConfigs {
228
+ c .machineConfigVersionCache .ingest (mc )
229
+ }
230
+ }
231
+ klog .V (2 ).Infof ("Stored %d machineConfig versions in the cache" , c .machineConfigVersionCache .len ())
232
+
233
+ return kutilerrors .NewAggregate (errs )
234
+ }
235
+
197
236
type machineConfigVersionCache struct {
198
237
cache map [string ]string
199
238
lock sync.Mutex
@@ -240,6 +279,12 @@ func (c *machineConfigVersionCache) match(config string) (string, bool) {
240
279
return v , ok
241
280
}
242
281
282
+ func (c * machineConfigVersionCache ) len () int {
283
+ c .lock .Lock ()
284
+ defer c .lock .Unlock ()
285
+ return len (c .cache )
286
+ }
287
+
243
288
type machineConfigPoolSelectorCache struct {
244
289
cache map [string ]labels.Selector
245
290
lock sync.Mutex
0 commit comments