@@ -227,6 +227,8 @@ func main() {
227
227
reqRemoteLiqoPods , err := labels .NewRequirement (consts .ManagedByLabelKey , selection .Equals , []string {consts .ManagedByShadowPodValue })
228
228
utilruntime .Must (err )
229
229
230
+ // Create the main manager.
231
+ // This manager caches only the pods that are offloaded from a remote cluster and are scheduled on this.
230
232
mgr , err := ctrl .NewManager (config , ctrl.Options {
231
233
MapperProvider : mapper .LiqoMapperProvider (scheme ),
232
234
Scheme : scheme ,
@@ -257,7 +259,8 @@ func main() {
257
259
utilruntime .Must (err )
258
260
259
261
// Create an accessory manager that cache only local offloaded pods.
260
- auxmgr , err := ctrl .NewManager (config , ctrl.Options {
262
+ // This manager caches only the pods that are offloaded and scheduled on a remote cluster.
263
+ auxmgrLocalPods , err := ctrl .NewManager (config , ctrl.Options {
261
264
MapperProvider : mapper .LiqoMapperProvider (scheme ),
262
265
Scheme : scheme ,
263
266
MetricsBindAddress : "0" , // Disable the metrics of the auxiliary manager to prevent conflicts.
@@ -275,12 +278,42 @@ func main() {
275
278
klog .Errorf ("Unable to create auxiliary manager: %w" , err )
276
279
os .Exit (1 )
277
280
}
278
- if err := mgr .Add (auxmgr ); err != nil {
281
+
282
+ // Create a label selector to filter only the events for virtual kubelet pods
283
+ reqVirtualKubeletPods , err := labels .NewRequirement (consts .K8sAppComponentKey , selection .Equals ,
284
+ []string {vkMachinery .KubeletBaseLabels [consts .K8sAppComponentKey ]})
285
+ utilruntime .Must (err )
286
+
287
+ // Create an accessory manager that cache only local offloaded pods.
288
+ // This manager caches only virtual kubelet pods.
289
+ auxmgrVirtualKubeletPods , err := ctrl .NewManager (config , ctrl.Options {
290
+ MapperProvider : mapper .LiqoMapperProvider (scheme ),
291
+ Scheme : scheme ,
292
+ MetricsBindAddress : "0" , // Disable the metrics of the auxiliary manager to prevent conflicts.
293
+ NewCache : func (config * rest.Config , opts cache.Options ) (cache.Cache , error ) {
294
+ opts .ByObject = map [client.Object ]cache.ByObject {
295
+ & corev1.Pod {}: {
296
+ Label : labels .NewSelector ().Add (* reqVirtualKubeletPods ),
297
+ },
298
+ }
299
+ return cache .New (config , opts )
300
+ },
301
+ })
302
+
303
+ if err != nil {
304
+ klog .Errorf ("Unable to create auxiliary manager: %w" , err )
305
+ os .Exit (1 )
306
+ }
307
+
308
+ if err := mgr .Add (auxmgrLocalPods ); err != nil {
279
309
klog .Errorf ("Unable to add the auxiliary manager to the main one: %w" , err )
280
310
os .Exit (1 )
281
311
}
282
312
283
- localPodsClient := auxmgr .GetClient ()
313
+ if err := mgr .Add (auxmgrVirtualKubeletPods ); err != nil {
314
+ klog .Errorf ("Unable to add the auxiliary manager to the main one: %w" , err )
315
+ os .Exit (1 )
316
+ }
284
317
285
318
// Register the healthiness probes.
286
319
if err := mgr .AddHealthzCheck ("healthz" , healthz .Ping ); err != nil {
@@ -307,7 +340,7 @@ func main() {
307
340
os .Exit (1 )
308
341
}
309
342
310
- if err := indexer .IndexField (ctx , auxmgr , & corev1.Pod {}, indexer .FieldNodeNameFromPod , indexer .ExtractNodeName ); err != nil {
343
+ if err := indexer .IndexField (ctx , auxmgrLocalPods , & corev1.Pod {}, indexer .FieldNodeNameFromPod , indexer .ExtractNodeName ); err != nil {
311
344
klog .Errorf ("Unable to setup the indexer for the Pod nodeName field: %v" , err )
312
345
os .Exit (1 )
313
346
}
@@ -394,7 +427,8 @@ func main() {
394
427
virtualNodeReconciler , err := virtualnodectrl .NewVirtualNodeReconciler (
395
428
ctx ,
396
429
mgr .GetClient (),
397
- auxmgr .GetClient (),
430
+ auxmgrLocalPods .GetClient (),
431
+ auxmgrVirtualKubeletPods .GetClient (),
398
432
mgr .GetScheme (),
399
433
mgr .GetEventRecorderFor ("virtualnode-controller" ),
400
434
& clusterIdentity ,
@@ -485,7 +519,7 @@ func main() {
485
519
podStatusReconciler := & podstatusctrl.PodStatusReconciler {
486
520
Client : mgr .GetClient (),
487
521
Scheme : mgr .GetScheme (),
488
- LocalPodsClient : localPodsClient ,
522
+ LocalPodsClient : auxmgrLocalPods . GetClient () ,
489
523
}
490
524
if err = podStatusReconciler .SetupWithManager (mgr ); err != nil {
491
525
klog .Errorf ("Unable to start the podstatus reconciler" , err )
0 commit comments