forked from cilium/tetragon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
284 lines (236 loc) · 10.2 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
GO ?= go
INSTALL = $(QUIET)install
BINDIR ?= /usr/local/bin
CONTAINER_ENGINE ?= docker
DOCKER_IMAGE_TAG ?= latest
LOCAL_CLANG ?= 0
LOCAL_CLANG_FORMAT ?= 0
FORMAT_FIND_FLAGS ?= -name '*.c' -o -name '*.h' -not -path 'bpf/include/vmlinux.h' -not -path 'bpf/include/api.h' -not -path 'bpf/libbpf/*'
NOOPT ?= 0
CLANG_IMAGE = quay.io/cilium/clang:ca424d14eb4326ffc65fccd8049d8a7bfdd06607@sha256:be37c932add0b5f22edd72da3af4ccc4df6dbd54e6e99424fa5190bafc10e55f
TESTER_PROGS_DIR = "contrib/tester-progs"
# Extra flags to pass to test binary
EXTRA_TESTFLAGS ?=
VERSION ?= $(shell git describe --tags --always)
GO_GCFLAGS ?= ""
GO_LDFLAGS="-X 'github.com/cilium/tetragon/pkg/version.Version=$(VERSION)'"
GO_IMAGE_LDFLAGS="-X 'github.com/cilium/tetragon/pkg/version.Version=$(VERSION)' -linkmode external -extldflags -static"
GO_OPERATOR_IMAGE_LDFLAGS="-X 'github.com/cilium/tetragon/pkg/version.Version=$(VERSION)' -s -w"
GOLANGCILINT_WANT_VERSION = 1.45.2
GOLANGCILINT_VERSION = $(shell golangci-lint version 2>/dev/null)
.PHONY: all
all: tetragon-bpf tetragon tetra tetragon-alignchecker test-compile tester-progs protoc-gen-go-tetragon tetragon-bench
-include Makefile.docker
-include Makefile.cli
.PHONY: help
help:
@echo 'Installation:'
@echo ' install - install tetragon agent and tetra as standalone binaries'
@echo 'Compilation:'
@echo ' tetragon - compile the Tetragon agent'
@echo ' tetragon-operator - compile the Tetragon operator'
@echo ' tetra - compile the Tetragon gRPC client'
@echo ' tetragon-bpf - compile bpf programs (use LOCAL_CLANG=0 to compile in a Docker build env)'
@echo ' test-compile - compile unit tests'
@echo ' tester-progs - compile helper programs for unit testing'
@echo ' compile-commands - generate a compile_commands.json with bear for bpf programs'
@echo ' cli-release - compile tetra CLI release binaries'
@echo 'Container images:'
@echo ' image - build the Tetragon agent container image'
@echo ' image-operator - build the Tetragon operator container image'
@echo 'Generated files:'
@echo ' codegen - generate code based on .proto files'
@echo ' generate - generate kubebuilder files'
@echo 'Linting and chores:'
@echo ' vendor - tidy and vendor Go modules'
@echo ' clang-format - run code formatter on BPF code'
@echo ' go-format - run code formatter on Go code'
@echo ' format - convenience alias for clang-format and go-format'
# Generate compile-commands.json using bear
.PHONY: compile-commands
compile-commands:
$(MAKE) -C ./bpf clean
bear -- $(MAKE) -C ./bpf
.PHONY: tetragon-bpf tetragon-bpf-local tetragon-bpf-container
ifeq (1,$(LOCAL_CLANG))
tetragon-bpf: tetragon-bpf-local
else
tetragon-bpf: tetragon-bpf-container
endif
ifeq (1,$(NOOPT))
GO_GCFLAGS = "all=-N -l"
endif
tetragon-bpf-local:
$(MAKE) -C ./bpf
tetragon-bpf-container:
$(CONTAINER_ENGINE) rm tetragon-clang || true
$(CONTAINER_ENGINE) run -v $(CURDIR):/tetragon:Z -u $$(id -u) --name tetragon-clang $(CLANG_IMAGE) $(MAKE) -C /tetragon/bpf
$(CONTAINER_ENGINE) rm tetragon-clang
.PHONY: verify
verify: tetragon-bpf
sudo contrib/verify/verify.sh bpf/objs
.PHONY: tetragon tetra tetragon-operator tetragon-alignchecker tetragon-bench
tetragon:
$(GO) build -gcflags=$(GO_GCFLAGS) -ldflags=$(GO_LDFLAGS) -mod=vendor ./cmd/tetragon/
tetra:
$(GO) build -gcflags=$(GO_GCFLAGS) -ldflags=$(GO_LDFLAGS) -mod=vendor ./cmd/tetra/
tetragon-bench:
$(GO) build -gcflags=$(GO_GCFLAGS) -ldflags=$(GO_LDFLAGS) -mod=vendor ./cmd/tetragon-bench/
tetragon-operator:
$(GO) build -gcflags=$(GO_GCFLAGS) -ldflags=$(GO_LDFLAGS) -mod=vendor -o $@ ./operator
tetragon-alignchecker:
$(GO) build -gcflags=$(GO_GCFLAGS) -ldflags=$(GO_LDFLAGS) -mod=vendor -o $@ ./tools/alignchecker/
.PHONY: ksyms
ksyms:
$(GO) build ./cmd/ksyms/
.PHONY: tetragon-image tetragon-operator-image
tetragon-image:
GOOS=linux GOARCH=amd64 $(GO) build -tags netgo -mod=vendor -ldflags=$(GO_IMAGE_LDFLAGS) ./cmd/tetragon/
GOOS=linux GOARCH=amd64 $(GO) build -tags netgo -mod=vendor -ldflags=$(GO_IMAGE_LDFLAGS) ./cmd/tetra/
tetragon-operator-image:
CGO_ENABLED=0 $(GO) build -ldflags=$(GO_OPERATOR_IMAGE_LDFLAGS) -mod=vendor -o tetragon-operator ./operator
.PHONY: install
install:
groupadd -f hubble
$(INSTALL) -m 0755 -d $(DESTDIR)$(BINDIR)
$(INSTALL) -m 0755 ./tetragon $(DESTDIR)$(BINDIR)
.PHONY: vendor
vendor:
$(MAKE) -C ./api vendor
$(MAKE) -C ./pkg/k8s vendor
$(GO) mod tidy -compat=1.17
$(GO) mod vendor
$(GO) mod verify
.PHONY: clean
clean: cli-clean
$(MAKE) -C ./bpf clean
rm -f go-tests/*.test ./ksyms ./tetragon ./tetragon-operator ./tetra ./tetragon-alignchecker
rm -f contrib/sigkill-tester/sigkill-tester contrib/namespace-tester/test_ns contrib/capabilities-tester/test_caps
$(MAKE) -C $(TESTER_PROGS_DIR) clean
.PHONY: test
test:
$(GO) test -p 1 -parallel 1 $(GOFLAGS) -gcflags=$(GO_GCFLAGS) -timeout 20m -failfast -cover ./pkg/... ${EXTRA_TESTFLAGS}
# Agent image to use for end-to-end tests
E2E_AGENT ?= "cilium/tetragon:$(DOCKER_IMAGE_TAG)"
# Operator image to use for end-to-end tests
E2E_OPERATOR ?= "cilium/tetragon-operator:$(DOCKER_IMAGE_TAG)"
# BTF file to use in the E2E test. Set to nothing to use system BTF.
E2E_BTF ?= ""
# Actual flags to use for BTF file in e2e test. Use E2E_BTF instead.
ifneq ($(E2E_BTF), "")
E2E_BTF_FLAGS ?= "-tetragon.btf=$(shell readlink -f $(E2E_BTF))"
else
E2E_BTF_FLAGS = ""
endif
# Build image and operator images locally before running test. Set to 0 to disable.
E2E_BUILD_IMAGES ?= 1
# Run an e2e-test
.PHONY: e2e-test
ifneq ($(E2E_BUILD_IMAGES), 0)
e2e-test: image image-operator
else
e2e-test:
endif
$(GO) test -p 1 -parallel 1 $(GOFLAGS) -gcflags=$(GO_GCFLAGS) -timeout 20m -failfast -cover ./tests/e2e/tests/... ${EXTRA_TESTFLAGS} -fail-fast -tetragon.helm.set tetragon.image.override="$(E2E_AGENT)" -tetragon.helm.set tetragonOperator.image.override="$(E2E_OPERATOR)" -tetragon.helm.url="" -tetragon.helm.chart="$(realpath ./install/kubernetes)" $(E2E_BTF_FLAGS)
TEST_COMPILE ?= ./...
.PHONY: test-compile
test-compile:
mkdir -p go-tests
for pkg in $$($(GO) list "$(TEST_COMPILE)"); do \
localpkg=$$(echo $$pkg | sed -e 's:github.com/cilium/tetragon/::'); \
localtestfile=$$(echo $$localpkg | sed -e 's:/:.:g'); \
numtests=$$(ls -l ./$$localpkg/*_test.go 2> /dev/null | wc -l); \
if [ $$numtests -le 0 ]; then \
continue; \
fi; \
echo -c ./$$localpkg -o go-tests/$$localtestfile; \
done | xargs -P $$(nproc) -L 1 $(GO) test -gcflags=$(GO_GCFLAGS)
.PHONY: check-copyright update-copyright
check-copyright:
for dir in $(COPYRIGHT_DIRS); do \
contrib/copyright-headers check $$dir; \
done
update-copyright:
for dir in $(COPYRIGHT_DIRS); do \
contrib/copyright-headers update $$dir; \
done
.PHONY: lint
lint:
golint -set_exit_status $$(go list ./...)
.PHONY: image image-operator image-test image-codegen
image:
$(CONTAINER_ENGINE) build -t "cilium/tetragon:${DOCKER_IMAGE_TAG}" --build-arg TETRAGON_VERSION=$(VERSION) .
$(QUIET)echo "Push like this when ready:"
$(QUIET)echo "${CONTAINER_ENGINE} push cilium/tetragon:$(DOCKER_IMAGE_TAG)"
image-operator:
$(CONTAINER_ENGINE) build -f operator.Dockerfile -t "cilium/tetragon-operator:${DOCKER_IMAGE_TAG}" .
$(QUIET)echo "Push like this when ready:"
$(QUIET)echo "${CONTAINER_ENGINE} push cilium/tetragon-operator:$(DOCKER_IMAGE_TAG)"
image-test: image-clang
$(CONTAINER_ENGINE) build -f Dockerfile.test -t "cilium/tetragon-test:${DOCKER_IMAGE_TAG}" .
$(QUIET)echo "Push like this when ready:"
$(QUIET)echo "${CONTAINER_ENGINE} push cilium/tetragon-test:$(DOCKER_IMAGE_TAG)"
image-codegen:
$(CONTAINER_ENGINE) build -f Dockerfile.codegen -t "cilium/tetragon-codegen:${DOCKER_IMAGE_TAG}" .
$(QUIET)echo "Push like this when ready:"
$(QUIET)echo "${CONTAINER_ENGINE} push cilium/tetragon-codegen:$(DOCKER_IMAGE_TAG)"
.PHONY: image-clang
image-clang:
$(CONTAINER_ENGINE) build -f Dockerfile.clang --build-arg VERSION=1:14.0.0-1ubuntu1 -t "cilium/clang:${DOCKER_IMAGE_TAG}" .
$(QUIET)echo "Push like this when ready:"
$(QUIET)echo "${CONTAINER_ENGINE} push cilium/clang:$(DOCKER_IMAGE_TAG)"
image-clang-arm:
# to compile bpf programs for arm, put 'docker.io/cilium/clang.arm:latest' to CLANG_IMAGE
$(CONTAINER_ENGINE) build -f Dockerfile.clang.arm -t "cilium/clang.arm:${DOCKER_IMAGE_TAG}" .
fetch-testdata:
wget -nc -P testdata/btf 'https://github.com/cilium/tetragon-testdata/raw/main/btf/vmlinux-5.4.104+'
.PHONY: generate codegen protoc-gen-go-tetragon
generate:
# Need to call vendor twice here, once before and once after generate, the reason
# being we need to grab changes first plus pull in whatever gets generated here.
$(MAKE) vendor
$(MAKE) -C pkg/k8s/
$(MAKE) vendor
codegen: image-codegen
# Need to call vendor twice here, once before and once after codegen the reason
# being we need to grab changes first plus pull in whatever gets generated here.
$(MAKE) vendor
$(MAKE) -C api
$(MAKE) vendor
protoc-gen-go-tetragon:
$(GO) build -gcflags=$(GO_GCFLAGS) -ldflags=$(GO_LDFLAGS) -mod=vendor -o bin/$@ ./cmd/protoc-gen-go-tetragon/
.PHONY: check
ifneq (,$(findstring $(GOLANGCILINT_WANT_VERSION),$(GOLANGCILINT_VERSION)))
check:
golangci-lint run
else
check:
$(CONTAINER_ENGINE) build -t golangci-lint:tetragon . -f Dockerfile.golangci-lint
$(CONTAINER_ENGINE) run --rm -v `pwd`:/app:Z -w /app golangci-lint:tetragon golangci-lint run
endif
.PHONY: clang-format
ifeq (1,$(LOCAL_CLANG_FORMAT))
clang-format:
find bpf $(FORMAT_FIND_FLAGS) | xargs -n 1000 clang-format -i -style=file
else
clang-format:
$(CONTAINER_ENGINE) build -f Dockerfile.clang-format -t "cilium/clang-format:${DOCKER_IMAGE_TAG}" .
find bpf $(FORMAT_FIND_FLAGS) | xargs -n 1000 \
$(CONTAINER_ENGINE) run -v $(shell realpath .):/tetragon "cilium/clang-format:${DOCKER_IMAGE_TAG}" -i -style=file
endif
.PHONY: go-format
go-format:
find . -name '*.go' -not -path './vendor/*' -not -path './api/vendor/*' -not -path './pkg/k8s/vendor/*' | xargs gofmt -w
.PHONY: format
format: go-format clang-format
# generate cscope for bpf files
cscope:
find bpf -name "*.[chxsS]" -print > cscope.files
cscope -b -q -k
.PHONY: cscope
tester-progs:
$(MAKE) -C $(TESTER_PROGS_DIR)
.PHONY: tester-progs
.PHONY: version
version:
@echo $(VERSION)