Skip to content

Commit

Permalink
Merge pull request #354 from anfredette/delete-program-fix
Browse files Browse the repository at this point in the history
Fix intermittent error when deleting programs
  • Loading branch information
mergify[bot] authored Jan 2, 2025
2 parents bbf2301 + d527a51 commit 48d744b
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions controllers/bpfman-agent/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,21 +653,30 @@ func (r *ReconcilerCommon[T, TL]) handleProgDelete(
return internal.Requeue, fmt.Errorf("failed to delete program from bpfman: %v", err)
}

if r.removeFinalizer(ctx, bpfProgram.GetClientObject(), rec.getFinalizer()) {
return internal.Updated, nil
}

if isBeingDeleted {
// We're deleting these programs because the *Program is being
// deleted, so update the status and the program will be deleted
// when the owner is deleted.
// deleted.

// So update the status.
if r.updateStatus(ctx, rec, &bpfProgram, cond) {
return internal.Updated, nil
}

// Then remove the finalizer, and the program will be deleted when
// the owner is deleted.
if r.removeFinalizer(ctx, bpfProgram.GetClientObject(), rec.getFinalizer()) {
return internal.Updated, nil
}
} else {
// We're deleting these programs because they were not expected due
// to changes that caused the containers to not be selected anymore.
// So, explicitly delete them.

// So, remove the finalizer.
if r.removeFinalizer(ctx, bpfProgram.GetClientObject(), rec.getFinalizer()) {
return internal.Updated, nil
}

// Then explicitly delete them.
opts := client.DeleteOptions{}
r.Logger.Info("Calling KubeAPI to delete BpfProgram", "Name", bpfProgram.GetName(), "Owner", bpfProgram.GetName())
if err := r.Delete(ctx, bpfProgram.GetClientObject(), &opts); err != nil {
Expand Down

0 comments on commit 48d744b

Please sign in to comment.