Skip to content

Commit

Permalink
Fix intermittent error when deleting programs
Browse files Browse the repository at this point in the history
Fixes: #353

Signed-off-by: Andre Fredette <[email protected]>
  • Loading branch information
anfredette committed Dec 23, 2024
1 parent 9b4813d commit d527a51
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.

Check warning on line 660 in controllers/bpfman-agent/common.go

View check run for this annotation

Codecov / codecov/patch

controllers/bpfman-agent/common.go#L658-L660

Added lines #L658 - L660 were not covered by tests
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
}

Check warning on line 669 in controllers/bpfman-agent/common.go

View check run for this annotation

Codecov / codecov/patch

controllers/bpfman-agent/common.go#L667-L669

Added lines #L667 - L669 were not covered by tests
} 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
}

Check warning on line 677 in controllers/bpfman-agent/common.go

View check run for this annotation

Codecov / codecov/patch

controllers/bpfman-agent/common.go#L673-L677

Added lines #L673 - L677 were not covered by tests

// 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 d527a51

Please sign in to comment.