@@ -62,7 +62,7 @@ type bpfProgramConditionType string
62
62
63
63
const (
64
64
BpfdAgentFinalizer = "bpfd.io.agent/finalizer"
65
- retryDurationAgent = 10 * time .Second
65
+ retryDurationAgent = 5 * time .Second
66
66
BpfProgCondLoaded bpfProgramConditionType = "Loaded"
67
67
BpfProgCondNotLoaded bpfProgramConditionType = "NotLoaded"
68
68
BpfProgCondNotUnloaded bpfProgramConditionType = "NotUnLoaded"
@@ -115,10 +115,6 @@ func (b bpfProgramConditionType) Condition() metav1.Condition {
115
115
116
116
// Reconcile is part of the main kubernetes reconciliation loop which aims to
117
117
// move the current state of the cluster closer to the desired state.
118
- // TODO(user): Modify the Reconcile function to compare the state specified by
119
- // the BpfProgram object against the actual cluster state, and then
120
- // perform operations to make the cluster state reflect the state specified by
121
- // the user.
122
118
// This should be called in the following scenarios
123
119
// 1. A new BpfProgramConfig Object is created
124
120
// 2. An BpfProgramConfig Object is Updated (i.e one of the following fields change
@@ -129,7 +125,7 @@ func (b bpfProgramConditionType) Condition() metav1.Condition {
129
125
//
130
126
// 3. Our NodeLabels are updated and the Node is no longer selected by an BpfProgramConfig
131
127
//
132
- // 4. An bpfProgramCongfig Object is deleted
128
+ // 4. An bpfProgramConfig Object is deleted
133
129
// For more details, check Reconcile and its Result here:
134
130
// - https://pkg.go.dev/sigs.k8s.io/[email protected] /pkg/reconcile
135
131
func (r * BpfProgramReconciler ) Reconcile (ctx context.Context , req ctrl.Request ) (ctrl.Result , error ) {
@@ -174,7 +170,7 @@ func (r *BpfProgramReconciler) Reconcile(ctx context.Context, req ctrl.Request)
174
170
// Reconcile every BpfProgramConfig Object
175
171
// note: This doesn't necessarily result in any extra grpc calls to bpfd
176
172
for _ , BpfProgramConfig := range BpfProgramConfigs .Items {
177
- retry , err := r .reconcilBpfProgramConfig (ctx , & BpfProgramConfig , ourNode , existingConfigs )
173
+ retry , err := r .reconcileBpfProgramConfig (ctx , & BpfProgramConfig , ourNode , existingConfigs )
178
174
if err != nil {
179
175
r .Logger .Error (err , "Reconciling BpfProgramConfig Failed" , "BpfProgramConfigName" , BpfProgramConfig .Name , "Retrying" , retry )
180
176
return ctrl.Result {Requeue : retry , RequeueAfter : retryDurationAgent }, nil
@@ -184,9 +180,9 @@ func (r *BpfProgramReconciler) Reconcile(ctx context.Context, req ctrl.Request)
184
180
return ctrl.Result {Requeue : false }, nil
185
181
}
186
182
187
- // reconcilBpfProgramConfig reconciles the existing node state to the user intent
183
+ // reconcileBpfProgramConfig reconciles the existing node state to the user intent
188
184
// within a single BpfProgramConfig Object.
189
- func (r * BpfProgramReconciler ) reconcilBpfProgramConfig (ctx context.Context ,
185
+ func (r * BpfProgramReconciler ) reconcileBpfProgramConfig (ctx context.Context ,
190
186
BpfProgramConfig * bpfdiov1alpha1.BpfProgramConfig ,
191
187
ourNode * v1.Node ,
192
188
nodeState map [string ]internal.ExistingReq ) (bool , error ) {
@@ -348,17 +344,14 @@ func (r *BpfProgramReconciler) reconcilBpfProgramConfig(ctx context.Context,
348
344
Maps : maps ,
349
345
}
350
346
351
- r .Logger .V (1 ).Info ("Updating programs" , "Programs" , bpfProgram .Spec .Programs )
347
+ r .Logger .V (1 ).Info ("Updating programs from nodestate " , "Programs" , bpfProgram .Spec .Programs )
352
348
// Update bpfProgram once successfully loaded
353
349
if err = r .Update (ctx , bpfProgram , & client.UpdateOptions {}); err != nil {
354
350
return false , fmt .Errorf ("failed to create bpfProgram object: %v" ,
355
351
err )
356
352
}
357
353
358
354
r .updateStatus (ctx , bpfProgram , BpfProgCondLoaded )
359
-
360
- r .Logger .Info ("Updated Programs on bpfProgram Object from nodeState" ,
361
- "bpfProgramName" , bpfProgram .Name )
362
355
} else {
363
356
// Program exists and bpfProgram K8s Object is up to date
364
357
r .Logger .Info ("Ignoring Object Change nothing to reconcile on node" )
@@ -390,10 +383,10 @@ func (r *BpfProgramReconciler) loadBpfdProgram(ctx context.Context, loadRequest
390
383
Maps : maps ,
391
384
}
392
385
393
- r .Logger .V (1 ).Info ("Updating programs" , "Programs" , prog .Spec .Programs )
386
+ r .Logger .V (1 ).Info ("updating programs after load " , "Programs" , prog .Spec .Programs )
394
387
// Update bpfProgram once successfully loaded
395
388
if err = r .Update (ctx , prog , & client.UpdateOptions {}); err != nil {
396
- return false , fmt .Errorf ("failed to create bpfProgram object : %v" ,
389
+ return false , fmt .Errorf ("failed to update bpfProgram programs : %v" ,
397
390
err )
398
391
}
399
392
return false , nil
@@ -416,6 +409,14 @@ func (r *BpfProgramReconciler) unloadBpfdProgram(ctx context.Context, prog *bpfd
416
409
return true , fmt .Errorf ("failed to unload bpfProgram via bpfd: %v" ,
417
410
err )
418
411
}
412
+ delete (prog .Spec .Programs , uuid )
413
+ }
414
+
415
+ r .Logger .V (1 ).Info ("updating programs after unload" , "Programs" , prog .Spec .Programs )
416
+ // Update bpfProgram once successfully unloaded
417
+ if err := r .Update (ctx , prog , & client.UpdateOptions {}); err != nil {
418
+ return false , fmt .Errorf ("failed to update bpfProgram programs: %v" ,
419
+ err )
419
420
}
420
421
421
422
return false , nil
@@ -459,11 +460,20 @@ func (r *BpfProgramReconciler) SetupWithManager(mgr ctrl.Manager) error {
459
460
Complete (r )
460
461
}
461
462
462
- // Only return node updates for our node
463
+ // Only return node updates for our node (all events)
463
464
func nodePredicate (nodeName string ) predicate.Funcs {
464
465
return predicate.Funcs {
465
466
GenericFunc : func (e event.GenericEvent ) bool {
466
467
return e .Object .GetLabels ()["kubernetes.io/hostname" ] == nodeName
467
468
},
469
+ CreateFunc : func (e event.CreateEvent ) bool {
470
+ return e .Object .GetLabels ()["kubernetes.io/hostname" ] == nodeName
471
+ },
472
+ UpdateFunc : func (e event.UpdateEvent ) bool {
473
+ return e .ObjectNew .GetLabels ()["kubernetes.io/hostname" ] == nodeName
474
+ },
475
+ DeleteFunc : func (e event.DeleteEvent ) bool {
476
+ return e .Object .GetLabels ()["kubernetes.io/hostname" ] == nodeName
477
+ },
468
478
}
469
479
}
0 commit comments