Skip to content

Commit

Permalink
maint: Detect BTF support and disable for local dev (#61)
Browse files Browse the repository at this point in the history
## Which problem is this PR solving?
Updates our generate makefile target to detect if the builder supports
BTF and if not disables. This means we can remove the mac-* targets and
Dockerfile.mac file.

Also includes a small update to the generated go files to remove the old
`+build` directives after running `docker-generate`.

## Short description of the changes
- Update Makefile to detect if BTF is support, if not sets
`BPF_NO_PRESERVE_ACCESS_INDEX` env var used to generate go files from
probe
- Remove mac specific Makefile targets
- Remove Dockerfile.mac file

## How to verify that this has the expected result
Can build and run the agent locally by using `docker-build`.
  • Loading branch information
MikeGoldsmith committed Aug 11, 2023
1 parent b4a5bf4 commit f3e2429
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 34 deletions.
2 changes: 0 additions & 2 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ For example, run it after changing the `tcp_event` struct in `tcp_probe.c`.

When building with `make docker-build`, the generated files are included in the build but not updated locally.

To run a locally-built image in Kubernetes on Docker Desktop, run `make mac-docker-build`.

## To pull a published image from ghcr

Docker images are found in [`ghcr.io/honeycombio/ebpf-agent:latest`](https://github.com/honeycombio/honeycomb-ebpf-agent/pkgs/container/ebpf-agent).
Expand Down
12 changes: 0 additions & 12 deletions Dockerfile.mac

This file was deleted.

25 changes: 7 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ REPODIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
# Build the list of header directories to compile the bpf program
BPF_HEADERS += -I${REPODIR}/bpf/headers

# Disable BTF if the kernel doesn't support it (eg local dev on Docker Desktop)
# needed until BTF is enabled for Docker Desktop
# see https://github.com/docker/for-mac/issues/6800
ifeq (,$(wildcard /sys/kernel/btf/vmlinux))
BPF_HEADERS += -DBPF_NO_PRESERVE_ACCESS_INDEX
endif

IMG_NAME ?= hny/ebpf-agent
IMG_TAG ?= local

Expand All @@ -31,24 +38,6 @@ update-headers:
cd bpf/headers && ./update.sh
@echo "*** Also update bpf_tracing.h file! ***"

### Local Mac Build for Kubernetes on Docker Desktop

# needed until BTF is enabled for Docker Desktop
# see https://github.com/docker/for-mac/issues/6800

.PHONY: mac-generate
mac-generate: export CFLAGS := $(BPF_HEADERS) -DBPF_NO_PRESERVE_ACCESS_INDEX
mac-generate:
go generate ./...

.PHONY: mac-build
mac-build: mac-generate
CGO_ENABLED=0 GOOS=linux go build -o hny-ebpf-agent main.go

.PHONY: mac-docker-build
mac-docker-build:
docker build --tag $(IMG_NAME):$(IMG_TAG) -f Dockerfile.mac .

### Testing targets

# deploy ebpf agent daemonset to already-running cluster with env vars from .env file
Expand Down
1 change: 0 additions & 1 deletion bpf/probes/bpf_bpfel_arm64.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion bpf/probes/bpf_bpfel_x86.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f3e2429

Please sign in to comment.