Skip to content

handle update app object by removing an existing program #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 8, 2024

Conversation

msherif1234
Copy link
Contributor

@msherif1234 msherif1234 commented Jul 3, 2024

fix #29

  • unit-test
    1- deploy app example oc create -f config/samples/bpfman.io_v1alpha1_bpfapplication.yaml
oc get bpfprograms 
NAME                                                                                                               TYPE          STATUS         AGE
bpfapplication-sample-kprobe-try-to-wake-up-bpfman-deployment-control-plane-try-to-wake-up                         application   bpfmanLoaded   31s
bpfapplication-sample-tc-ingress-eth0-bpfman-deployment-control-plane-eth0                                         application   bpfmanLoaded   18s
bpfapplication-sample-tracepoint-syscalls-sys-enter-kill-bpfman-deployment-control-plane-syscalls-sys-enter-kill   application   bpfmanLoaded   20s
bpfapplication-sample-uprobe-malloc-bpfman-deployment-control-plane-libc-bpfman-daemon-8ddxs-bpfman                application   bpfmanLoaded   10s
bpfapplication-sample-uprobe-malloc-bpfman-deployment-control-plane-libc-bpfman-daemon-8ddxs-bpfman-agent          application   bpfmanLoaded   13s
bpfapplication-sample-xdp-eth0-bpfman-deployment-control-plane-eth0                                                application   bpfmanLoaded   8s

2- edit app object and remove kprobe oc edit bpfapplication bpfapplication-sample

 oc get bpfprograms 
NAME                                                                                                               TYPE          STATUS         AGE
bpfapplication-sample-tc-ingress-eth0-bpfman-deployment-control-plane-eth0                                         application   bpfmanLoaded   4m30s
bpfapplication-sample-tracepoint-syscalls-sys-enter-kill-bpfman-deployment-control-plane-syscalls-sys-enter-kill   application   bpfmanLoaded   4m32s
bpfapplication-sample-uprobe-malloc-bpfman-deployment-control-plane-libc-bpfman-daemon-8ddxs-bpfman                application   bpfmanLoaded   4m22s
bpfapplication-sample-uprobe-malloc-bpfman-deployment-control-plane-libc-bpfman-daemon-8ddxs-bpfman-agent          application   bpfmanLoaded   4m25s
bpfapplication-sample-xdp-eth0-bpfman-deployment-control-plane-eth0                                                application   bpfmanLoaded   4m20s

3- add back kprobe

oc get bpfprograms 
NAME                                                                                                               TYPE          STATUS         AGE
bpfapplication-sample-kprobe-try-to-wake-up-bpfman-deployment-control-plane-try-to-wake-up                         application   bpfmanLoaded   13s
bpfapplication-sample-tc-ingress-eth0-bpfman-deployment-control-plane-eth0                                         application   bpfmanLoaded   6m52s
bpfapplication-sample-tracepoint-syscalls-sys-enter-kill-bpfman-deployment-control-plane-syscalls-sys-enter-kill   application   bpfmanLoaded   6m54s
bpfapplication-sample-uprobe-malloc-bpfman-deployment-control-plane-libc-bpfman-daemon-8ddxs-bpfman                application   bpfmanLoaded   6m44s
bpfapplication-sample-uprobe-malloc-bpfman-deployment-control-plane-libc-bpfman-daemon-8ddxs-bpfman-agent          application   bpfmanLoaded   6m47s
bpfapplication-sample-xdp-eth0-bpfman-deployment-control-plane-eth0                                                application   bpfmanLoaded   6m42s

@msherif1234 msherif1234 requested a review from anfredette July 3, 2024 17:29
Copy link

codecov bot commented Jul 3, 2024

Codecov Report

Attention: Patch coverage is 7.01754% with 53 lines in your changes missing coverage. Please review.

Project coverage is 26.92%. Comparing base (4a4309b) to head (b3c925c).
Report is 3 commits behind head on main.

