Skip to content

Commit c008e6f

Browse files
committed
Fix issue with object deletes failing
Signed-off-by: Andre Fredette <[email protected]>
1 parent d256664 commit c008e6f

15 files changed

+63
-76
lines changed

Diff for: apis/v1alpha1/bpf_application_state_types.go

-4
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ type BpfApplicationProgramState struct {
6464
URetProbe *UprobeProgramInfoState `json:"uretprobe,omitempty"`
6565
}
6666

67-
type BpfApplicationStateSpec struct {
68-
}
69-
7067
// BpfApplicationStateStatus reflects the status of the BpfApplication on the given node
7168
type BpfApplicationStateStatus struct {
7269
// updateCount is the number of times the BpfApplicationState has been updated. Set to 1
@@ -103,7 +100,6 @@ type BpfApplicationState struct {
103100
metav1.TypeMeta `json:",inline"`
104101
metav1.ObjectMeta `json:"metadata,omitempty"`
105102

106-
Spec BpfApplicationStateSpec `json:"spec,omitempty"`
107103
Status BpfApplicationStateStatus `json:"status,omitempty"`
108104
}
109105

Diff for: apis/v1alpha1/cluster_bpf_application_state_types.go

-4
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,6 @@ type ClBpfApplicationProgramState struct {
9494
TracePoint *ClTracepointProgramInfoState `json:"tracepoint,omitempty"`
9595
}
9696

97-
type ClBpfApplicationStateSpec struct {
98-
}
99-
10097
// ClBpfApplicationStateStatus reflects the status of the ClusterBpfApplicationState on the given node
10198
type ClBpfApplicationStateStatus struct {
10299
// updateCount is the number of times the BpfApplicationState has been updated. Set to 1
@@ -134,7 +131,6 @@ type ClusterBpfApplicationState struct {
134131
metav1.TypeMeta `json:",inline"`
135132
metav1.ObjectMeta `json:"metadata,omitempty"`
136133

137-
Spec ClBpfApplicationStateSpec `json:"spec,omitempty"`
138134
Status ClBpfApplicationStateStatus `json:"status,omitempty"`
139135
}
140136

Diff for: apis/v1alpha1/shared_types.go

+20-7
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,14 @@ const (
339339
// node while attempting to apply the configuration described in the CRD.
340340
BpfAppStateCondProgramListChangedError BpfApplicationStateConditionType = "ProgramListChangedError"
341341

342-
// BpfAppStateCondDeleteError indicates that the BPF Application was marked
343-
// for deletion, but deletion was unsuccessful on the given node.
344-
BpfAppStateCondDeleteError BpfApplicationStateConditionType = "DeleteError"
342+
// BpfAppStateCondUnloadError indicates that the BPF Application was marked
343+
// for deletion, but unloading one or more programs was unsuccessful on the
344+
// given node.
345+
BpfAppStateCondUnloadError BpfApplicationStateConditionType = "UnloadError"
346+
347+
// BpfAppStateCondUnloaded indicates that the BPF Application was marked
348+
// for deletion, and has been successfully unloaded.
349+
BpfAppStateCondUnloaded BpfApplicationStateConditionType = "Unloaded"
345350
)
346351

347352
// Condition is a helper method to promote any given
@@ -375,13 +380,21 @@ func (b BpfApplicationStateConditionType) Condition() metav1.Condition {
375380
Reason: "Error",
376381
Message: "An error has occurred",
377382
}
378-
case BpfAppStateCondDeleteError:
379-
condType := string(BpfAppStateCondDeleteError)
383+
case BpfAppStateCondUnloadError:
384+
condType := string(BpfAppStateCondUnloadError)
380385
cond = metav1.Condition{
381386
Type: condType,
382387
Status: metav1.ConditionTrue,
383-
Reason: "Delete Error",
384-
Message: "Deletion failed on one or more nodes",
388+
Reason: "Unload Error",
389+
Message: "Unload failed for one or more programs",
390+
}
391+
case BpfAppStateCondUnloaded:
392+
condType := string(BpfAppStateCondUnloaded)
393+
cond = metav1.Condition{
394+
Type: condType,
395+
Status: metav1.ConditionTrue,
396+
Reason: "Unloaded",
397+
Message: "The application has been successfully unloaded",
385398
}
386399
}
387400
return cond

Diff for: apis/v1alpha1/zz_generated.deepcopy.go

-32
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: bundle/manifests/bpfman-operator.clusterserviceversion.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,7 @@ metadata:
998998
capabilities: Basic Install
999999
categories: OpenShift Optional
10001000
containerImage: quay.io/bpfman/bpfman-operator:latest
1001-
createdAt: "2025-04-01T15:12:21Z"
1001+
createdAt: "2025-04-02T21:50:16Z"
10021002
description: The bpfman Operator is designed to manage eBPF programs for applications.
10031003
features.operators.openshift.io/cnf: "false"
10041004
features.operators.openshift.io/cni: "false"

Diff for: bundle/manifests/bpfman.io_bpfapplicationstates.yaml

-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ spec:
4646
type: string
4747
metadata:
4848
type: object
49-
spec:
50-
type: object
5149
status:
5250
description: BpfApplicationStateStatus reflects the status of the BpfApplication
5351
on the given node

Diff for: bundle/manifests/bpfman.io_clusterbpfapplicationstates.yaml

-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ spec:
4646
type: string
4747
metadata:
4848
type: object
49-
spec:
50-
type: object
5149
status:
5250
description: ClBpfApplicationStateStatus reflects the status of the ClusterBpfApplicationState
5351
on the given node

Diff for: config/crd/bases/bpfman.io_bpfapplicationstates.yaml

-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ spec:
4646
type: string
4747
metadata:
4848
type: object
49-
spec:
50-
type: object
5149
status:
5250
description: BpfApplicationStateStatus reflects the status of the BpfApplication
5351
on the given node

Diff for: config/crd/bases/bpfman.io_clusterbpfapplicationstates.yaml

-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ spec:
4646
type: string
4747
metadata:
4848
type: object
49-
spec:
50-
type: object
5149
status:
5250
description: ClBpfApplicationStateStatus reflects the status of the ClusterBpfApplicationState
5351
on the given node

Diff for: controllers/bpfman-agent/cl_application_program.go

+17-9
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
bpfmaniov1alpha1 "github.com/bpfman/bpfman-operator/apis/v1alpha1"
2525
bpfmanagentinternal "github.com/bpfman/bpfman-operator/controllers/bpfman-agent/internal"
2626
"github.com/bpfman/bpfman-operator/internal"
27+
"github.com/bpfman/bpfman-operator/pkg/helpers"
2728
gobpfman "github.com/bpfman/bpfman/clients/gobpfman/v1"
2829

2930
v1 "k8s.io/api/core/v1"
@@ -109,7 +110,7 @@ func (r *ClBpfApplicationReconciler) SetupWithManager(mgr ctrl.Manager) error {
109110
builder.WithPredicates(predicate.And(predicate.LabelChangedPredicate{}, nodePredicate(r.NodeName))),
110111
).
111112
// Watch for changes in Pod resources in case we are using a container
112-
// or network namepsce selector.
113+
// or network namespace selector.
113114
Watches(
114115
&v1.Pod{},
115116
&handler.EnqueueRequestForObject{},
@@ -241,12 +242,13 @@ func (r *ClBpfApplicationReconciler) Reconcile(ctx context.Context, req ctrl.Req
241242
r.Logger.Info("Successfully reconciled program", "Name", rec.getProgName())
242243
}
243244
}
245+
}
244246

