diff --git a/controllers/bpfman-agent/application-program.go b/controllers/bpfman-agent/application-program.go index 9a3ca4661..9691d29a8 100644 --- a/controllers/bpfman-agent/application-program.go +++ b/controllers/bpfman-agent/application-program.go @@ -67,10 +67,10 @@ func (r *BpfApplicationReconciler) Reconcile(ctx context.Context, req ctrl.Reque var err error var complete bool - namePrefix := func( + buildProgramName := func( app bpfmaniov1alpha1.BpfApplication, prog bpfmaniov1alpha1.BpfApplicationProgram) string { - return app.Name + "-" + strings.ToLower(string(prog.Type)) + "-" + return app.Name + "-" + strings.ToLower(string(prog.Type)) } for i, a := range appPrograms.Items { @@ -78,10 +78,11 @@ func (r *BpfApplicationReconciler) Reconcile(ctx context.Context, req ctrl.Reque for j, p := range a.Spec.Programs { switch p.Type { case bpfmaniov1alpha1.ProgTypeFentry: + appProgramId := fmt.Sprintf("%s-%s", strings.ToLower(string(p.Type)), sanitize(p.Fentry.FunctionName)) fentryProgram := bpfmaniov1alpha1.FentryProgram{ ObjectMeta: metav1.ObjectMeta{ - Name: namePrefix(a, p) + sanitize(p.Fentry.FunctionName), - }, + Name: buildProgramName(a, p), + Labels: map[string]string{internal.AppProgramId: appProgramId}}, Spec: bpfmaniov1alpha1.FentryProgramSpec{ FentryProgramInfo: *p.Fentry, BpfAppCommon: a.Spec.BpfAppCommon, @@ -94,15 +95,16 @@ func (r *BpfApplicationReconciler) Reconcile(ctx context.Context, req ctrl.Reque } rec.appOwner = &a fentryObjects := []client.Object{&fentryProgram} - appProgramMap[fentryProgram.Name] = true + appProgramMap[appProgramId] = true // Reconcile FentryProgram. complete, res, err = r.reconcileCommon(ctx, rec, fentryObjects) case bpfmaniov1alpha1.ProgTypeFexit: + appProgramId := fmt.Sprintf("%s-%s", strings.ToLower(string(p.Type)), sanitize(p.Fexit.FunctionName)) fexitProgram := bpfmaniov1alpha1.FexitProgram{ ObjectMeta: metav1.ObjectMeta{ - Name: namePrefix(a, p) + sanitize(p.Fexit.FunctionName), - }, + Name: buildProgramName(a, p), + Labels: map[string]string{internal.AppProgramId: appProgramId}}, Spec: bpfmaniov1alpha1.FexitProgramSpec{ FexitProgramInfo: *p.Fexit, BpfAppCommon: a.Spec.BpfAppCommon, @@ -115,16 +117,17 @@ func (r *BpfApplicationReconciler) Reconcile(ctx context.Context, req ctrl.Reque } rec.appOwner = &a fexitObjects := []client.Object{&fexitProgram} - appProgramMap[fexitProgram.Name] = true + appProgramMap[appProgramId] = true // Reconcile FexitProgram. complete, res, err = r.reconcileCommon(ctx, rec, fexitObjects) case bpfmaniov1alpha1.ProgTypeKprobe, bpfmaniov1alpha1.ProgTypeKretprobe: + appProgramId := fmt.Sprintf("%s-%s", strings.ToLower(string(p.Type)), sanitize(p.Kprobe.FunctionName)) kprobeProgram := bpfmaniov1alpha1.KprobeProgram{ ObjectMeta: metav1.ObjectMeta{ - Name: namePrefix(a, p) + sanitize(p.Kprobe.FunctionName), - }, + Name: buildProgramName(a, p), + Labels: map[string]string{internal.AppProgramId: appProgramId}}, Spec: bpfmaniov1alpha1.KprobeProgramSpec{ KprobeProgramInfo: *p.Kprobe, BpfAppCommon: a.Spec.BpfAppCommon, @@ -137,16 +140,17 @@ func (r *BpfApplicationReconciler) Reconcile(ctx context.Context, req ctrl.Reque } rec.appOwner = &a kprobeObjects := []client.Object{&kprobeProgram} - appProgramMap[kprobeProgram.Name] = true + appProgramMap[appProgramId] = true // Reconcile KprobeProgram or KpretprobeProgram. complete, res, err = r.reconcileCommon(ctx, rec, kprobeObjects) case bpfmaniov1alpha1.ProgTypeUprobe, bpfmaniov1alpha1.ProgTypeUretprobe: + appProgramId := fmt.Sprintf("%s-%s", strings.ToLower(string(p.Type)), sanitize(p.Uprobe.FunctionName)) uprobeProgram := bpfmaniov1alpha1.UprobeProgram{ ObjectMeta: metav1.ObjectMeta{ - Name: namePrefix(a, p) + sanitize(p.Uprobe.FunctionName), - }, + Name: buildProgramName(a, p), + Labels: map[string]string{internal.AppProgramId: appProgramId}}, Spec: bpfmaniov1alpha1.UprobeProgramSpec{ UprobeProgramInfo: *p.Uprobe, BpfAppCommon: a.Spec.BpfAppCommon, @@ -159,15 +163,16 @@ func (r *BpfApplicationReconciler) Reconcile(ctx context.Context, req ctrl.Reque } rec.appOwner = &a uprobeObjects := []client.Object{&uprobeProgram} - appProgramMap[uprobeProgram.Name] = true + appProgramMap[appProgramId] = true // Reconcile UprobeProgram or UpretprobeProgram. complete, res, err = r.reconcileCommon(ctx, rec, uprobeObjects) case bpfmaniov1alpha1.ProgTypeTracepoint: + appProgramId := fmt.Sprintf("%s-%s", strings.ToLower(string(p.Type)), sanitize(p.Tracepoint.Names[0])) tracepointProgram := bpfmaniov1alpha1.TracepointProgram{ ObjectMeta: metav1.ObjectMeta{ - Name: namePrefix(a, p) + sanitize(p.Tracepoint.Names[0]), - }, + Name: buildProgramName(a, p), + Labels: map[string]string{internal.AppProgramId: appProgramId}}, Spec: bpfmaniov1alpha1.TracepointProgramSpec{ TracepointProgramInfo: *p.Tracepoint, BpfAppCommon: a.Spec.BpfAppCommon, @@ -180,7 +185,7 @@ func (r *BpfApplicationReconciler) Reconcile(ctx context.Context, req ctrl.Reque } rec.appOwner = &a tracepointObjects := []client.Object{&tracepointProgram} - appProgramMap[tracepointProgram.Name] = true + appProgramMap[appProgramId] = true // Reconcile TracepointProgram. complete, res, err = r.reconcileCommon(ctx, rec, tracepointObjects) @@ -192,10 +197,11 @@ func (r *BpfApplicationReconciler) Reconcile(ctx context.Context, req ctrl.Reque "app program name", a.Name, "program index", j) continue } + appProgramId := fmt.Sprintf("%s-%s-%s", strings.ToLower(string(p.Type)), p.TC.Direction, interfaces[0]) tcProgram := bpfmaniov1alpha1.TcProgram{ ObjectMeta: metav1.ObjectMeta{ - Name: namePrefix(a, p) + p.TC.Direction + "-" + interfaces[0], - }, + Name: buildProgramName(a, p), + Labels: map[string]string{internal.AppProgramId: appProgramId}}, Spec: bpfmaniov1alpha1.TcProgramSpec{ TcProgramInfo: *p.TC, BpfAppCommon: a.Spec.BpfAppCommon, @@ -208,7 +214,7 @@ func (r *BpfApplicationReconciler) Reconcile(ctx context.Context, req ctrl.Reque } rec.appOwner = &a tcObjects := []client.Object{&tcProgram} - appProgramMap[tcProgram.Name] = true + appProgramMap[appProgramId] = true // Reconcile TcProgram. complete, res, err = r.reconcileCommon(ctx, rec, tcObjects) @@ -219,10 +225,11 @@ func (r *BpfApplicationReconciler) Reconcile(ctx context.Context, req ctrl.Reque "app program name", a.Name, "program index", j) continue } + appProgramId := fmt.Sprintf("%s-%s", strings.ToLower(string(p.Type)), interfaces[0]) xdpProgram := bpfmaniov1alpha1.XdpProgram{ ObjectMeta: metav1.ObjectMeta{ - Name: namePrefix(a, p) + interfaces[0], - }, + Name: buildProgramName(a, p), + Labels: map[string]string{internal.AppProgramId: appProgramId}}, Spec: bpfmaniov1alpha1.XdpProgramSpec{ XdpProgramInfo: *p.XDP, BpfAppCommon: a.Spec.BpfAppCommon, @@ -235,7 +242,7 @@ func (r *BpfApplicationReconciler) Reconcile(ctx context.Context, req ctrl.Reque } rec.appOwner = &a xdpObjects := []client.Object{&xdpProgram} - appProgramMap[xdpProgram.Name] = true + appProgramMap[appProgramId] = true // Reconcile XdpProgram. complete, res, err = r.reconcileCommon(ctx, rec, xdpObjects) @@ -260,15 +267,15 @@ func (r *BpfApplicationReconciler) Reconcile(ctx context.Context, req ctrl.Reque bpfPrograms := &bpfmaniov1alpha1.BpfProgramList{} bpfDeletedPrograms := &bpfmaniov1alpha1.BpfProgramList{} // find programs that need to be deleted and delete them - opts := []client.ListOption{client.MatchingLabels{internal.BpfProgramOwnerLabel: a.Name}} + opts := []client.ListOption{client.MatchingLabels{internal.BpfProgramOwner: a.Name}} if err := r.List(ctx, bpfPrograms, opts...); err != nil { ctxLogger.Error(err, "failed to get freshPrograms for full reconcile") return ctrl.Result{}, err } for _, bpfProgram := range bpfPrograms.Items { - progName := bpfProgram.Labels[internal.BpfParentProgram] - if _, ok := appProgramMap[progName]; !ok { - ctxLogger.Info("Deleting BpfProgram", "BpfProgram", progName) + id := bpfProgram.Labels[internal.AppProgramId] + if _, ok := appProgramMap[id]; !ok { + ctxLogger.Info("Deleting BpfProgram", "AppProgramId", id, "BpfProgram", bpfProgram.Name) bpfDeletedPrograms.Items = append(bpfDeletedPrograms.Items, bpfProgram) } } diff --git a/controllers/bpfman-agent/application-program_test.go b/controllers/bpfman-agent/application-program_test.go index 9b5f1d211..14e176d37 100644 --- a/controllers/bpfman-agent/application-program_test.go +++ b/controllers/bpfman-agent/application-program_test.go @@ -36,13 +36,15 @@ func TestBpfApplicationControllerCreate(t *testing.T) { // fentry program config bpfFentryFunctionName = "fentry_test" fentryFunctionName = "do_unlinkat" - fentryBpfProgName = fmt.Sprintf("%s-%s-%s-%s-%s", name, "fentry", "do-unlinkat", fakeNode.Name, "do-unlinkat") + fentryAppProgramId = fmt.Sprintf("%s-%s", "fentry", sanitize(fentryFunctionName)) + fentryAttachPoint = sanitize(fentryFunctionName) fentryBpfProg = &bpfmaniov1alpha1.BpfProgram{} fentryFakeUID = "ef71d42c-aa21-48e8-a697-82391d801a81" // kprobe program config bpfKprobeFunctionName = "kprobe_test" kprobeFunctionName = "try_to_wake_up" - kprobeBpfProgName = fmt.Sprintf("%s-%s-%s-%s-%s", name, "kprobe", "try-to-wake-up", fakeNode.Name, "try-to-wake-up") + kprobeAppProgramId = fmt.Sprintf("%s-%s", "kprobe", sanitize(kprobeFunctionName)) + kprobeAttachPoint = sanitize(kprobeFunctionName) kprobeBpfProg = &bpfmaniov1alpha1.BpfProgram{} kprobeFakeUID = "ef71d42c-aa21-48e8-a697-82391d801a82" kprobeOffset = 0 @@ -133,14 +135,14 @@ func TestBpfApplicationControllerCreate(t *testing.T) { } // Check the BpfProgram Object was created successfully - err = cl.Get(ctx, types.NamespacedName{Name: fentryBpfProgName, Namespace: metav1.NamespaceAll}, fentryBpfProg) + err = rc.getBpfProgram(ctx, name, fentryAppProgramId, fentryAttachPoint, fentryBpfProg) require.NoError(t, err) require.NotEmpty(t, fentryBpfProg) // Finalizer is written require.Equal(t, internal.BpfApplicationControllerFinalizer, fentryBpfProg.Finalizers[0]) // owningConfig Label was correctly set - require.Equal(t, name, fentryBpfProg.Labels[internal.BpfProgramOwnerLabel]) + require.Equal(t, name, fentryBpfProg.Labels[internal.BpfProgramOwner]) // node Label was correctly set require.Equal(t, fakeNode.Name, fentryBpfProg.Labels[internal.K8sHostLabel]) // fentry function Annotation was correctly set @@ -184,7 +186,7 @@ func TestBpfApplicationControllerCreate(t *testing.T) { } // Check that the bpfProgram's programs was correctly updated - err = cl.Get(ctx, types.NamespacedName{Name: fentryBpfProgName, Namespace: metav1.NamespaceAll}, fentryBpfProg) + err = rc.getBpfProgram(ctx, name, fentryAppProgramId, fentryAttachPoint, fentryBpfProg) require.NoError(t, err) // prog ID should already have been set @@ -208,7 +210,7 @@ func TestBpfApplicationControllerCreate(t *testing.T) { require.False(t, res.Requeue) // Check that the bpfProgram's status was correctly updated - err = cl.Get(ctx, types.NamespacedName{Name: fentryBpfProgName, Namespace: metav1.NamespaceAll}, fentryBpfProg) + err = rc.getBpfProgram(ctx, name, fentryAppProgramId, fentryAttachPoint, fentryBpfProg) require.NoError(t, err) require.Equal(t, string(bpfmaniov1alpha1.BpfProgCondLoaded), fentryBpfProg.Status.Conditions[0].Type) @@ -220,14 +222,14 @@ func TestBpfApplicationControllerCreate(t *testing.T) { t.Fatalf("reconcile: (%v)", err) } - err = cl.Get(ctx, types.NamespacedName{Name: kprobeBpfProgName, Namespace: metav1.NamespaceAll}, kprobeBpfProg) + err = rc.getBpfProgram(ctx, name, kprobeAppProgramId, kprobeAttachPoint, kprobeBpfProg) require.NoError(t, err) require.NotEmpty(t, kprobeBpfProg) // Finalizer is written require.Equal(t, internal.BpfApplicationControllerFinalizer, kprobeBpfProg.Finalizers[0]) // owningConfig Label was correctly set - require.Equal(t, name, kprobeBpfProg.Labels[internal.BpfProgramOwnerLabel]) + require.Equal(t, name, kprobeBpfProg.Labels[internal.BpfProgramOwner]) // node Label was correctly set require.Equal(t, fakeNode.Name, kprobeBpfProg.Labels[internal.K8sHostLabel]) // fentry function Annotation was correctly set @@ -273,7 +275,7 @@ func TestBpfApplicationControllerCreate(t *testing.T) { } // Check that the bpfProgram's programs was correctly updated - err = cl.Get(ctx, types.NamespacedName{Name: kprobeBpfProgName, Namespace: metav1.NamespaceAll}, kprobeBpfProg) + err = rc.getBpfProgram(ctx, name, kprobeAppProgramId, kprobeAttachPoint, kprobeBpfProg) require.NoError(t, err) // prog ID should already have been set @@ -297,9 +299,8 @@ func TestBpfApplicationControllerCreate(t *testing.T) { require.False(t, res.Requeue) // Check that the bpfProgram's status was correctly updated - err = cl.Get(ctx, types.NamespacedName{Name: kprobeBpfProgName, Namespace: metav1.NamespaceAll}, kprobeBpfProg) + err = rc.getBpfProgram(ctx, name, kprobeAppProgramId, kprobeAttachPoint, kprobeBpfProg) require.NoError(t, err) require.Equal(t, string(bpfmaniov1alpha1.BpfProgCondLoaded), kprobeBpfProg.Status.Conditions[0].Type) - } diff --git a/controllers/bpfman-agent/common.go b/controllers/bpfman-agent/common.go index e9dc12f51..443ba9055 100644 --- a/controllers/bpfman-agent/common.go +++ b/controllers/bpfman-agent/common.go @@ -43,6 +43,7 @@ import ( "github.com/bpfman/bpfman-operator/internal" gobpfman "github.com/bpfman/bpfman/clients/gobpfman/v1" "github.com/go-logr/logr" + "github.com/google/uuid" "google.golang.org/grpc" ) @@ -126,6 +127,9 @@ type bpfmanReconciler interface { getNodeSelector() *metav1.LabelSelector // getBpfGlobalData returns the Bpf program global variables. getBpfGlobalData() map[string][]byte + // getAppProgramId() returns the program qualifier for the current + // program. If there is no qualifier, it should return an empty string. + getAppProgramId() string } // reconcileCommon is the common reconciler loop called by each bpfman @@ -500,17 +504,22 @@ func (r *ReconcilerCommon) updateStatus(ctx context.Context, bpfProgram *bpfmani return true } +type bpfProgKey struct { + appProgId string + attachPoint string +} + func (r *ReconcilerCommon) getExistingBpfPrograms(ctx context.Context, - rec bpfmanReconciler) (map[string]bpfmaniov1alpha1.BpfProgram, error) { + rec bpfmanReconciler) (map[bpfProgKey]bpfmaniov1alpha1.BpfProgram, error) { bpfProgramList := &bpfmaniov1alpha1.BpfProgramList{} // Only list bpfPrograms for this *Program and the controller's node opts := []client.ListOption{ client.MatchingLabels{ - internal.BpfProgramOwnerLabel: rec.getOwner().GetName(), - internal.BpfParentProgram: rec.getName(), - internal.K8sHostLabel: r.NodeName, + internal.BpfProgramOwner: rec.getOwner().GetName(), + internal.AppProgramId: rec.getAppProgramId(), + internal.K8sHostLabel: r.NodeName, }, } @@ -519,32 +528,47 @@ func (r *ReconcilerCommon) getExistingBpfPrograms(ctx context.Context, return nil, err } - existingBpfPrograms := map[string]bpfmaniov1alpha1.BpfProgram{} + existingBpfPrograms := map[bpfProgKey]bpfmaniov1alpha1.BpfProgram{} for _, bpfProg := range bpfProgramList.Items { - existingBpfPrograms[bpfProg.GetName()] = bpfProg + key := bpfProgKey{ + appProgId: bpfProg.GetLabels()[internal.AppProgramId], + attachPoint: bpfProg.GetAnnotations()[internal.BpfProgramAttachPoint], + } + existingBpfPrograms[key] = bpfProg } return existingBpfPrograms, nil } +func generateUniqueName(baseName string) string { + uuid := uuid.New().String() + return fmt.Sprintf("%s-%s", baseName, uuid[:8]) +} + // createBpfProgram moves some shared logic for building bpfProgram objects // into a central location. func (r *ReconcilerCommon) createBpfProgram( - bpfProgramName string, + attachPoint string, rec bpfmanReconciler, annotations map[string]string) (*bpfmaniov1alpha1.BpfProgram, error) { - r.Logger.V(1).Info("createBpfProgram()", "Name", bpfProgramName, + r.Logger.V(1).Info("createBpfProgram()", "Name", attachPoint, "Owner", rec.getOwner().GetName(), "OwnerType", rec.getRecType(), "Name", rec.getName()) + if annotations == nil { + annotations = make(map[string]string) + } + annotations[internal.BpfProgramAttachPoint] = attachPoint + bpfProg := &bpfmaniov1alpha1.BpfProgram{ ObjectMeta: metav1.ObjectMeta{ - Name: bpfProgramName, + Name: generateUniqueName(rec.getName()), Finalizers: []string{rec.getFinalizer()}, Labels: map[string]string{ - internal.BpfProgramOwnerLabel: rec.getOwner().GetName(), - internal.BpfParentProgram: rec.getName(), - internal.K8sHostLabel: r.NodeName}, + internal.BpfProgramOwner: rec.getOwner().GetName(), + internal.AppProgramId: rec.getAppProgramId(), + internal.K8sHostLabel: r.NodeName, + }, Annotations: annotations, }, Spec: bpfmaniov1alpha1.BpfProgramSpec{ @@ -581,7 +605,7 @@ func (r *ReconcilerCommon) createBpfProgram( func (r *ReconcilerCommon) handleProgDelete( ctx context.Context, rec bpfmanReconciler, - existingBpfPrograms map[string]bpfmaniov1alpha1.BpfProgram, + existingBpfPrograms map[bpfProgKey]bpfmaniov1alpha1.BpfProgram, loadedBpfPrograms map[string]*gobpfman.ListResponse_ListResult, isNodeSelected bool, isBeingDeleted bool, @@ -679,7 +703,7 @@ func (r *ReconcilerCommon) unLoadAndDeleteBpfProgramsList(ctx context.Context, b func (r *ReconcilerCommon) handleProgCreateOrUpdate( ctx context.Context, rec bpfmanReconciler, - existingBpfPrograms map[string]bpfmaniov1alpha1.BpfProgram, + existingBpfPrograms map[bpfProgKey]bpfmaniov1alpha1.BpfProgram, expectedBpfPrograms *bpfmaniov1alpha1.BpfProgramList, loadedBpfPrograms map[string]*gobpfman.ListResponse_ListResult, isNodeSelected bool, @@ -692,11 +716,15 @@ func (r *ReconcilerCommon) handleProgCreateOrUpdate( // even if the node isn't selected for _, expectedBpfProgram := range expectedBpfPrograms.Items { r.Logger.V(1).Info("Creating or Updating", "Name", expectedBpfProgram.Name) - existingBpfProgram, exists := existingBpfPrograms[expectedBpfProgram.Name] + key := bpfProgKey{ + appProgId: expectedBpfProgram.GetLabels()[internal.AppProgramId], + attachPoint: expectedBpfProgram.GetAnnotations()[internal.BpfProgramAttachPoint], + } + existingBpfProgram, exists := existingBpfPrograms[key] if exists { // Remove the bpfProgram from the existingPrograms map so we know // not to delete it below. - delete(existingBpfPrograms, expectedBpfProgram.Name) + delete(existingBpfPrograms, key) } else { // Create a new bpfProgram Object for this program. opts := client.CreateOptions{} @@ -938,3 +966,48 @@ func sanitize(name string) string { name = strings.Replace(strings.Replace(name, "/", "-", -1), "_", "-", -1) return strings.ToLower(name) } + +func appProgramId(labels map[string]string) string { + id, ok := labels[internal.AppProgramId] + if ok { + return id + } + return "" +} + +// getBpfProgram returns a BpfProgram object in the bpfProgram parameter based +// on the given owner, appProgId, and attachPoint. If the BpfProgram is not +// found, an error is returned. +func (r *ReconcilerCommon) getBpfProgram( + ctx context.Context, + owner string, + appProgId string, + attachPoint string, + bpfProgram *bpfmaniov1alpha1.BpfProgram) error { + + bpfProgramList := &bpfmaniov1alpha1.BpfProgramList{} + + // Only list bpfPrograms for this *Program and the controller's node + opts := []client.ListOption{ + client.MatchingLabels{ + internal.BpfProgramOwner: owner, + internal.AppProgramId: appProgId, + internal.K8sHostLabel: r.NodeName, + }, + } + + err := r.List(ctx, bpfProgramList, opts...) + if err != nil { + return err + } + + for _, bpfProg := range bpfProgramList.Items { + if appProgId == bpfProg.GetLabels()[internal.AppProgramId] && + attachPoint == bpfProg.GetAnnotations()[internal.BpfProgramAttachPoint] { + *bpfProgram = bpfProg + return nil + } + } + + return fmt.Errorf("bpfProgram not found") +} diff --git a/controllers/bpfman-agent/fentry-program.go b/controllers/bpfman-agent/fentry-program.go index 69a8d70ee..680693e1e 100644 --- a/controllers/bpfman-agent/fentry-program.go +++ b/controllers/bpfman-agent/fentry-program.go @@ -85,6 +85,10 @@ func (r *FentryProgramReconciler) getBpfGlobalData() map[string][]byte { return r.currentFentryProgram.Spec.GlobalData } +func (r *FentryProgramReconciler) getAppProgramId() string { + return appProgramId(r.currentFentryProgram.GetLabels()) +} + func (r *FentryProgramReconciler) setCurrentProgram(program client.Object) error { var ok bool @@ -123,14 +127,13 @@ func (r *FentryProgramReconciler) SetupWithManager(mgr ctrl.Manager) error { func (r *FentryProgramReconciler) getExpectedBpfPrograms(ctx context.Context) (*bpfmaniov1alpha1.BpfProgramList, error) { progs := &bpfmaniov1alpha1.BpfProgramList{} - sanatizedFentry := sanitize(r.currentFentryProgram.Spec.FunctionName) - bpfProgramName := fmt.Sprintf("%s-%s-%s", r.currentFentryProgram.Name, r.NodeName, sanatizedFentry) + attachPoint := sanitize(r.currentFentryProgram.Spec.FunctionName) annotations := map[string]string{internal.FentryProgramFunction: r.currentFentryProgram.Spec.FunctionName} - prog, err := r.createBpfProgram(bpfProgramName, r, annotations) + prog, err := r.createBpfProgram(attachPoint, r, annotations) if err != nil { - return nil, fmt.Errorf("failed to create BpfProgram %s: %v", bpfProgramName, err) + return nil, fmt.Errorf("failed to create BpfProgram %s: %v", attachPoint, err) } progs.Items = append(progs.Items, *prog) diff --git a/controllers/bpfman-agent/fentry-program_test.go b/controllers/bpfman-agent/fentry-program_test.go index 7e9925ed2..1a5384162 100644 --- a/controllers/bpfman-agent/fentry-program_test.go +++ b/controllers/bpfman-agent/fentry-program_test.go @@ -18,7 +18,6 @@ package bpfmanagent import ( "context" - "fmt" "testing" "github.com/google/go-cmp/cmp" @@ -52,7 +51,8 @@ func TestFentryProgramControllerCreate(t *testing.T) { functionName = "do_unlinkat" fakeNode = testutils.NewNode("fake-control-plane") ctx = context.TODO() - bpfProgName = fmt.Sprintf("%s-%s-%s", name, fakeNode.Name, "do-unlinkat") + appProgramId = "" + attachPoint = sanitize(functionName) bpfProg = &bpfmaniov1alpha1.BpfProgram{} fakeUID = "ef71d42c-aa21-48e8-a697-82391d801a81" ) @@ -121,14 +121,14 @@ func TestFentryProgramControllerCreate(t *testing.T) { } // Check the BpfProgram Object was created successfully - err = cl.Get(ctx, types.NamespacedName{Name: bpfProgName, Namespace: metav1.NamespaceAll}, bpfProg) + err = rc.getBpfProgram(ctx, name, appProgramId, attachPoint, bpfProg) require.NoError(t, err) require.NotEmpty(t, bpfProg) // Finalizer is written require.Equal(t, r.getFinalizer(), bpfProg.Finalizers[0]) // owningConfig Label was correctly set - require.Equal(t, bpfProg.Labels[internal.BpfProgramOwnerLabel], name) + require.Equal(t, bpfProg.Labels[internal.BpfProgramOwner], name) // node Label was correctly set require.Equal(t, bpfProg.Labels[internal.K8sHostLabel], fakeNode.Name) // fentry function Annotation was correctly set @@ -170,7 +170,7 @@ func TestFentryProgramControllerCreate(t *testing.T) { } // Check that the bpfProgram's programs was correctly updated - err = cl.Get(ctx, types.NamespacedName{Name: bpfProgName, Namespace: metav1.NamespaceAll}, bpfProg) + err = rc.getBpfProgram(ctx, name, appProgramId, attachPoint, bpfProg) require.NoError(t, err) // prog ID should already have been set @@ -194,7 +194,7 @@ func TestFentryProgramControllerCreate(t *testing.T) { require.False(t, res.Requeue) // Check that the bpfProgram's status was correctly updated - err = cl.Get(ctx, types.NamespacedName{Name: bpfProgName, Namespace: metav1.NamespaceAll}, bpfProg) + err = rc.getBpfProgram(ctx, name, appProgramId, attachPoint, bpfProg) require.NoError(t, err) require.Equal(t, string(bpfmaniov1alpha1.BpfProgCondLoaded), bpfProg.Status.Conditions[0].Type) diff --git a/controllers/bpfman-agent/fexit-program.go b/controllers/bpfman-agent/fexit-program.go index 6741a71bb..b52171e80 100644 --- a/controllers/bpfman-agent/fexit-program.go +++ b/controllers/bpfman-agent/fexit-program.go @@ -85,6 +85,10 @@ func (r *FexitProgramReconciler) getBpfGlobalData() map[string][]byte { return r.currentFexitProgram.Spec.GlobalData } +func (r *FexitProgramReconciler) getAppProgramId() string { + return appProgramId(r.currentFexitProgram.GetLabels()) +} + func (r *FexitProgramReconciler) setCurrentProgram(program client.Object) error { var ok bool @@ -123,14 +127,13 @@ func (r *FexitProgramReconciler) SetupWithManager(mgr ctrl.Manager) error { func (r *FexitProgramReconciler) getExpectedBpfPrograms(ctx context.Context) (*bpfmaniov1alpha1.BpfProgramList, error) { progs := &bpfmaniov1alpha1.BpfProgramList{} - sanatizedFexit := sanitize(r.currentFexitProgram.Spec.FunctionName) - bpfProgramName := fmt.Sprintf("%s-%s-%s", r.currentFexitProgram.Name, r.NodeName, sanatizedFexit) + attachPoint := sanitize(r.currentFexitProgram.Spec.FunctionName) annotations := map[string]string{internal.FexitProgramFunction: r.currentFexitProgram.Spec.FunctionName} - prog, err := r.createBpfProgram(bpfProgramName, r, annotations) + prog, err := r.createBpfProgram(attachPoint, r, annotations) if err != nil { - return nil, fmt.Errorf("failed to create BpfProgram %s: %v", bpfProgramName, err) + return nil, fmt.Errorf("failed to create BpfProgram %s: %v", attachPoint, err) } progs.Items = append(progs.Items, *prog) diff --git a/controllers/bpfman-agent/fexit-program_test.go b/controllers/bpfman-agent/fexit-program_test.go index 51dfb615e..a424384d5 100644 --- a/controllers/bpfman-agent/fexit-program_test.go +++ b/controllers/bpfman-agent/fexit-program_test.go @@ -18,7 +18,6 @@ package bpfmanagent import ( "context" - "fmt" "testing" "github.com/google/go-cmp/cmp" @@ -52,7 +51,8 @@ func TestFexitProgramControllerCreate(t *testing.T) { functionName = "do_unlinkat" fakeNode = testutils.NewNode("fake-control-plane") ctx = context.TODO() - bpfProgName = fmt.Sprintf("%s-%s-%s", name, fakeNode.Name, "do-unlinkat") + appProgramId = "" + attachPoint = sanitize(functionName) bpfProg = &bpfmaniov1alpha1.BpfProgram{} fakeUID = "ef71d42c-aa21-48e8-a697-82391d801a81" ) @@ -121,14 +121,14 @@ func TestFexitProgramControllerCreate(t *testing.T) { } // Check the BpfProgram Object was created successfully - err = cl.Get(ctx, types.NamespacedName{Name: bpfProgName, Namespace: metav1.NamespaceAll}, bpfProg) + err = rc.getBpfProgram(ctx, name, appProgramId, attachPoint, bpfProg) require.NoError(t, err) require.NotEmpty(t, bpfProg) // Finalizer is written require.Equal(t, r.getFinalizer(), bpfProg.Finalizers[0]) // owningConfig Label was correctly set - require.Equal(t, bpfProg.Labels[internal.BpfProgramOwnerLabel], name) + require.Equal(t, bpfProg.Labels[internal.BpfProgramOwner], name) // node Label was correctly set require.Equal(t, bpfProg.Labels[internal.K8sHostLabel], fakeNode.Name) // fexit function Annotation was correctly set @@ -170,7 +170,7 @@ func TestFexitProgramControllerCreate(t *testing.T) { } // Check that the bpfProgram's programs was correctly updated - err = cl.Get(ctx, types.NamespacedName{Name: bpfProgName, Namespace: metav1.NamespaceAll}, bpfProg) + err = rc.getBpfProgram(ctx, name, appProgramId, attachPoint, bpfProg) require.NoError(t, err) // prog ID should already have been set @@ -194,7 +194,7 @@ func TestFexitProgramControllerCreate(t *testing.T) { require.False(t, res.Requeue) // Check that the bpfProgram's status was correctly updated - err = cl.Get(ctx, types.NamespacedName{Name: bpfProgName, Namespace: metav1.NamespaceAll}, bpfProg) + err = rc.getBpfProgram(ctx, name, appProgramId, attachPoint, bpfProg) require.NoError(t, err) require.Equal(t, string(bpfmaniov1alpha1.BpfProgCondLoaded), bpfProg.Status.Conditions[0].Type) diff --git a/controllers/bpfman-agent/kprobe-program.go b/controllers/bpfman-agent/kprobe-program.go index eaeb684fb..89e912b70 100644 --- a/controllers/bpfman-agent/kprobe-program.go +++ b/controllers/bpfman-agent/kprobe-program.go @@ -85,6 +85,10 @@ func (r *KprobeProgramReconciler) getBpfGlobalData() map[string][]byte { return r.currentKprobeProgram.Spec.GlobalData } +func (r *KprobeProgramReconciler) getAppProgramId() string { + return appProgramId(r.currentKprobeProgram.GetLabels()) +} + func (r *KprobeProgramReconciler) setCurrentProgram(program client.Object) error { var ok bool @@ -123,14 +127,13 @@ func (r *KprobeProgramReconciler) SetupWithManager(mgr ctrl.Manager) error { func (r *KprobeProgramReconciler) getExpectedBpfPrograms(ctx context.Context) (*bpfmaniov1alpha1.BpfProgramList, error) { progs := &bpfmaniov1alpha1.BpfProgramList{} - sanatizedKprobe := sanitize(r.currentKprobeProgram.Spec.FunctionName) - bpfProgramName := fmt.Sprintf("%s-%s-%s", r.currentKprobeProgram.Name, r.NodeName, sanatizedKprobe) + attachPoint := sanitize(r.currentKprobeProgram.Spec.FunctionName) annotations := map[string]string{internal.KprobeProgramFunction: r.currentKprobeProgram.Spec.FunctionName} - prog, err := r.createBpfProgram(bpfProgramName, r, annotations) + prog, err := r.createBpfProgram(attachPoint, r, annotations) if err != nil { - return nil, fmt.Errorf("failed to create BpfProgram %s: %v", bpfProgramName, err) + return nil, fmt.Errorf("failed to create BpfProgram %s: %v", attachPoint, err) } progs.Items = append(progs.Items, *prog) diff --git a/controllers/bpfman-agent/kprobe-program_test.go b/controllers/bpfman-agent/kprobe-program_test.go index 2a315610e..96f1a3744 100644 --- a/controllers/bpfman-agent/kprobe-program_test.go +++ b/controllers/bpfman-agent/kprobe-program_test.go @@ -18,7 +18,6 @@ package bpfmanagent import ( "context" - "fmt" "testing" "github.com/google/go-cmp/cmp" @@ -55,7 +54,8 @@ func TestKprobeProgramControllerCreate(t *testing.T) { kprobecontainerpid int32 = 0 fakeNode = testutils.NewNode("fake-control-plane") ctx = context.TODO() - bpfProgName = fmt.Sprintf("%s-%s-%s", name, fakeNode.Name, "try-to-wake-up") + appProgramId = "" + attachPoint = sanitize(functionName) bpfProg = &bpfmaniov1alpha1.BpfProgram{} fakeUID = "ef71d42c-aa21-48e8-a697-82391d801a81" ) @@ -126,14 +126,14 @@ func TestKprobeProgramControllerCreate(t *testing.T) { } // Check the BpfProgram Object was created successfully - err = cl.Get(ctx, types.NamespacedName{Name: bpfProgName, Namespace: metav1.NamespaceAll}, bpfProg) + err = rc.getBpfProgram(ctx, name, appProgramId, attachPoint, bpfProg) require.NoError(t, err) require.NotEmpty(t, bpfProg) // Finalizer is written require.Equal(t, r.getFinalizer(), bpfProg.Finalizers[0]) // owningConfig Label was correctly set - require.Equal(t, bpfProg.Labels[internal.BpfProgramOwnerLabel], name) + require.Equal(t, bpfProg.Labels[internal.BpfProgramOwner], name) // node Label was correctly set require.Equal(t, bpfProg.Labels[internal.K8sHostLabel], fakeNode.Name) // kprobe function Annotation was correctly set @@ -178,7 +178,7 @@ func TestKprobeProgramControllerCreate(t *testing.T) { } // Check that the bpfProgram's programs was correctly updated - err = cl.Get(ctx, types.NamespacedName{Name: bpfProgName, Namespace: metav1.NamespaceAll}, bpfProg) + err = rc.getBpfProgram(ctx, name, appProgramId, attachPoint, bpfProg) require.NoError(t, err) // prog ID should already have been set @@ -202,7 +202,7 @@ func TestKprobeProgramControllerCreate(t *testing.T) { require.False(t, res.Requeue) // Check that the bpfProgram's status was correctly updated - err = cl.Get(ctx, types.NamespacedName{Name: bpfProgName, Namespace: metav1.NamespaceAll}, bpfProg) + err = rc.getBpfProgram(ctx, name, appProgramId, attachPoint, bpfProg) require.NoError(t, err) require.Equal(t, string(bpfmaniov1alpha1.BpfProgCondLoaded), bpfProg.Status.Conditions[0].Type) diff --git a/controllers/bpfman-agent/tc-program.go b/controllers/bpfman-agent/tc-program.go index f1499937e..03515dd05 100644 --- a/controllers/bpfman-agent/tc-program.go +++ b/controllers/bpfman-agent/tc-program.go @@ -87,6 +87,10 @@ func (r *TcProgramReconciler) getBpfGlobalData() map[string][]byte { return r.currentTcProgram.Spec.GlobalData } +func (r *TcProgramReconciler) getAppProgramId() string { + return appProgramId(r.currentTcProgram.GetLabels()) +} + func (r *TcProgramReconciler) setCurrentProgram(program client.Object) error { var err error var ok bool @@ -169,12 +173,12 @@ func (r *TcProgramReconciler) SetupWithManager(mgr ctrl.Manager) error { func (r *TcProgramReconciler) getExpectedBpfPrograms(ctx context.Context) (*bpfmaniov1alpha1.BpfProgramList, error) { progs := &bpfmaniov1alpha1.BpfProgramList{} for _, iface := range r.interfaces { - bpfProgramName := fmt.Sprintf("%s-%s-%s", r.currentTcProgram.Name, r.NodeName, iface) + attachPoint := iface + "-" + r.currentTcProgram.Spec.Direction annotations := map[string]string{internal.TcProgramInterface: iface} - prog, err := r.createBpfProgram(bpfProgramName, r, annotations) + prog, err := r.createBpfProgram(attachPoint, r, annotations) if err != nil { - return nil, fmt.Errorf("failed to create BpfProgram %s: %v", bpfProgramName, err) + return nil, fmt.Errorf("failed to create BpfProgram %s: %v", attachPoint, err) } progs.Items = append(progs.Items, *prog) diff --git a/controllers/bpfman-agent/tc-program_test.go b/controllers/bpfman-agent/tc-program_test.go index 7a75fb261..a1b711843 100644 --- a/controllers/bpfman-agent/tc-program_test.go +++ b/controllers/bpfman-agent/tc-program_test.go @@ -18,7 +18,6 @@ package bpfmanagent import ( "context" - "fmt" "testing" "github.com/google/go-cmp/cmp" @@ -54,7 +53,8 @@ func TestTcProgramControllerCreate(t *testing.T) { fakeNode = testutils.NewNode("fake-control-plane") fakeInt = "eth0" ctx = context.TODO() - bpfProgName = fmt.Sprintf("%s-%s-%s", name, fakeNode.Name, fakeInt) + appProgramId = "" + attachPoint = fakeInt + "-" + direction bpfProg = &bpfmaniov1alpha1.BpfProgram{} fakeUID = "ef71d42c-aa21-48e8-a697-82391d801a81" ) @@ -131,12 +131,12 @@ func TestTcProgramControllerCreate(t *testing.T) { } // Check the BpfProgram Object was created successfully - err = cl.Get(ctx, types.NamespacedName{Name: bpfProgName, Namespace: metav1.NamespaceAll}, bpfProg) + err = rc.getBpfProgram(ctx, name, appProgramId, attachPoint, bpfProg) require.NoError(t, err) require.NotEmpty(t, bpfProg) // owningConfig Label was correctly set - require.Equal(t, bpfProg.Labels[internal.BpfProgramOwnerLabel], name) + require.Equal(t, bpfProg.Labels[internal.BpfProgramOwner], name) // node Label was correctly set require.Equal(t, bpfProg.Labels[internal.K8sHostLabel], fakeNode.Name) // Finalizer is written @@ -183,7 +183,7 @@ func TestTcProgramControllerCreate(t *testing.T) { } // Check that the bpfProgram's programs was correctly updated - err = cl.Get(ctx, types.NamespacedName{Name: bpfProgName, Namespace: metav1.NamespaceAll}, bpfProg) + err = rc.getBpfProgram(ctx, name, appProgramId, attachPoint, bpfProg) require.NoError(t, err) // prog ID should already have been set @@ -206,7 +206,7 @@ func TestTcProgramControllerCreate(t *testing.T) { require.False(t, res.Requeue) // Check that the bpfProgram's status was correctly updated - err = cl.Get(ctx, types.NamespacedName{Name: bpfProgName, Namespace: metav1.NamespaceAll}, bpfProg) + err = rc.getBpfProgram(ctx, name, appProgramId, attachPoint, bpfProg) require.NoError(t, err) require.Equal(t, string(bpfmaniov1alpha1.BpfProgCondLoaded), bpfProg.Status.Conditions[0].Type) @@ -222,8 +222,10 @@ func TestTcProgramControllerCreateMultiIntf(t *testing.T) { fakeNode = testutils.NewNode("fake-control-plane") fakeInts = []string{"eth0", "eth1"} ctx = context.TODO() - bpfProgName0 = fmt.Sprintf("%s-%s-%s", name, fakeNode.Name, fakeInts[0]) - bpfProgName1 = fmt.Sprintf("%s-%s-%s", name, fakeNode.Name, fakeInts[1]) + appProgramId0 = "" + attachPoint0 = fakeInts[0] + "-" + direction + appProgramId1 = "" + attachPoint1 = fakeInts[1] + "-" + direction bpfProgEth0 = &bpfmaniov1alpha1.BpfProgram{} bpfProgEth1 = &bpfmaniov1alpha1.BpfProgram{} fakeUID0 = "ef71d42c-aa21-48e8-a697-82391d801a80" @@ -301,12 +303,12 @@ func TestTcProgramControllerCreateMultiIntf(t *testing.T) { } // Check the first BpfProgram Object was created successfully - err = cl.Get(ctx, types.NamespacedName{Name: bpfProgName0, Namespace: metav1.NamespaceAll}, bpfProgEth0) + err = rc.getBpfProgram(ctx, name, appProgramId0, attachPoint0, bpfProgEth0) require.NoError(t, err) require.NotEmpty(t, bpfProgEth0) // owningConfig Label was correctly set - require.Equal(t, bpfProgEth0.Labels[internal.BpfProgramOwnerLabel], name) + require.Equal(t, bpfProgEth0.Labels[internal.BpfProgramOwner], name) // node Label was correctly set require.Equal(t, bpfProgEth0.Labels[internal.K8sHostLabel], fakeNode.Name) // Finalizer is written @@ -349,12 +351,12 @@ func TestTcProgramControllerCreateMultiIntf(t *testing.T) { require.False(t, res.Requeue) // Check the Second BpfProgram Object was created successfully - err = cl.Get(ctx, types.NamespacedName{Name: bpfProgName1, Namespace: metav1.NamespaceAll}, bpfProgEth1) + err = rc.getBpfProgram(ctx, name, appProgramId1, attachPoint1, bpfProgEth1) require.NoError(t, err) require.NotEmpty(t, bpfProgEth1) // owningConfig Label was correctly set - require.Equal(t, bpfProgEth1.Labels[internal.BpfProgramOwnerLabel], name) + require.Equal(t, bpfProgEth1.Labels[internal.BpfProgramOwner], name) // node Label was correctly set require.Equal(t, bpfProgEth1.Labels[internal.K8sHostLabel], fakeNode.Name) // Finalizer is written @@ -427,7 +429,7 @@ func TestTcProgramControllerCreateMultiIntf(t *testing.T) { } // Check that the bpfProgram's maps was correctly updated - err = cl.Get(ctx, types.NamespacedName{Name: bpfProgName0, Namespace: metav1.NamespaceAll}, bpfProgEth0) + err = rc.getBpfProgram(ctx, name, appProgramId0, attachPoint0, bpfProgEth0) require.NoError(t, err) // prog ID should already have been set @@ -435,7 +437,7 @@ func TestTcProgramControllerCreateMultiIntf(t *testing.T) { require.NoError(t, err) // Check that the bpfProgram's maps was correctly updated - err = cl.Get(ctx, types.NamespacedName{Name: bpfProgName1, Namespace: metav1.NamespaceAll}, bpfProgEth1) + err = rc.getBpfProgram(ctx, name, appProgramId1, attachPoint1, bpfProgEth1) require.NoError(t, err) // prog ID should already have been set @@ -455,11 +457,11 @@ func TestTcProgramControllerCreateMultiIntf(t *testing.T) { } // Check that the bpfProgram's maps was correctly updated - err = cl.Get(ctx, types.NamespacedName{Name: bpfProgName0, Namespace: metav1.NamespaceAll}, bpfProgEth0) + err = rc.getBpfProgram(ctx, name, appProgramId0, attachPoint0, bpfProgEth0) require.NoError(t, err) // Check that the bpfProgram's maps was correctly updated - err = cl.Get(ctx, types.NamespacedName{Name: bpfProgName1, Namespace: metav1.NamespaceAll}, bpfProgEth1) + err = rc.getBpfProgram(ctx, name, appProgramId1, attachPoint1, bpfProgEth1) require.NoError(t, err) // Third reconcile should update the bpfPrograms status to loaded @@ -472,13 +474,13 @@ func TestTcProgramControllerCreateMultiIntf(t *testing.T) { require.False(t, res.Requeue) // Check that the bpfProgram's status was correctly updated - err = cl.Get(ctx, types.NamespacedName{Name: bpfProgName0, Namespace: metav1.NamespaceAll}, bpfProgEth0) + err = rc.getBpfProgram(ctx, name, appProgramId0, attachPoint0, bpfProgEth0) require.NoError(t, err) require.Equal(t, string(bpfmaniov1alpha1.BpfProgCondLoaded), bpfProgEth0.Status.Conditions[0].Type) // Check that the bpfProgram's status was correctly updated - err = cl.Get(ctx, types.NamespacedName{Name: bpfProgName1, Namespace: metav1.NamespaceAll}, bpfProgEth1) + err = rc.getBpfProgram(ctx, name, appProgramId1, attachPoint1, bpfProgEth1) require.NoError(t, err) require.Equal(t, string(bpfmaniov1alpha1.BpfProgCondLoaded), bpfProgEth1.Status.Conditions[0].Type) diff --git a/controllers/bpfman-agent/tracepoint-program.go b/controllers/bpfman-agent/tracepoint-program.go index b7350fe2d..dfafff528 100644 --- a/controllers/bpfman-agent/tracepoint-program.go +++ b/controllers/bpfman-agent/tracepoint-program.go @@ -85,6 +85,10 @@ func (r *TracepointProgramReconciler) getBpfGlobalData() map[string][]byte { return r.currentTracepointProgram.Spec.GlobalData } +func (r *TracepointProgramReconciler) getAppProgramId() string { + return appProgramId(r.currentTracepointProgram.GetLabels()) +} + func (r *TracepointProgramReconciler) setCurrentProgram(program client.Object) error { var ok bool @@ -124,14 +128,12 @@ func (r *TracepointProgramReconciler) getExpectedBpfPrograms(ctx context.Context progs := &bpfmaniov1alpha1.BpfProgramList{} for _, tracepoint := range r.currentTracepointProgram.Spec.Names { - sanatizedTrace := sanitize(tracepoint) - bpfProgramName := fmt.Sprintf("%s-%s-%s", r.currentTracepointProgram.Name, r.NodeName, sanatizedTrace) - + attachPoint := sanitize(tracepoint) annotations := map[string]string{internal.TracepointProgramTracepoint: tracepoint} - prog, err := r.createBpfProgram(bpfProgramName, r, annotations) + prog, err := r.createBpfProgram(attachPoint, r, annotations) if err != nil { - return nil, fmt.Errorf("failed to create BpfProgram %s: %v", bpfProgramName, err) + return nil, fmt.Errorf("failed to create BpfProgram %s: %v", attachPoint, err) } progs.Items = append(progs.Items, *prog) diff --git a/controllers/bpfman-agent/tracepoint-program_test.go b/controllers/bpfman-agent/tracepoint-program_test.go index b42dfb305..3455f72a4 100644 --- a/controllers/bpfman-agent/tracepoint-program_test.go +++ b/controllers/bpfman-agent/tracepoint-program_test.go @@ -18,7 +18,6 @@ package bpfmanagent import ( "context" - "fmt" "testing" "github.com/google/go-cmp/cmp" @@ -52,7 +51,8 @@ func TestTracepointProgramControllerCreate(t *testing.T) { tracepointName = "syscalls/sys_enter_setitimer" fakeNode = testutils.NewNode("fake-control-plane") ctx = context.TODO() - bpfProgName = fmt.Sprintf("%s-%s-%s", name, fakeNode.Name, "syscalls-sys-enter-setitimer") + appProgramId = "" + attachPoint = sanitize(tracepointName) bpfProg = &bpfmaniov1alpha1.BpfProgram{} fakeUID = "ef71d42c-aa21-48e8-a697-82391d801a81" ) @@ -121,14 +121,14 @@ func TestTracepointProgramControllerCreate(t *testing.T) { } // Check the BpfProgram Object was created successfully - err = cl.Get(ctx, types.NamespacedName{Name: bpfProgName, Namespace: metav1.NamespaceAll}, bpfProg) + err = rc.getBpfProgram(ctx, name, appProgramId, attachPoint, bpfProg) require.NoError(t, err) require.NotEmpty(t, bpfProg) // Finalizer is written require.Equal(t, r.getFinalizer(), bpfProg.Finalizers[0]) // owningConfig Label was correctly set - require.Equal(t, bpfProg.Labels[internal.BpfProgramOwnerLabel], name) + require.Equal(t, bpfProg.Labels[internal.BpfProgramOwner], name) // node Label was correctly set require.Equal(t, bpfProg.Labels[internal.K8sHostLabel], fakeNode.Name) // Type is set @@ -170,7 +170,7 @@ func TestTracepointProgramControllerCreate(t *testing.T) { } // Check that the bpfProgram's programs was correctly updated - err = cl.Get(ctx, types.NamespacedName{Name: bpfProgName, Namespace: metav1.NamespaceAll}, bpfProg) + err = rc.getBpfProgram(ctx, name, appProgramId, attachPoint, bpfProg) require.NoError(t, err) // prog ID should already have been set @@ -184,7 +184,7 @@ func TestTracepointProgramControllerCreate(t *testing.T) { } // Check that the bpfProgram's programs was correctly updated - err = cl.Get(ctx, types.NamespacedName{Name: bpfProgName, Namespace: metav1.NamespaceAll}, bpfProg) + err = rc.getBpfProgram(ctx, name, appProgramId, attachPoint, bpfProg) require.NoError(t, err) // Third reconcile should update the bpfPrograms status to loaded @@ -197,7 +197,7 @@ func TestTracepointProgramControllerCreate(t *testing.T) { require.False(t, res.Requeue) // Check that the bpfProgram's status was correctly updated - err = cl.Get(ctx, types.NamespacedName{Name: bpfProgName, Namespace: metav1.NamespaceAll}, bpfProg) + err = rc.getBpfProgram(ctx, name, appProgramId, attachPoint, bpfProg) require.NoError(t, err) require.Equal(t, string(bpfmaniov1alpha1.BpfProgCondLoaded), bpfProg.Status.Conditions[0].Type) diff --git a/controllers/bpfman-agent/uprobe-program.go b/controllers/bpfman-agent/uprobe-program.go index 8db4b2b00..7e03b3fd7 100644 --- a/controllers/bpfman-agent/uprobe-program.go +++ b/controllers/bpfman-agent/uprobe-program.go @@ -86,6 +86,10 @@ func (r *UprobeProgramReconciler) getBpfGlobalData() map[string][]byte { return r.currentUprobeProgram.Spec.GlobalData } +func (r *UprobeProgramReconciler) getAppProgramId() string { + return appProgramId(r.currentUprobeProgram.GetLabels()) +} + func (r *UprobeProgramReconciler) setCurrentProgram(program client.Object) error { var ok bool @@ -156,8 +160,7 @@ func (r *UprobeProgramReconciler) getUprobeContainerInfo(ctx context.Context) (* func (r *UprobeProgramReconciler) getExpectedBpfPrograms(ctx context.Context) (*bpfmaniov1alpha1.BpfProgramList, error) { progs := &bpfmaniov1alpha1.BpfProgramList{} - sanatizedUprobe := sanitize(r.currentUprobeProgram.Spec.Target) - bpfProgramNameBase := fmt.Sprintf("%s-%s-%s", r.currentUprobeProgram.Name, r.NodeName, sanatizedUprobe) + sanatizedUprobe := sanitize(r.currentUprobeProgram.Spec.Target) + "-" + sanitize(r.currentUprobeProgram.Spec.FunctionName) if r.currentUprobeProgram.Spec.Containers != nil { @@ -175,11 +178,11 @@ func (r *UprobeProgramReconciler) getExpectedBpfPrograms(ctx context.Context) (* internal.UprobeNoContainersOnNode: "true", } - bpfProgramName := fmt.Sprintf("%s-%s", bpfProgramNameBase, "no-containers-on-node") + attachPoint := sanatizedUprobe + "-no-containers-on-node" - prog, err := r.createBpfProgram(bpfProgramName, r, annotations) + prog, err := r.createBpfProgram(attachPoint, r, annotations) if err != nil { - return nil, fmt.Errorf("failed to create BpfProgram %s: %v", bpfProgramNameBase, err) + return nil, fmt.Errorf("failed to create BpfProgram %s: %v", attachPoint, err) } progs.Items = append(progs.Items, *prog) @@ -192,11 +195,15 @@ func (r *UprobeProgramReconciler) getExpectedBpfPrograms(ctx context.Context) (* annotations := map[string]string{internal.UprobeProgramTarget: r.currentUprobeProgram.Spec.Target} annotations[internal.UprobeContainerPid] = strconv.FormatInt(container.pid, 10) - bpfProgramName := fmt.Sprintf("%s-%s-%s", bpfProgramNameBase, container.podName, container.containerName) + attachPoint := fmt.Sprintf("%s-%s-%s", + sanatizedUprobe, + container.podName, + container.containerName, + ) - prog, err := r.createBpfProgram(bpfProgramName, r, annotations) + prog, err := r.createBpfProgram(attachPoint, r, annotations) if err != nil { - return nil, fmt.Errorf("failed to create BpfProgram %s: %v", bpfProgramName, err) + return nil, fmt.Errorf("failed to create BpfProgram %s: %v", attachPoint, err) } progs.Items = append(progs.Items, *prog) @@ -205,9 +212,11 @@ func (r *UprobeProgramReconciler) getExpectedBpfPrograms(ctx context.Context) (* } else { annotations := map[string]string{internal.UprobeProgramTarget: r.currentUprobeProgram.Spec.Target} - prog, err := r.createBpfProgram(bpfProgramNameBase, r, annotations) + attachPoint := sanatizedUprobe + + prog, err := r.createBpfProgram(attachPoint, r, annotations) if err != nil { - return nil, fmt.Errorf("failed to create BpfProgram %s: %v", bpfProgramNameBase, err) + return nil, fmt.Errorf("failed to create BpfProgram %s: %v", attachPoint, err) } progs.Items = append(progs.Items, *prog) diff --git a/controllers/bpfman-agent/uprobe-program_test.go b/controllers/bpfman-agent/uprobe-program_test.go index 72461c857..fbcd48a98 100644 --- a/controllers/bpfman-agent/uprobe-program_test.go +++ b/controllers/bpfman-agent/uprobe-program_test.go @@ -18,7 +18,6 @@ package bpfmanagent import ( "context" - "fmt" "testing" "github.com/google/go-cmp/cmp" @@ -57,7 +56,8 @@ func TestUprobeProgramControllerCreate(t *testing.T) { retprobe = false fakeNode = testutils.NewNode("fake-control-plane") ctx = context.TODO() - bpfProgName = fmt.Sprintf("%s-%s-%s", name, fakeNode.Name, "libc") + appProgramId = "" + attachPoint = sanitize(target) + "-" + sanitize(functionName) bpfProg = &bpfmaniov1alpha1.BpfProgram{} fakeUID = "ef71d42c-aa21-48e8-a697-82391d801a81" ) @@ -129,14 +129,14 @@ func TestUprobeProgramControllerCreate(t *testing.T) { } // Check the BpfProgram Object was created successfully - err = cl.Get(ctx, types.NamespacedName{Name: bpfProgName, Namespace: metav1.NamespaceAll}, bpfProg) + err = rc.getBpfProgram(ctx, name, appProgramId, attachPoint, bpfProg) require.NoError(t, err) require.NotEmpty(t, bpfProg) // Finalizer is written require.Equal(t, r.getFinalizer(), bpfProg.Finalizers[0]) // owningConfig Label was correctly set - require.Equal(t, bpfProg.Labels[internal.BpfProgramOwnerLabel], name) + require.Equal(t, bpfProg.Labels[internal.BpfProgramOwner], name) // node Label was correctly set require.Equal(t, bpfProg.Labels[internal.K8sHostLabel], fakeNode.Name) // uprobe function Annotation was correctly set @@ -181,7 +181,7 @@ func TestUprobeProgramControllerCreate(t *testing.T) { } // Check that the bpfProgram's programs was correctly updated - err = cl.Get(ctx, types.NamespacedName{Name: bpfProgName, Namespace: metav1.NamespaceAll}, bpfProg) + err = rc.getBpfProgram(ctx, name, appProgramId, attachPoint, bpfProg) require.NoError(t, err) // prog ID should already have been set @@ -205,7 +205,7 @@ func TestUprobeProgramControllerCreate(t *testing.T) { require.False(t, res.Requeue) // Check that the bpfProgram's status was correctly updated - err = cl.Get(ctx, types.NamespacedName{Name: bpfProgName, Namespace: metav1.NamespaceAll}, bpfProg) + err = rc.getBpfProgram(ctx, name, appProgramId, attachPoint, bpfProg) require.NoError(t, err) require.Equal(t, string(bpfmaniov1alpha1.BpfProgCondLoaded), bpfProg.Status.Conditions[0].Type) diff --git a/controllers/bpfman-agent/xdp-program.go b/controllers/bpfman-agent/xdp-program.go index 88afccfe7..72859a4b2 100644 --- a/controllers/bpfman-agent/xdp-program.go +++ b/controllers/bpfman-agent/xdp-program.go @@ -86,6 +86,10 @@ func (r *XdpProgramReconciler) getBpfGlobalData() map[string][]byte { return r.currentXdpProgram.Spec.GlobalData } +func (r *XdpProgramReconciler) getAppProgramId() string { + return appProgramId(r.currentXdpProgram.GetLabels()) +} + func (r *XdpProgramReconciler) setCurrentProgram(program client.Object) error { var err error var ok bool @@ -155,12 +159,12 @@ func (r *XdpProgramReconciler) getExpectedBpfPrograms(ctx context.Context) (*bpf progs := &bpfmaniov1alpha1.BpfProgramList{} for _, iface := range r.interfaces { - bpfProgramName := fmt.Sprintf("%s-%s-%s", r.currentXdpProgram.Name, r.NodeName, iface) + attachPoint := iface annotations := map[string]string{internal.XdpProgramInterface: iface} - prog, err := r.createBpfProgram(bpfProgramName, r, annotations) + prog, err := r.createBpfProgram(attachPoint, r, annotations) if err != nil { - return nil, fmt.Errorf("failed to create BpfProgram %s: %v", bpfProgramName, err) + return nil, fmt.Errorf("failed to create BpfProgram %s: %v", attachPoint, err) } progs.Items = append(progs.Items, *prog) diff --git a/controllers/bpfman-agent/xdp-program_test.go b/controllers/bpfman-agent/xdp-program_test.go index b77ea53cb..922cd28e4 100644 --- a/controllers/bpfman-agent/xdp-program_test.go +++ b/controllers/bpfman-agent/xdp-program_test.go @@ -18,7 +18,6 @@ package bpfmanagent import ( "context" - "fmt" "testing" "github.com/google/go-cmp/cmp" @@ -57,8 +56,10 @@ func xdpProgramControllerCreate(t *testing.T, multiInterface bool, multiConditio fakeInt0 = "eth0" fakeInt1 = "eth1" ctx = context.TODO() - bpfProgName0 = fmt.Sprintf("%s-%s-%s", name, fakeNode.Name, fakeInt0) - bpfProgName1 = fmt.Sprintf("%s-%s-%s", name, fakeNode.Name, fakeInt1) + appProgramId0 = "" + attachPoint0 = fakeInt0 + appProgramId1 = "" + attachPoint1 = fakeInt1 bpfProgEth0 = &bpfmaniov1alpha1.BpfProgram{} bpfProgEth1 = &bpfmaniov1alpha1.BpfProgram{} fakeUID0 = "ef71d42c-aa21-48e8-a697-82391d801a80" @@ -143,12 +144,12 @@ func xdpProgramControllerCreate(t *testing.T, multiInterface bool, multiConditio } // Check the first BpfProgram Object was created successfully - err = cl.Get(ctx, types.NamespacedName{Name: bpfProgName0, Namespace: metav1.NamespaceAll}, bpfProgEth0) + err = rc.getBpfProgram(ctx, name, appProgramId0, attachPoint0, bpfProgEth0) require.NoError(t, err) require.NotEmpty(t, bpfProgEth0) // owningConfig Label was correctly set - require.Equal(t, bpfProgEth0.Labels[internal.BpfProgramOwnerLabel], name) + require.Equal(t, bpfProgEth0.Labels[internal.BpfProgramOwner], name) // node Label was correctly set require.Equal(t, bpfProgEth0.Labels[internal.K8sHostLabel], fakeNode.Name) // Finalizer is written @@ -194,7 +195,7 @@ func xdpProgramControllerCreate(t *testing.T, multiInterface bool, multiConditio } // Check that the bpfProgram's maps was correctly updated - err = cl.Get(ctx, types.NamespacedName{Name: bpfProgName0, Namespace: metav1.NamespaceAll}, bpfProgEth0) + err = rc.getBpfProgram(ctx, name, appProgramId0, attachPoint0, bpfProgEth0) require.NoError(t, err) // prog ID should already have been set @@ -234,7 +235,7 @@ func xdpProgramControllerCreate(t *testing.T, multiInterface bool, multiConditio require.False(t, res.Requeue) // Get program object - err = cl.Get(ctx, types.NamespacedName{Name: bpfProgName0, Namespace: metav1.NamespaceAll}, bpfProgEth0) + err = rc.getBpfProgram(ctx, name, appProgramId0, attachPoint0, bpfProgEth0) require.NoError(t, err) // Check that the bpfProgram's status was correctly updated @@ -254,12 +255,12 @@ func xdpProgramControllerCreate(t *testing.T, multiInterface bool, multiConditio require.False(t, res.Requeue) // Check the Second BpfProgram Object was created successfully - err = cl.Get(ctx, types.NamespacedName{Name: bpfProgName1, Namespace: metav1.NamespaceAll}, bpfProgEth1) + err = rc.getBpfProgram(ctx, name, appProgramId1, attachPoint1, bpfProgEth1) require.NoError(t, err) require.NotEmpty(t, bpfProgEth1) // owningConfig Label was correctly set - require.Equal(t, bpfProgEth1.Labels[internal.BpfProgramOwnerLabel], name) + require.Equal(t, bpfProgEth1.Labels[internal.BpfProgramOwner], name) // node Label was correctly set require.Equal(t, bpfProgEth1.Labels[internal.K8sHostLabel], fakeNode.Name) // Finalizer is written @@ -314,7 +315,7 @@ func xdpProgramControllerCreate(t *testing.T, multiInterface bool, multiConditio } // Check that the bpfProgram's maps was correctly updated - err = cl.Get(ctx, types.NamespacedName{Name: bpfProgName1, Namespace: metav1.NamespaceAll}, bpfProgEth1) + err = rc.getBpfProgram(ctx, name, appProgramId1, attachPoint1, bpfProgEth1) require.NoError(t, err) // prog ID should already have been set @@ -328,7 +329,7 @@ func xdpProgramControllerCreate(t *testing.T, multiInterface bool, multiConditio } // Get program object - err = cl.Get(ctx, types.NamespacedName{Name: bpfProgName1, Namespace: metav1.NamespaceAll}, bpfProgEth1) + err = rc.getBpfProgram(ctx, name, appProgramId1, attachPoint1, bpfProgEth1) require.NoError(t, err) // Check that the bpfProgram's status was correctly updated diff --git a/controllers/bpfman-operator/application-program_test.go b/controllers/bpfman-operator/application-program_test.go index 257b977a4..76fc0770f 100644 --- a/controllers/bpfman-operator/application-program_test.go +++ b/controllers/bpfman-operator/application-program_test.go @@ -112,7 +112,7 @@ func appProgramReconcile(t *testing.T, multiCondition bool) { Controller: &[]bool{true}[0], }, }, - Labels: map[string]string{internal.BpfProgramOwnerLabel: App.Name, internal.K8sHostLabel: fakeNode.Name}, + Labels: map[string]string{internal.BpfProgramOwner: App.Name, internal.K8sHostLabel: fakeNode.Name}, Finalizers: []string{internal.BpfApplicationControllerFinalizer}, }, Spec: bpfmaniov1alpha1.BpfProgramSpec{ diff --git a/controllers/bpfman-operator/common.go b/controllers/bpfman-operator/common.go index 2bcef68f3..69e89efa1 100644 --- a/controllers/bpfman-operator/common.go +++ b/controllers/bpfman-operator/common.go @@ -77,7 +77,7 @@ func reconcileBpfProgram(ctx context.Context, rec ProgramReconciler, prog client bpfPrograms := &bpfmaniov1alpha1.BpfProgramList{} // Only list bpfPrograms for this Program - opts := []client.ListOption{client.MatchingLabels{internal.BpfProgramOwnerLabel: progName}} + opts := []client.ListOption{client.MatchingLabels{internal.BpfProgramOwner: progName}} if err := r.List(ctx, bpfPrograms, opts...); err != nil { r.Logger.Error(err, "failed to get freshPrograms for full reconcile") @@ -97,7 +97,7 @@ func reconcileBpfProgram(ctx context.Context, rec ProgramReconciler, prog client for _, node := range nodes.Items { nodeFound := false for _, program := range bpfPrograms.Items { - bpfProgramNode := program.ObjectMeta.Labels[internal.K8sHostLabel] + bpfProgramNode := program.GetLabels()[internal.K8sHostLabel] if node.Name == bpfProgramNode { nodeFound = true break diff --git a/controllers/bpfman-operator/fentry-program_test.go b/controllers/bpfman-operator/fentry-program_test.go index a694a6ba7..1ffd18af7 100644 --- a/controllers/bpfman-operator/fentry-program_test.go +++ b/controllers/bpfman-operator/fentry-program_test.go @@ -82,7 +82,7 @@ func fentryProgramReconcile(t *testing.T, multiCondition bool) { Controller: &[]bool{true}[0], }, }, - Labels: map[string]string{internal.BpfProgramOwnerLabel: Fentry.Name, internal.K8sHostLabel: fakeNode.Name}, + Labels: map[string]string{internal.BpfProgramOwner: Fentry.Name, internal.K8sHostLabel: fakeNode.Name}, Finalizers: []string{internal.FentryProgramControllerFinalizer}, }, Spec: bpfmaniov1alpha1.BpfProgramSpec{ diff --git a/controllers/bpfman-operator/fexit-program_test.go b/controllers/bpfman-operator/fexit-program_test.go index 0eb732422..086e30d9d 100644 --- a/controllers/bpfman-operator/fexit-program_test.go +++ b/controllers/bpfman-operator/fexit-program_test.go @@ -82,7 +82,7 @@ func fexitProgramReconcile(t *testing.T, multiCondition bool) { Controller: &[]bool{true}[0], }, }, - Labels: map[string]string{internal.BpfProgramOwnerLabel: Fexit.Name, internal.K8sHostLabel: fakeNode.Name}, + Labels: map[string]string{internal.BpfProgramOwner: Fexit.Name, internal.K8sHostLabel: fakeNode.Name}, Finalizers: []string{internal.FexitProgramControllerFinalizer}, }, Spec: bpfmaniov1alpha1.BpfProgramSpec{ diff --git a/controllers/bpfman-operator/kprobe-program_test.go b/controllers/bpfman-operator/kprobe-program_test.go index 6740e829b..5216fbd77 100644 --- a/controllers/bpfman-operator/kprobe-program_test.go +++ b/controllers/bpfman-operator/kprobe-program_test.go @@ -86,7 +86,7 @@ func kprobeProgramReconcile(t *testing.T, multiCondition bool) { Controller: &[]bool{true}[0], }, }, - Labels: map[string]string{internal.BpfProgramOwnerLabel: Kprobe.Name, internal.K8sHostLabel: fakeNode.Name}, + Labels: map[string]string{internal.BpfProgramOwner: Kprobe.Name, internal.K8sHostLabel: fakeNode.Name}, Finalizers: []string{internal.KprobeProgramControllerFinalizer}, }, Spec: bpfmaniov1alpha1.BpfProgramSpec{ diff --git a/controllers/bpfman-operator/tc-program_test.go b/controllers/bpfman-operator/tc-program_test.go index 9acc04d1f..032a4d7f8 100644 --- a/controllers/bpfman-operator/tc-program_test.go +++ b/controllers/bpfman-operator/tc-program_test.go @@ -89,7 +89,7 @@ func TestTcProgramReconcile(t *testing.T) { Controller: &[]bool{true}[0], }, }, - Labels: map[string]string{internal.BpfProgramOwnerLabel: tc.Name, internal.K8sHostLabel: fakeNode.Name}, + Labels: map[string]string{internal.BpfProgramOwner: tc.Name, internal.K8sHostLabel: fakeNode.Name}, Finalizers: []string{internal.TcProgramControllerFinalizer}, }, Spec: bpfmaniov1alpha1.BpfProgramSpec{ diff --git a/controllers/bpfman-operator/tracepoint-program_test.go b/controllers/bpfman-operator/tracepoint-program_test.go index 3e9ce3a79..8cac0a367 100644 --- a/controllers/bpfman-operator/tracepoint-program_test.go +++ b/controllers/bpfman-operator/tracepoint-program_test.go @@ -79,7 +79,7 @@ func TestTracepointProgramReconcile(t *testing.T) { Controller: &[]bool{true}[0], }, }, - Labels: map[string]string{internal.BpfProgramOwnerLabel: Tracepoint.Name, internal.K8sHostLabel: fakeNode.Name}, + Labels: map[string]string{internal.BpfProgramOwner: Tracepoint.Name, internal.K8sHostLabel: fakeNode.Name}, Finalizers: []string{internal.TracepointProgramControllerFinalizer}, }, Spec: bpfmaniov1alpha1.BpfProgramSpec{ diff --git a/controllers/bpfman-operator/uprobe-program_test.go b/controllers/bpfman-operator/uprobe-program_test.go index 6d169156d..d591165fd 100644 --- a/controllers/bpfman-operator/uprobe-program_test.go +++ b/controllers/bpfman-operator/uprobe-program_test.go @@ -85,7 +85,7 @@ func TestUprobeProgramReconcile(t *testing.T) { Controller: &[]bool{true}[0], }, }, - Labels: map[string]string{internal.BpfProgramOwnerLabel: Uprobe.Name, internal.K8sHostLabel: fakeNode.Name}, + Labels: map[string]string{internal.BpfProgramOwner: Uprobe.Name, internal.K8sHostLabel: fakeNode.Name}, Finalizers: []string{internal.UprobeProgramControllerFinalizer}, }, Spec: bpfmaniov1alpha1.BpfProgramSpec{ diff --git a/controllers/bpfman-operator/xdp-program_test.go b/controllers/bpfman-operator/xdp-program_test.go index cd70b54b0..92223a008 100644 --- a/controllers/bpfman-operator/xdp-program_test.go +++ b/controllers/bpfman-operator/xdp-program_test.go @@ -85,7 +85,7 @@ func TestXdpProgramReconcile(t *testing.T) { Controller: &[]bool{true}[0], }, }, - Labels: map[string]string{internal.BpfProgramOwnerLabel: Xdp.Name, internal.K8sHostLabel: fakeNode.Name}, + Labels: map[string]string{internal.BpfProgramOwner: Xdp.Name, internal.K8sHostLabel: fakeNode.Name}, Finalizers: []string{internal.TcProgramControllerFinalizer}, }, Spec: bpfmaniov1alpha1.BpfProgramSpec{ diff --git a/internal/constants.go b/internal/constants.go index 8ddc43a06..d97cba9c1 100644 --- a/internal/constants.go +++ b/internal/constants.go @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, @@ -49,16 +49,17 @@ const ( DefaultPath = "/run/bpfman-sock/bpfman.sock" DefaultPort = 50051 DefaultEnabled = true - // BpfProgramOwnerLabel is the name of the object that owns the BpfProgram - // object. In the case of a *Program, it will be the name of the *Program - // object. In the case of a BpfApplication, it will be the name of the + // BpfProgramOwner is the name of the object that owns the BpfProgram + // object. In the case of a *Program, it will be the name of the *Program + // object. In the case of a BpfApplication, it will be the name of the // BpfApplication object. - BpfProgramOwnerLabel = "bpfman.io/ownedByProgram" - // BpfParentProgram is the name of the current program that caused the - // creation of the BpfProgram object. In the case of a *Program, it will be - // the name of the *Program object. In the case of a BpfApplication, it - // will be the name generated for the given BpfApplication program. - BpfParentProgram = "bpfman.io/parentProgram" + BpfProgramOwner = "bpfman.io/ownedByProgram" + // AppProgramId is an identifier that is used to identify individual + // programs that are part of a given BpfApplication object. *Programs have + // an AppProgramId of "". + AppProgramId = "bpfman.io/appProgramId" + // BpfProgramAttachPoint is the attach point for a given BpfProgram. + BpfProgramAttachPoint = "bpfman.io/bpfProgramAttachPoint" ) // ----------------------------------------------------------------------------- @@ -233,7 +234,7 @@ func (p ProgramType) String() string { } } -// Define a constant strings for Uprobe, Fentry and Fexit. Uprobe has the same +// Define a constant strings for Uprobe, Fentry and Fexit. Uprobe has the same // kernel ProgramType as Kprobe, and Fentry and Fexit both have the Tracing // ProgramType, so we can't use the ProgramType String() method above. const UprobeString = "uprobe" @@ -249,11 +250,11 @@ const ( // programs in it's list. Unchanged ReconcileResult = 0 // Changes were made to k8s objects that we know will trigger another - // reconcile. Calling code should stop reconciling additional programs and + // reconcile. Calling code should stop reconciling additional programs and // return immediately to avoid multiple concurrent reconcile threads. Updated ReconcileResult = 1 // A retry should be scheduled. This should only be used when "Updated" - // doesn't apply, but we want to trigger another reconcile anyway. For + // doesn't apply, but we want to trigger another reconcile anyway. For // example, there was a transient error. The calling code may continue // reconciling other programs in it's list. Requeue ReconcileResult = 2