Files Patch % Lines
controllers/bpfman-agent/common.go 0.00% 28 Missing ⚠️
controllers/bpfman-agent/application-program.go 13.79% 25 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #38      +/-   ##
==========================================
- Coverage   27.08%   26.92%   -0.17%     
==========================================
  Files          81       81              
  Lines        6844     6897      +53     
==========================================
+ Hits         1854     1857       +3     
- Misses       4806     4856      +50     
  Partials      184      184              
Flag Coverage Δ
unittests 26.92% <7.01%> (-0.17%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@anfredette anfredette left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this! It looks pretty good, but I have a few comments.

@@ -74,6 +74,7 @@ func (r *BpfApplicationReconciler) Reconcile(ctx context.Context, req ctrl.Reque
}

for i, a := range appPrograms.Items {
var appProgramMap = make(map[string][]client.Object)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we just need to know whether the app program exists, and don't actually need the object, you can make this map[string]bool and just set the entry to true.

@@ -633,6 +633,31 @@ func (r *ReconcilerCommon) handleProgDelete(
return internal.Unchanged, nil
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// unloadAndDeletePrograms unloads and deletes BbpPrograms when the owning
// *Program or BpfApplication is not being deleted itself, but something
// has change such that the BpfPrograms are no longer needed.

Suggested change

@@ -633,6 +633,31 @@ func (r *ReconcilerCommon) handleProgDelete(
return internal.Unchanged, nil
}

func (r *ReconcilerCommon) unloadAndDeleteApplicationProgramsList(ctx context.Context, bpfDeletedPrograms *bpfmaniov1alpha1.BpfProgramList) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func (r *ReconcilerCommon) unloadAndDeleteApplicationProgramsList(ctx context.Context, bpfDeletedPrograms *bpfmaniov1alpha1.BpfProgramList) error {
func (r *ReconcilerCommon) unloadAndDeleteBpfPrograms(ctx context.Context, bpfProgramList *bpfmaniov1alpha1.BpfProgramList) error {

This can also be used by handleProgCreateOrUpdate() to delete the extra BpfPrograms

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"bpfDeletedPrograms" doesn't seem right because they aren't deleted yet.

return err
}

r.removeFinalizer(ctx, &bpfProgram, internal.BpfApplicationControllerFinalizer)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's inefficient, but the way the current controller is implemented, every time we make a change to a BpfProgram object, we exit. For example, from handleProgDelete:

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

r.Logger.Info("Deleting bpfProgram", "Name", bpfProgram.Name, "Owner", bpfProgram.GetName())
if err := r.Delete(ctx, &bpfProgram, &opts); err != nil {
return fmt.Errorf("failed to delete bpfProgram object: %v", err)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would return here too on success.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some ideas about changing that behavior, but I think we should keep it as is. The reason is that as soon as you make a change, the manager calls Reconcile() again, and if we don't stop, we end up with a Reconcile storm. That's the theory anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so u wanted to delete one program at a time that is why the return ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what ends up happening, but I'd like to look at changing that behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah this behavior isn't great I watched app sample configs with 6 hooks takes ~30s to complete

@msherif1234 msherif1234 requested a review from anfredette July 3, 2024 19:41
@msherif1234 msherif1234 force-pushed the bfpapp-delete branch 2 times, most recently from 38e21e8 to 2b538e2 Compare July 3, 2024 20:03
Copy link
Contributor

@anfredette anfredette left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mergify mergify bot merged commit 2a8ce1b into bpfman:main Jul 8, 2024
12 checks passed
anfredette added a commit to anfredette/bpfman-operator that referenced this pull request Jul 8, 2024
Signed-off-by: Andre Fredette <[email protected]>
anfredette added a commit to anfredette/bpfman-operator that referenced this pull request Jul 8, 2024
Signed-off-by: Andre Fredette <[email protected]>
msherif1234 added a commit to msherif1234/bpfman-operator that referenced this pull request Oct 30, 2024
…84197785d29f23b4

[Snyk] Security upgrade golang from 1.6 to 1.23.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support deleting programs from a BpfApplication object
2 participants