245-
// If the bpfApplicationStatus didn't get changed to an error already,
246-
// check the status of the programs.
247-
if bpfApplicationStatus == bpfmaniov1alpha1.BpfAppStateCondSuccess {
248-
bpfApplicationStatus = r.checkProgramStatus()
249-
}
247+
// If the bpfApplicationStatus didn't get changed to an error already,
248+
// check the status of the programs.
249+
if bpfApplicationStatus == bpfmaniov1alpha1.BpfAppStateCondSuccess {
250+
bpfApplicationStatus = r.checkProgramStatus()
251+
r.Logger.Info("Checking program status", "Name", r.currentAppState.Name, "Status", bpfApplicationStatus)
250252
}
251253

252254
r.updateBpfAppStateCondition(r, bpfApplicationStatus)
@@ -262,7 +264,7 @@ func (r *ClBpfApplicationReconciler) Reconcile(ctx context.Context, req ctrl.Req
262264
return ctrl.Result{}, nil
263265
}
264266

265-
if r.isBeingDeleted() {
267+
if r.isBeingDeleted() && !helpers.IsBpfAppStateConditionFailure(r.currentAppState.Status.Conditions) {
266268
r.Logger.Info("BpfApplication is being deleted", "Name", r.currentApp.Name)
267269
if r.removeFinalizer(ctx, r.currentAppState, r.finalizer) {
268270
return ctrl.Result{}, nil
@@ -289,7 +291,7 @@ func (r *ClBpfApplicationReconciler) createBpfAppState(ctx context.Context) (ctr
289291
r.Logger.Error(err, "failed to create BpfApplicationState object")
290292
return ctrl.Result{Requeue: true, RequeueAfter: retryDurationAgent}, nil
291293
}
292-
if err := r.initBpfAppStateStatus(ctx); err != nil {
294+
if err := r.initBpfAppStateStatus(); err != nil {
293295
r.Logger.Error(err, "failed to initialize BpfApplicationState status")
294296
return ctrl.Result{Requeue: true, RequeueAfter: retryDurationAgent}, nil
295297
}
@@ -397,6 +399,12 @@ func (r *ClBpfApplicationReconciler) getProgramReconciler(prog *bpfmaniov1alpha1
397399
}
398400

399401
func (r *ClBpfApplicationReconciler) checkProgramStatus() bpfmaniov1alpha1.BpfApplicationStateConditionType {
402+
if r.currentAppState.Status.AppLoadStatus == bpfmaniov1alpha1.AppLoadError {
403+
return bpfmaniov1alpha1.BpfAppStateCondUnloadError
404+
}
405+
if r.currentAppState.Status.AppLoadStatus == bpfmaniov1alpha1.AppUnLoadSuccess {
406+
return bpfmaniov1alpha1.BpfAppStateCondUnloaded
407+
}
400408
for _, program := range r.currentAppState.Status.Programs {
401409
if program.ProgramLinkStatus != bpfmaniov1alpha1.ProgAttachSuccess {
402410
return bpfmaniov1alpha1.BpfAppStateCondError
@@ -573,7 +581,7 @@ func (r *ClBpfApplicationReconciler) initBpfAppState() error {
573581
return nil
574582
}
575583

576-
func (r *ClBpfApplicationReconciler) initBpfAppStateStatus(ctx context.Context) error {
584+
func (r *ClBpfApplicationReconciler) initBpfAppStateStatus() error {
577585
r.currentAppState.Status = bpfmaniov1alpha1.ClBpfApplicationStateStatus{
578586
Node: r.NodeName,
579587
AppLoadStatus: bpfmaniov1alpha1.AppLoadNotLoaded,

Diff for: controllers/bpfman-agent/ns_application_program.go

+15-8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
bpfmaniov1alpha1 "github.com/bpfman/bpfman-operator/apis/v1alpha1"
2525
bpfmanagentinternal "github.com/bpfman/bpfman-operator/controllers/bpfman-agent/internal"
2626
"github.com/bpfman/bpfman-operator/internal"
27+
"github.com/bpfman/bpfman-operator/pkg/helpers"
2728
gobpfman "github.com/bpfman/bpfman/clients/gobpfman/v1"
2829

2930
v1 "k8s.io/api/core/v1"
@@ -241,12 +242,12 @@ func (r *NsBpfApplicationReconciler) Reconcile(ctx context.Context, req ctrl.Req
241242
r.Logger.Info("Successfully reconciled program", "Name", rec.getProgName())
242243
}
243244
}
245+
}
244246

245-
// If the bpfApplicationStatus didn't get changed to an error already,
246-
// check the status of the programs.
247-
if bpfApplicationStatus == bpfmaniov1alpha1.BpfAppStateCondSuccess {
248-
bpfApplicationStatus = r.checkProgramStatus()
249-
}
247+
// If the bpfApplicationStatus didn't get changed to an error already,
248+
// check the status of the programs.
249+
if bpfApplicationStatus == bpfmaniov1alpha1.BpfAppStateCondSuccess {
250+
bpfApplicationStatus = r.checkProgramStatus()
250251
}
251252

252253
r.updateBpfAppStateCondition(r, bpfApplicationStatus)
@@ -262,7 +263,7 @@ func (r *NsBpfApplicationReconciler) Reconcile(ctx context.Context, req ctrl.Req
262263
return ctrl.Result{}, nil
263264
}
264265

265-
if r.isBeingDeleted() {
266+
if r.isBeingDeleted() && !helpers.IsBpfAppStateConditionFailure(r.currentAppState.Status.Conditions) {
266267
r.Logger.Info("BpfApplication is being deleted", "Name", r.currentApp.Name)
267268
if r.removeFinalizer(ctx, r.currentAppState, r.finalizer) {
268269
return ctrl.Result{}, nil
@@ -289,7 +290,7 @@ func (r *NsBpfApplicationReconciler) createBpfAppState(ctx context.Context) (ctr
289290
r.Logger.Error(err, "failed to create BpfApplicationState object")
290291
return ctrl.Result{Requeue: true, RequeueAfter: retryDurationAgent}, nil
291292
}
292-
if err := r.initBpfAppStateStatus(ctx); err != nil {
293+
if err := r.initBpfAppStateStatus(); err != nil {
293294
r.Logger.Error(err, "failed to initialize BpfApplicationState status")
294295
return ctrl.Result{Requeue: true, RequeueAfter: retryDurationAgent}, nil
295296
}
@@ -352,6 +353,12 @@ func (r *NsBpfApplicationReconciler) getProgramReconciler(prog *bpfmaniov1alpha1
352353
}
353354

354355
func (r *NsBpfApplicationReconciler) checkProgramStatus() bpfmaniov1alpha1.BpfApplicationStateConditionType {
356+
if r.currentAppState.Status.AppLoadStatus == bpfmaniov1alpha1.AppLoadError {
357+
return bpfmaniov1alpha1.BpfAppStateCondUnloadError
358+
}
359+
if r.currentAppState.Status.AppLoadStatus == bpfmaniov1alpha1.AppUnLoadSuccess {
360+
return bpfmaniov1alpha1.BpfAppStateCondUnloaded
361+
}
355362
for _, program := range r.currentAppState.Status.Programs {
356363
if program.ProgramLinkStatus != bpfmaniov1alpha1.ProgAttachSuccess {
357364
return bpfmaniov1alpha1.BpfAppStateCondError
@@ -518,7 +525,7 @@ func (r *NsBpfApplicationReconciler) initBpfAppState() error {
518525
return nil
519526
}
520527

521-
func (r *NsBpfApplicationReconciler) initBpfAppStateStatus(ctx context.Context) error {
528+
func (r *NsBpfApplicationReconciler) initBpfAppStateStatus() error {
522529
r.currentAppState.Status = bpfmaniov1alpha1.BpfApplicationStateStatus{
523530
Node: r.NodeName,
524531
AppLoadStatus: bpfmaniov1alpha1.AppLoadNotLoaded,

Diff for: controllers/bpfman-operator/cl_application_programs.go

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func (r *BpfApplicationReconciler) getFinalizer() string {
5454
}
5555

5656
// SetupWithManager sets up the controller with the Manager.
57+
5758
func (r *BpfApplicationReconciler) SetupWithManager(mgr ctrl.Manager) error {
5859
return ctrl.NewControllerManagedBy(mgr).
5960
For(&bpfmaniov1alpha1.ClusterBpfApplication{}).

Diff for: controllers/bpfman-operator/common_cluster.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ func statusChangedPredicateCluster() predicate.Funcs {
7474
UpdateFunc: func(e event.UpdateEvent) bool {
7575
oldObject := e.ObjectOld.(*bpfmaniov1alpha1.ClusterBpfApplicationState)
7676
newObject := e.ObjectNew.(*bpfmaniov1alpha1.ClusterBpfApplicationState)
77-
return !reflect.DeepEqual(oldObject.Status.Conditions, newObject.Status.Conditions)
77+
statusChanged := !reflect.DeepEqual(oldObject.Status.Conditions, newObject.Status.Conditions)
78+
finalizerChanged := controllerutil.ContainsFinalizer(oldObject, internal.ClBpfApplicationControllerFinalizer) !=
79+
controllerutil.ContainsFinalizer(newObject, internal.ClBpfApplicationControllerFinalizer)
80+
return statusChanged || finalizerChanged
7881
},
7982
DeleteFunc: func(e event.DeleteEvent) bool {
8083
return false

Diff for: controllers/bpfman-operator/common_namespace.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ func statusChangedPredicateNamespace() predicate.Funcs {
7575
UpdateFunc: func(e event.UpdateEvent) bool {
7676
oldObject := e.ObjectOld.(*bpfmaniov1alpha1.BpfApplicationState)
7777
newObject := e.ObjectNew.(*bpfmaniov1alpha1.BpfApplicationState)
78-
return !reflect.DeepEqual(oldObject.Status.Conditions, newObject.Status.Conditions)
78+
statusChanged := !reflect.DeepEqual(oldObject.Status.Conditions, newObject.Status.Conditions)
79+
finalizerChanged := controllerutil.ContainsFinalizer(oldObject, internal.NsBpfApplicationControllerFinalizer) !=
80+
controllerutil.ContainsFinalizer(newObject, internal.NsBpfApplicationControllerFinalizer)
81+
return statusChanged || finalizerChanged
7982
},
8083
DeleteFunc: func(e event.DeleteEvent) bool {
8184
return false

Diff for: pkg/helpers/helpers.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func IsBpfAppStateConditionFailure(conditions []metav1.Condition) bool {
169169

170170
return conditions[0].Type == string(bpfmaniov1alpha1.BpfAppStateCondError) ||
171171
conditions[0].Type == string(bpfmaniov1alpha1.BpfAppStateCondProgramListChangedError) ||
172-
conditions[0].Type == string(bpfmaniov1alpha1.BpfAppStateCondDeleteError)
172+
conditions[0].Type == string(bpfmaniov1alpha1.BpfAppStateCondUnloadError)
173173
}
174174

175175
func IsBpfAppStateConditionPending(conditions []metav1.Condition) bool {

0 commit comments

Comments
 (0)