@@ -653,21 +653,30 @@ func (r *ReconcilerCommon[T, TL]) handleProgDelete(
653653 return internal .Requeue , fmt .Errorf ("failed to delete program from bpfman: %v" , err )
654654 }
655655
656- if r .removeFinalizer (ctx , bpfProgram .GetClientObject (), rec .getFinalizer ()) {
657- return internal .Updated , nil
658- }
659-
660656 if isBeingDeleted {
661657 // We're deleting these programs because the *Program is being
662- // deleted, so update the status and the program will be deleted
663- // when the owner is deleted.
658+ // deleted.
659+
660+ // So update the status.
664661 if r .updateStatus (ctx , rec , & bpfProgram , cond ) {
665662 return internal .Updated , nil
666663 }
664+
665+ // Then remove the finalizer, and the program will be deleted when
666+ // the owner is deleted.
667+ if r .removeFinalizer (ctx , bpfProgram .GetClientObject (), rec .getFinalizer ()) {
668+ return internal .Updated , nil
669+ }
667670 } else {
668671 // We're deleting these programs because they were not expected due
669672 // to changes that caused the containers to not be selected anymore.
670- // So, explicitly delete them.
673+
674+ // So, remove the finalizer.
675+ if r .removeFinalizer (ctx , bpfProgram .GetClientObject (), rec .getFinalizer ()) {
676+ return internal .Updated , nil
677+ }
678+
679+ // Then explicitly delete them.
671680 opts := client.DeleteOptions {}
672681 r .Logger .Info ("Calling KubeAPI to delete BpfProgram" , "Name" , bpfProgram .GetName (), "Owner" , bpfProgram .GetName ())
673682 if err := r .Delete (ctx , bpfProgram .GetClientObject (), & opts ); err != nil {
0 commit comments