Skip to content

Commit

Permalink
bpfd-client: get the xskmap info from bpfd
Browse files Browse the repository at this point in the history
Signed-off-by: Maryam Tahhan <[email protected]>
  • Loading branch information
maryamtahhan committed Aug 15, 2023
1 parent f872f8d commit 5878644
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
43 changes: 21 additions & 22 deletions internal/bpfd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,21 @@ func (b *BpfdClient) GetBPFProgs() (*bpfdiov1alpha1.BpfProgramList, error) {
return bpfProgramList, nil
}

func (b *BpfdClient) SubmitXdpProg(iface, node, pm string) error {
func (b *BpfdClient) SubmitXdpProg(iface, node, pm string) (error, string) {

Check failure on line 94 in internal/bpfd/client.go

View workflow job for this annotation

GitHub Actions / go-static-tools

error should be returned as the last argument (ST1008)
var (
name = node + "-" + pm + "-" + iface
//sectionName = "pass"
sectionName = "xsk_def_prog"
//image = "quay.io/astoycos/xdp_pass:latest"
image = "quay.io/mtahhan/xsk_def_xdp_prog" //TODO make this configurable
// sectionName = "xdp"
//image = "quay.io/mtahhan/xsk_def_prog:latest"
name = node + "-" + pm + "-" + iface
sectionName = "stats"
image = "quay.io/bpfd-bytecode/go-xdp-counter"
// sectionName = "xsk_def_prog" //TODO make this configurable
// image = "quay.io/mtahhan/xsk_def_xdp_prog" //TODO make this configurable

)
// Create an example XdpProgram resource

// Create an XdpProgram resource
xdpProgram := &bpfdiov1alpha1.XdpProgram{
ObjectMeta: metav1.ObjectMeta{
Name: name,
// Namespace: "bpfd",
// Namespace: "bpfd", //TODO decide on namespace
Labels: map[string]string{"afxdp.io/xdpprog": name},
},
Spec: bpfdiov1alpha1.XdpProgramSpec{
Expand All @@ -131,38 +131,37 @@ func (b *BpfdClient) SubmitXdpProg(iface, node, pm string) error {
}

// Submit the XdpProgram resource to the API
result, err := b.xdpProgramsClient.Create(context.TODO(), xdpProgram, metav1.CreateOptions{})
_, err := b.xdpProgramsClient.Create(context.TODO(), xdpProgram, metav1.CreateOptions{})
if err != nil {
return errors.Wrapf(err, "Failed to create XdpProgram resource: %v", err)
return errors.Wrapf(err, "Failed to create XdpProgram resource: %v", err), ""
}

logging.Infof("Created XdpProgram resource:\n%v\n", result)

time.Sleep(time.Second)
err = b.checkProgStatus(name)
if err != nil {
return errors.Wrapf(err, "Failed to create XdpProgram resource: %v", err)
return errors.Wrapf(err, "Failed to create XdpProgram resource: %v", err), ""
}

bpfProgramList, err := b.GetBPFProgs()
if err != nil {
return errors.Wrapf(err, "Failed to get bpf prog resources: %v", err)
return errors.Wrapf(err, "Failed to get bpf prog resources: %v", err), ""
}

// Try to get the map(s) info for the bpf program
var xskmap string

// Try to get the xspmap path from the bpf program resource
if bpfProgramList != nil {
bpfProgName := node + "-" + pm + "-" + iface + "-" + node
for _, bpfProgram := range bpfProgramList.Items {
logging.Infof("bpfProgram.ObjectMeta.Name: %s", bpfProgram.ObjectMeta.Name)
if bpfProgram.ObjectMeta.Name == bpfProgName {
logging.Infof("Found the BPF prog %s \n", bpfProgram.ObjectMeta.Name)
for _, maps := range bpfProgram.Spec.Programs {
logging.Infof("MAPS: %v", maps)
if len(maps) == 0 {
logging.Infof("NO MAPS") //TODO log/return an error.
logging.Errorf("NO MAPS FOUND for %s", bpfProgName)
return errors.New("Failed to find a map for the loaded bpf program"), ""
} else {
for _, mapName := range maps {
logging.Infof("map: %v", mapName)
xskmap = mapName
}
}
}
Expand All @@ -171,7 +170,7 @@ func (b *BpfdClient) SubmitXdpProg(iface, node, pm string) error {
}
}

return nil
return nil, xskmap
}

// Delete XdpProgram
Expand Down
9 changes: 8 additions & 1 deletion internal/deviceplugin/poolManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,19 @@ func (pm *PoolManager) Allocate(ctx context.Context,

if pm.BpfdClientEnable {

err := pm.BpfdClient.SubmitXdpProg(device.Name(), pm.Node, pm.DevicePrefix)
err, xskmap := pm.BpfdClient.SubmitXdpProg(device.Name(), pm.Node, pm.DevicePrefix)
if err != nil {
logging.Errorf("Error SubmitXdpProg to bpfd %v", err)
return &response, err
}

logging.Debugf("mapping %s to %s", xskmap, constants.Bpf.BpfMapPodPath)
cresp.Mounts = append(cresp.Mounts, &pluginapi.Mount{
HostPath: xskmap,
ContainerPath: constants.Bpf.BpfMapPodPath,
ReadOnly: false,
})

}

if pm.EthtoolFilters != nil {
Expand Down

0 comments on commit 5878644

Please sign in to comment.