cilium
/
Makefile
577 строк · 26.6 Кб
1# Copyright Authors of Cilium
2# SPDX-License-Identifier: Apache-2.0
3
4##@ Default
5all: precheck build postcheck ## Default make target that perform precheck -> build -> postcheck
6@echo "Build finished."
7
8##@ Build, Install and Test
9debug: export NOOPT=1 ## Builds Cilium by disabling inlining, compiler optimizations and without stripping debug symbols, useful for debugging.
10debug: export NOSTRIP=1
11debug: all
12
13include Makefile.defs
14
15SUBDIRS_CILIUM_CONTAINER := cilium-dbg daemon cilium-health bugtool tools/mount tools/sysctlfix plugins/cilium-cni
16SUBDIR_OPERATOR_CONTAINER := operator
17SUBDIR_RELAY_CONTAINER := hubble-relay
18
19ifdef LIBNETWORK_PLUGIN
20SUBDIRS_CILIUM_CONTAINER += plugins/cilium-docker
21endif
22
23# Add the ability to override variables
24-include Makefile.override
25
26# List of subdirectories used for global "make build", "make clean", etc
27SUBDIRS := $(SUBDIRS_CILIUM_CONTAINER) $(SUBDIR_OPERATOR_CONTAINER) plugins tools $(SUBDIR_RELAY_CONTAINER) bpf
28
29# Filter out any directories where the parent directory is also present, to avoid
30# building or cleaning a subdirectory twice.
31# For example: The directory "tools" is transformed into a match pattern "tools/%",
32# which is then used to filter out items such as "tools/mount" and "tools/sysctlfx"
33SUBDIRS := $(filter-out $(foreach dir,$(SUBDIRS),$(dir)/%),$(SUBDIRS))
34
35# Space-separated list of Go packages to test, equivalent to 'go test' package patterns.
36# Because is treated as a Go package pattern, the special '...' sequence is supported,
37# meaning 'all subpackages of the given package'.
38TESTPKGS ?= ./...
39
40GOTEST_BASE := -timeout 600s
41GOTEST_COVER_OPTS += -coverprofile=coverage.out
42BENCH_EVAL := "."
43BENCH ?= $(BENCH_EVAL)
44BENCHFLAGS_EVAL := -bench=$(BENCH) -run=^$ -benchtime=10s
45BENCHFLAGS ?= $(BENCHFLAGS_EVAL)
46SKIP_KVSTORES ?= "false"
47SKIP_K8S_CODE_GEN_CHECK ?= "true"
48SKIP_CUSTOMVET_CHECK ?= "false"
49
50JOB_BASE_NAME ?= cilium_test
51
52TEST_LDFLAGS=-ldflags "-X github.com/cilium/cilium/pkg/kvstore.consulDummyAddress=https://consul:8443 \
53-X github.com/cilium/cilium/pkg/kvstore.etcdDummyAddress=http://etcd:4002 \
54-X github.com/cilium/cilium/pkg/datapath.datapathSHA256=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
55
56TEST_UNITTEST_LDFLAGS=-ldflags "-X github.com/cilium/cilium/pkg/datapath.datapathSHA256=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
57
58BPF_SOURCE_NAMES_TO_IDS ?= bpf/source_names_to_ids.h
59GO_SOURCE_NAMES_TO_IDS ?= pkg/monitor/datapath_drop.go
60
61build: check-sources $(SUBDIRS) ## Builds all the components for Cilium by executing make in the respective sub directories.
62
63build-container: check-sources ## Builds components required for cilium-agent container.
64for i in $(SUBDIRS_CILIUM_CONTAINER); do $(MAKE) $(SUBMAKEOPTS) -C $$i all; done
65
66build-container-operator: ## Builds components required for cilium-operator container.
67$(MAKE) $(SUBMAKEOPTS) -C $(SUBDIR_OPERATOR_CONTAINER) all
68
69build-container-operator-generic: ## Builds components required for a cilium-operator generic variant container.
70$(MAKE) $(SUBMAKEOPTS) -C $(SUBDIR_OPERATOR_CONTAINER) cilium-operator-generic
71
72build-container-operator-aws: ## Builds components required for a cilium-operator aws variant container.
73$(MAKE) $(SUBMAKEOPTS) -C $(SUBDIR_OPERATOR_CONTAINER) cilium-operator-aws
74
75build-container-operator-azure: ## Builds components required for a cilium-operator azure variant container.
76$(MAKE) $(SUBMAKEOPTS) -C $(SUBDIR_OPERATOR_CONTAINER) cilium-operator-azure
77
78build-container-operator-alibabacloud: ## Builds components required for a cilium-operator alibabacloud variant container.
79$(MAKE) $(SUBMAKEOPTS) -C $(SUBDIR_OPERATOR_CONTAINER) cilium-operator-alibabacloud
80
81build-container-hubble-relay:
82$(MAKE) $(SUBMAKEOPTS) -C $(SUBDIR_RELAY_CONTAINER) all
83
84$(SUBDIRS): force ## Execute default make target(make all) for the provided subdirectory.
85@ $(MAKE) $(SUBMAKEOPTS) -C $@ all
86
87tests-privileged: ## Run Go tests including ones that require elevated privileges.
88@$(ECHO_CHECK) running privileged tests...
89PRIVILEGED_TESTS=true PATH=$(PATH):$(ROOT_DIR)/bpf $(GO_TEST) $(TEST_LDFLAGS) \
90$(TESTPKGS) $(GOTEST_BASE) $(GOTEST_COVER_OPTS) | $(GOTEST_FORMATTER)
91$(MAKE) generate-cov
92
93start-kvstores: ## Start running kvstores (etcd and consul containers) for integration tests.
94ifeq ($(SKIP_KVSTORES),"false")
95@echo Starting key-value store containers...
96-$(QUIET)$(CONTAINER_ENGINE) rm -f "cilium-etcd-test-container" 2> /dev/null
97$(QUIET)$(CONTAINER_ENGINE) run -d \
98-e ETCD_UNSUPPORTED_ARCH=$(GOARCH) \
99--name "cilium-etcd-test-container" \
100-p 4002:4001 \
101$(ETCD_IMAGE) \
102etcd -name etcd0 \
103-advertise-client-urls http://0.0.0.0:4001 \
104-listen-client-urls http://0.0.0.0:4001 \
105-listen-peer-urls http://0.0.0.0:2380 \
106-initial-cluster-token etcd-cluster-1 \
107-initial-cluster-state new
108-$(QUIET)$(CONTAINER_ENGINE) rm -f "cilium-consul-test-container" 2> /dev/null
109$(QUIET)rm -rf /tmp/cilium-consul-certs
110$(QUIET)mkdir /tmp/cilium-consul-certs
111$(QUIET)cp $(CURDIR)/test/consul/* /tmp/cilium-consul-certs
112$(QUIET)chmod -R a+rX /tmp/cilium-consul-certs
113$(QUIET)$(CONTAINER_ENGINE) run -d \
114--name "cilium-consul-test-container" \
115-p 8501:8443 \
116-e 'CONSUL_LOCAL_CONFIG={"skip_leave_on_interrupt": true, "disable_update_check": true}' \
117-v /tmp/cilium-consul-certs:/cilium-consul/ \
118$(CONSUL_IMAGE) \
119agent -client=0.0.0.0 -server -bootstrap-expect 1 -config-file=/cilium-consul/consul-config.json
120endif
121
122stop-kvstores: ## Forcefully removes running kvstore components (etcd and consul containers) for integration tests.
123ifeq ($(SKIP_KVSTORES),"false")
124$(QUIET)$(CONTAINER_ENGINE) rm -f "cilium-etcd-test-container"
125$(QUIET)$(CONTAINER_ENGINE) rm -f "cilium-consul-test-container"
126$(QUIET)rm -rf /tmp/cilium-consul-certs
127endif
128
129generate-cov: ## Generate HTML coverage report at coverage-all.html.
130# Remove generated code from coverage
131$(QUIET) grep -Ev '(^github.com/cilium/cilium/api/v1)|(generated.deepcopy.go)|(^github.com/cilium/cilium/pkg/k8s/client/)' \
132coverage.out > coverage.out.tmp
133$(QUIET)$(GO) tool cover -html=coverage.out.tmp -o=coverage-all.html
134$(QUIET) rm coverage.out.tmp
135@rmdir ./daemon/1 ./daemon/1_backup 2> /dev/null || true
136
137integration-tests: start-kvstores ## Run Go tests including ones that are marked as integration tests.
138$(QUIET) $(MAKE) $(SUBMAKEOPTS) -C test/bpf/
139@$(ECHO_CHECK) running integration tests...
140INTEGRATION_TESTS=true $(GO_TEST) $(TEST_UNITTEST_LDFLAGS) $(TESTPKGS) $(GOTEST_BASE) $(GOTEST_COVER_OPTS) | $(GOTEST_FORMATTER)
141$(MAKE) generate-cov
142$(MAKE) stop-kvstores
143
144bench: start-kvstores ## Run benchmarks for Cilium integration-tests in the repository.
145$(GO_TEST) $(TEST_UNITTEST_LDFLAGS) $(GOTEST_BASE) $(BENCHFLAGS) $(TESTPKGS)
146$(MAKE) stop-kvstores
147
148bench-privileged: ## Run benchmarks for privileged tests.
149PRIVILEGED_TESTS=true $(GO_TEST) $(TEST_UNITTEST_LDFLAGS) $(GOTEST_BASE) $(BENCHFLAGS) $(TESTPKGS)
150
151clean-tags: ## Remove all the tags files from the repository.
152@$(ECHO_CLEAN) tags
153@-rm -f cscope.out cscope.in.out cscope.po.out cscope.files tags
154
155.PHONY: cscope.files
156cscope.files: ## Generate cscope.files with the list of all files to generate ctags for.
157@# Argument to -f must be double-quoted since shell removes backslashes that appear
158@# before newlines. Otherwise, backslashes will appear in the output file.
159@go list -f "{{ \$$p := .ImportPath }} \
160{{- range .GoFiles }}{{ printf \"%s/%s\n\" \$$p . }}{{ end }} \
161{{- range .TestGoFiles }}{{ printf \"%s/%s\n\" \$$p . }}{{ end }}" ./... \
162| sed 's#github.com/cilium/cilium/##g' | sort | uniq > cscope.files
163
164@echo "$(BPF_SRCFILES)" | sed 's/ /\n/g' | sort >> cscope.files
165
166tags: cscope.files ## Generate tags for Go and BPF source files.
167@ctags -L cscope.files
168cscope -R -b -q
169
170clean-container: ## Perform `make clean` for each component required in cilium-agent container.
171-$(QUIET) for i in $(SUBDIRS_CILIUM_CONTAINER); do $(MAKE) $(SUBMAKEOPTS) -C $$i clean; done
172
173clean: ## Perform overall cleanup for Cilium.
174-$(QUIET) for i in $(SUBDIRS); do $(MAKE) $(SUBMAKEOPTS) -C $$i clean; done
175
176veryclean: ## Perform complete cleanup for container engine images(including build cache).
177-$(QUIET) $(CONTAINER_ENGINE) image prune -af
178-$(QUIET) $(CONTAINER_ENGINE) builder prune -af
179
180install-bpf: ## Copies over the BPF source files from bpf/ to /var/lib/cilium/bpf/
181$(QUIET)$(INSTALL) -m 0750 -d $(DESTDIR)$(LOCALSTATEDIR)/lib/cilium
182-rm -rf $(DESTDIR)$(LOCALSTATEDIR)/lib/cilium/bpf/*
183$(foreach bpfsrc,$(BPF_SRCFILES), $(INSTALL) -D -m 0644 $(bpfsrc) $(DESTDIR)$(LOCALSTATEDIR)/lib/cilium/$(bpfsrc);)
184
185install: install-bpf ## Performs install for all the Cilium sub components (daemon, operator, relay etc.)
186$(QUIET)$(INSTALL) -m 0755 -d $(DESTDIR)$(BINDIR)
187for i in $(SUBDIRS); do $(MAKE) $(SUBMAKEOPTS) -C $$i install; done
188
189install-container: install-bpf ## Performs install for all components required for cilium-agent container.
190$(QUIET)$(INSTALL) -m 0755 -d $(DESTDIR)$(BINDIR)
191for i in $(SUBDIRS_CILIUM_CONTAINER); do $(MAKE) $(SUBMAKEOPTS) -C $$i install; done
192
193install-container-binary: install-bpf ## Install binaries for all components required for cilium-agent container.
194$(QUIET)$(INSTALL) -m 0755 -d $(DESTDIR)$(BINDIR)
195for i in $(SUBDIRS_CILIUM_CONTAINER); do $(MAKE) $(SUBMAKEOPTS) -C $$i install-binary; done
196
197install-bash-completion: ## Install bash completion for all components required for cilium-agent container.
198$(QUIET)$(INSTALL) -m 0755 -d $(DESTDIR)$(BINDIR)
199for i in $(SUBDIRS_CILIUM_CONTAINER); do $(MAKE) $(SUBMAKEOPTS) -C $$i install-bash-completion; done
200
201install-container-binary-operator: ## Install binaries for all components required for cilium-operator container.
202$(QUIET)$(INSTALL) -m 0755 -d $(DESTDIR)$(BINDIR)
203$(MAKE) $(SUBMAKEOPTS) -C $(SUBDIR_OPERATOR_CONTAINER) install
204
205install-container-binary-operator-generic: ## Install binaries for all components required for cilium-operator generic variant container.
206$(QUIET)$(INSTALL) -m 0755 -d $(DESTDIR)$(BINDIR)
207$(MAKE) $(SUBMAKEOPTS) -C $(SUBDIR_OPERATOR_CONTAINER) install-generic
208
209install-container-binary-operator-aws: ## Install binaries for all components required for cilium-operator aws variant container.
210$(QUIET)$(INSTALL) -m 0755 -d $(DESTDIR)$(BINDIR)
211$(MAKE) $(SUBMAKEOPTS) -C $(SUBDIR_OPERATOR_CONTAINER) install-aws
212
213install-container-binary-operator-azure: ## Install binaries for all components required for cilium-operator azure variant container.
214$(QUIET)$(INSTALL) -m 0755 -d $(DESTDIR)$(BINDIR)
215$(MAKE) $(SUBMAKEOPTS) -C $(SUBDIR_OPERATOR_CONTAINER) install-azure
216
217install-container-binary-operator-alibabacloud: ## Install binaries for all components required for cilium-operator alibabacloud variant container.
218$(QUIET)$(INSTALL) -m 0755 -d $(DESTDIR)$(BINDIR)
219$(MAKE) $(SUBMAKEOPTS) -C $(SUBDIR_OPERATOR_CONTAINER) install-alibabacloud
220
221install-container-binary-hubble-relay:
222$(QUIET)$(INSTALL) -m 0755 -d $(DESTDIR)$(BINDIR)
223$(MAKE) $(SUBMAKEOPTS) -C $(SUBDIR_RELAY_CONTAINER) install-binary
224
225# Workaround for not having git in the build environment
226# Touch the file only if needed
227GIT_VERSION: force
228@if [ "$(GIT_VERSION)" != "`cat 2>/dev/null GIT_VERSION`" ] ; then echo "$(GIT_VERSION)" >GIT_VERSION; fi
229
230include Makefile.kind
231
232-include Makefile.docker
233
234##@ API targets
235CRD_OPTIONS ?= "crd:crdVersions=v1"
236CRD_PATHS := "$(PWD)/pkg/k8s/apis/cilium.io/v2;\
237$(PWD)/pkg/k8s/apis/cilium.io/v2alpha1;"
238CRDS_CILIUM_PATHS := $(PWD)/pkg/k8s/apis/cilium.io/client/crds/v2\
239$(PWD)/pkg/k8s/apis/cilium.io/client/crds/v2alpha1
240CRDS_CILIUM_V2 := ciliumnetworkpolicies \
241ciliumclusterwidenetworkpolicies \
242ciliumendpoints \
243ciliumidentities \
244ciliumnodes \
245ciliumexternalworkloads \
246ciliumlocalredirectpolicies \
247ciliumegressgatewaypolicies \
248ciliumenvoyconfigs \
249ciliumclusterwideenvoyconfigs
250CRDS_CILIUM_V2ALPHA1 := ciliumendpointslices \
251ciliumbgppeeringpolicies \
252ciliumbgpclusterconfigs \
253ciliumbgppeerconfigs \
254ciliumbgpadvertisements \
255ciliumbgpnodeconfigs \
256ciliumbgpnodeconfigoverrides \
257ciliumloadbalancerippools \
258ciliumnodeconfigs \
259ciliumcidrgroups \
260ciliuml2announcementpolicies \
261ciliumpodippools
262
263manifests: ## Generate K8s manifests e.g. CRD, RBAC etc.
264$(eval TMPDIR := $(shell mktemp -d -t cilium.tmpXXXXXXXX))
265$(QUIET)$(GO) run sigs.k8s.io/controller-tools/cmd/controller-gen $(CRD_OPTIONS) paths=$(CRD_PATHS) output:crd:artifacts:config="$(TMPDIR)"
266$(QUIET)$(GO) run ./tools/crdcheck "$(TMPDIR)"
267
268# Clean up old CRD state and start with a blank state.
269for path in $(CRDS_CILIUM_PATHS); do rm -rf $${path} && mkdir $${path}; done
270
271for file in $(CRDS_CILIUM_V2); do mv ${TMPDIR}/cilium.io_$${file}.yaml ./pkg/k8s/apis/cilium.io/client/crds/v2/$${file}.yaml; done
272for file in $(CRDS_CILIUM_V2ALPHA1); do mv ${TMPDIR}/cilium.io_$${file}.yaml ./pkg/k8s/apis/cilium.io/client/crds/v2alpha1/$${file}.yaml; done
273rm -rf $(TMPDIR)
274
275generate-api: api/v1/openapi.yaml ## Generate cilium-agent client, model and server code from openapi spec.
276@$(ECHO_GEN)api/v1/openapi.yaml
277-$(QUIET)$(SWAGGER) generate server -s server -a restapi \
278-t api/v1 \
279-f api/v1/openapi.yaml \
280--default-scheme=unix \
281-C api/v1/cilium-server.yml \
282-r hack/spdx-copyright-header.txt
283-$(QUIET)$(SWAGGER) generate client -a restapi \
284-t api/v1 \
285-f api/v1/openapi.yaml \
286-r hack/spdx-copyright-header.txt
287@# sort goimports automatically
288-$(QUIET)$(GO) run golang.org/x/tools/cmd/goimports -w ./api/v1/client ./api/v1/models ./api/v1/server
289
290generate-health-api: api/v1/health/openapi.yaml ## Generate cilium-health client, model and server code from openapi spec.
291@$(ECHO_GEN)api/v1/health/openapi.yaml
292-$(QUIET)$(SWAGGER) generate server -s server -a restapi \
293-t api/v1 \
294-t api/v1/health/ \
295-f api/v1/health/openapi.yaml \
296--default-scheme=unix \
297-C api/v1/cilium-server.yml \
298-r hack/spdx-copyright-header.txt
299-$(QUIET)$(SWAGGER) generate client -a restapi \
300-t api/v1 \
301-t api/v1/health/ \
302-f api/v1/health/openapi.yaml \
303-r hack/spdx-copyright-header.txt
304@# sort goimports automatically
305-$(QUIET)$(GO) run golang.org/x/tools/cmd/goimports -w ./api/v1/health
306
307generate-operator-api: api/v1/operator/openapi.yaml ## Generate cilium-operator client, model and server code from openapi spec.
308@$(ECHO_GEN)api/v1/operator/openapi.yaml
309-$(QUIET)$(SWAGGER) generate server -s server -a restapi \
310-t api/v1 \
311-t api/v1/operator/ \
312-f api/v1/operator/openapi.yaml \
313--default-scheme=http \
314-C api/v1/cilium-server.yml \
315-r hack/spdx-copyright-header.txt
316-$(QUIET)$(SWAGGER) generate client -a restapi \
317-t api/v1 \
318-t api/v1/operator/ \
319-f api/v1/operator/openapi.yaml \
320-r hack/spdx-copyright-header.txt
321@# sort goimports automatically
322-$(QUIET)$(GO) run golang.org/x/tools/cmd/goimports -w ./api/v1/operator
323
324generate-hubble-api: api/v1/flow/flow.proto api/v1/peer/peer.proto api/v1/observer/observer.proto api/v1/relay/relay.proto ## Generate hubble proto Go sources.
325$(QUIET) $(MAKE) $(SUBMAKEOPTS) -C api/v1
326
327define generate_k8s_api
328$(QUIET) cd "./vendor/k8s.io/code-generator" && \
329bash ./generate-internal-groups.sh $(1) \
330$(2) \
331"" \
332$(3) \
333$(4) \
334--go-header-file "$(PWD)/hack/custom-boilerplate.go.txt" \
335--output-base $(5)
336endef
337
338define generate_deepequal
339$(GO) run github.com/cilium/deepequal-gen \
340--input-dirs $(subst $(space),$(comma),$(1)) \
341--go-header-file "$(PWD)/hack/custom-boilerplate.go.txt" \
342--output-file-base zz_generated.deepequal \
343--output-base $(2)
344endef
345
346define generate_deepcopy
347$(GO) run k8s.io/code-generator/cmd/deepcopy-gen \
348--input-dirs $(subst $(space),$(comma),$(1)) \
349--go-header-file "$(PWD)/hack/custom-boilerplate.go.txt" \
350--output-file-base zz_generated.deepcopy \
351--output-base $(2)
352endef
353
354define generate_k8s_protobuf
355$(GO) install k8s.io/code-generator/cmd/go-to-protobuf/protoc-gen-gogo && \
356$(GO) install golang.org/x/tools/cmd/goimports && \
357$(GO) run k8s.io/code-generator/cmd/go-to-protobuf \
358--apimachinery-packages='-k8s.io/apimachinery/pkg/util/intstr,$\
359-k8s.io/apimachinery/pkg/api/resource,$\
360-k8s.io/apimachinery/pkg/runtime/schema,$\
361-k8s.io/apimachinery/pkg/runtime,$\
362-k8s.io/apimachinery/pkg/apis/meta/v1,$\
363-k8s.io/apimachinery/pkg/apis/meta/v1beta1'\
364--drop-embedded-fields="github.com/cilium/cilium/pkg/k8s/slim/k8s/apis/meta/v1.TypeMeta" \
365--proto-import="$(PWD)" \
366--proto-import="$(PWD)/vendor" \
367--proto-import="$(PWD)/tools/protobuf" \
368--packages=$(subst $(newline),$(comma),$(1)) \
369--go-header-file "$(PWD)/hack/custom-boilerplate.go.txt" \
370--output-base=$(2)
371endef
372
373define K8S_PROTO_PACKAGES
374github.com/cilium/cilium/pkg/k8s/slim/k8s/api/core/v1
375github.com/cilium/cilium/pkg/k8s/slim/k8s/api/discovery/v1
376github.com/cilium/cilium/pkg/k8s/slim/k8s/api/discovery/v1beta1
377github.com/cilium/cilium/pkg/k8s/slim/k8s/api/networking/v1
378github.com/cilium/cilium/pkg/k8s/slim/k8s/apis/apiextensions/v1
379github.com/cilium/cilium/pkg/k8s/slim/k8s/apis/meta/v1
380github.com/cilium/cilium/pkg/k8s/slim/k8s/apis/meta/v1beta1
381github.com/cilium/cilium/pkg/k8s/slim/k8s/apis/util/intstr
382endef
383
384GEN_CRD_GROUPS := "cilium.io:v2\
385cilium.io:v2alpha1"
386generate-k8s-api: ## Generate Cilium k8s API client, deepcopy and deepequal Go sources.
387$(ASSERT_CILIUM_MODULE)
388
389$(eval TMPDIR := $(shell mktemp -d -t cilium.tmpXXXXXXXX))
390
391$(QUIET) $(call generate_k8s_protobuf,${K8S_PROTO_PACKAGES},"$(TMPDIR)")
392
393$(eval DEEPEQUAL_PACKAGES := $(shell grep "\+deepequal-gen" -l -r --include \*.go --exclude-dir 'vendor' . | xargs dirname {} | sort | uniq | grep -x -v '.' | sed 's|\.\/|github.com/cilium/cilium\/|g'))
394$(QUIET) $(call generate_deepequal,${DEEPEQUAL_PACKAGES},"$(TMPDIR)")
395
396$(eval DEEPCOPY_PACKAGES := $(shell grep "\+k8s:deepcopy-gen" -l -r --include \*.go --exclude-dir 'vendor' . | xargs dirname {} | sort | uniq | grep -x -v '.' | sed 's|\.\/|github.com/cilium/cilium\/|g'))
397$(QUIET) $(call generate_deepcopy,${DEEPCOPY_PACKAGES},"$(TMPDIR)")
398
399$(QUIET) $(call generate_k8s_api,client,github.com/cilium/cilium/pkg/k8s/slim/k8s/client,github.com/cilium/cilium/pkg/k8s/slim/k8s/api,"discovery:v1beta1 discovery:v1 networking:v1 core:v1","$(TMPDIR)")
400$(QUIET) $(call generate_k8s_api,client,github.com/cilium/cilium/pkg/k8s/slim/k8s/apiextensions-client,github.com/cilium/cilium/pkg/k8s/slim/k8s/apis,"apiextensions:v1","$(TMPDIR)")
401$(QUIET) $(call generate_k8s_api,client$(comma)lister$(comma)informer,github.com/cilium/cilium/pkg/k8s/client,github.com/cilium/cilium/pkg/k8s/apis,$(GEN_CRD_GROUPS),"$(TMPDIR)")
402
403$(QUIET) cp -r "$(TMPDIR)/github.com/cilium/cilium/." ./
404$(QUIET) rm -rf "$(TMPDIR)"
405
406check-k8s-clusterrole: ## Ensures there is no diff between preflight's clusterrole and runtime's clusterrole.
407./contrib/scripts/check-preflight-clusterrole.sh
408
409##@ Development
410vps: ## List all the running vagrant VMs.
411VBoxManage list runningvms
412
413reload: ## Reload cilium-agent and cilium-docker systemd service after installing built binaries.
414sudo systemctl stop cilium cilium-docker
415sudo $(MAKE) install
416sudo systemctl start cilium cilium-docker
417sleep 6
418cilium status
419
420release: ## Perform a Git release for Cilium.
421$(eval TAG_VERSION := $(shell git tag | grep v$(VERSION) > /dev/null; echo $$?))
422$(eval BRANCH := $(shell git rev-parse --abbrev-ref HEAD))
423$(info Checking if tag $(VERSION) is created '$(TAG_VERSION)' $(BRANCH))
424
425@if [ "$(TAG_VERSION)" -eq "0" ];then { echo Git tag v$(VERSION) is already created; exit 1; } fi
426git commit -m "Version $(VERSION)"
427git tag v$(VERSION)
428git archive --format tar $(BRANCH) | gzip > ../cilium_$(VERSION).orig.tar.gz
429
430gofmt: ## Run gofmt on Go source files in the repository.
431$(QUIET)$(GO) fmt ./...
432
433govet: ## Run govet on Go source files in the repository.
434@$(ECHO_CHECK) vetting all packages...
435$(QUIET) $(GO_VET) ./...
436
437golangci-lint: ## Run golangci-lint
438ifneq (,$(findstring $(GOLANGCILINT_WANT_VERSION:v%=%),$(GOLANGCILINT_VERSION)))
439@$(ECHO_CHECK) golangci-lint $(GOLANGCI_LINT_ARGS)
440$(QUIET) golangci-lint run $(GOLANGCI_LINT_ARGS)
441else
442$(QUIET) $(CONTAINER_ENGINE) run --rm -v `pwd`:/app -w /app docker.io/golangci/golangci-lint:$(GOLANGCILINT_WANT_VERSION)@$(GOLANGCILINT_IMAGE_SHA) golangci-lint run $(GOLANGCI_LINT_ARGS)
443endif
444
445golangci-lint-fix: ## Run golangci-lint to automatically fix warnings
446$(QUIET)$(MAKE) golangci-lint GOLANGCI_LINT_ARGS="--fix"
447
448lint: golangci-lint
449
450lint-fix: golangci-lint-fix
451
452logging-subsys-field: ## Validate logrus subsystem field for logs in Go source code.
453@$(ECHO_CHECK) contrib/scripts/check-logging-subsys-field.sh
454$(QUIET) contrib/scripts/check-logging-subsys-field.sh
455
456check-microk8s: ## Validate if microk8s is ready to install cilium.
457@$(ECHO_CHECK) microk8s is ready...
458$(QUIET)microk8s.status >/dev/null \
459|| (echo "Error: Microk8s is not running" && exit 1)
460
461LOCAL_IMAGE_TAG=local
462microk8s: export DOCKER_REGISTRY=localhost:32000
463microk8s: export LOCAL_AGENT_IMAGE=$(DOCKER_REGISTRY)/$(DOCKER_DEV_ACCOUNT)/cilium-dev:$(LOCAL_IMAGE_TAG)
464microk8s: export LOCAL_OPERATOR_IMAGE=$(DOCKER_REGISTRY)/$(DOCKER_DEV_ACCOUNT)/operator:$(LOCAL_IMAGE_TAG)
465microk8s: check-microk8s ## Build cilium-dev docker image and import to microk8s
466$(QUIET)$(MAKE) dev-docker-image DOCKER_IMAGE_TAG=$(LOCAL_IMAGE_TAG)
467@echo " DEPLOY image to microk8s ($(LOCAL_AGENT_IMAGE))"
468$(QUIET)./contrib/scripts/microk8s-import.sh $(LOCAL_AGENT_IMAGE)
469$(QUIET)$(MAKE) dev-docker-operator-image DOCKER_IMAGE_TAG=$(LOCAL_IMAGE_TAG)
470@echo " DEPLOY image to microk8s ($(LOCAL_OPERATOR_IMAGE))"
471$(QUIET)./contrib/scripts/microk8s-import.sh $(LOCAL_OPERATOR_IMAGE)
472
473precheck: logging-subsys-field ## Peform build precheck for the source code.
474ifeq ($(SKIP_K8S_CODE_GEN_CHECK),"false")
475@$(ECHO_CHECK) contrib/scripts/check-k8s-code-gen.sh
476$(QUIET) contrib/scripts/check-k8s-code-gen.sh
477endif
478@$(ECHO_CHECK) contrib/scripts/check-fmt.sh
479$(QUIET) contrib/scripts/check-fmt.sh
480@$(ECHO_CHECK) contrib/scripts/check-log-newlines.sh
481$(QUIET) contrib/scripts/check-log-newlines.sh
482@$(ECHO_CHECK) contrib/scripts/check-test-tags.sh
483$(QUIET) contrib/scripts/check-test-tags.sh
484@$(ECHO_CHECK) contrib/scripts/check-assert-deep-equals.sh
485$(QUIET) contrib/scripts/check-assert-deep-equals.sh
486@$(ECHO_CHECK) contrib/scripts/lock-check.sh
487$(QUIET) contrib/scripts/lock-check.sh
488@$(ECHO_CHECK) contrib/scripts/check-viper.sh
489$(QUIET) contrib/scripts/check-viper.sh
490ifeq ($(SKIP_CUSTOMVET_CHECK),"false")
491@$(ECHO_CHECK) contrib/scripts/custom-vet-check.sh
492$(QUIET) contrib/scripts/custom-vet-check.sh
493endif
494@$(ECHO_CHECK) contrib/scripts/rand-check.sh
495$(QUIET) contrib/scripts/rand-check.sh
496@$(ECHO_CHECK) contrib/scripts/check-time.sh
497$(QUIET) contrib/scripts/check-time.sh
498
499check-sources:
500@$(ECHO_CHECK) pkg/datapath/loader/check-sources.sh
501$(QUIET) BPF_SOURCE_NAMES_TO_IDS=$(BPF_SOURCE_NAMES_TO_IDS) GO_SOURCE_NAMES_TO_IDS=$(GO_SOURCE_NAMES_TO_IDS) pkg/datapath/loader/check-sources.sh
502
503pprof-heap: ## Get Go pprof heap profile.
504$(QUIET)$(GO) tool pprof http://localhost:6060/debug/pprof/heap
505
506pprof-profile: ## Get Go pprof profile.
507$(QUIET)$(GO) tool pprof http://localhost:6060/debug/pprof/profile
508
509pprof-block: ## Get Go pprof block profile.
510$(QUIET)$(GO) tool pprof http://localhost:6060/debug/pprof/block
511
512pprof-trace-5s: ## Get Go pprof trace for a duration of 5 seconds.
513curl http://localhost:6060/debug/pprof/trace?seconds=5
514
515pprof-mutex: ## Get Go pprof mutex profile.
516$(QUIET)$(GO) tool pprof http://localhost:6060/debug/pprof/mutex
517
518update-authors: ## Update AUTHORS file for Cilium repository.
519@echo "Updating AUTHORS file..."
520@echo "The following people, in alphabetical order, have either authored or signed" > AUTHORS
521@echo "off on commits in the Cilium repository:" >> AUTHORS
522@echo "" >> AUTHORS
523@contrib/scripts/extract_authors.sh >> AUTHORS
524@cat .authors.aux >> AUTHORS
525
526generate-crd-docs: ## Generate CRD List for documentation
527$(QUIET)$(GO) run ./tools/crdlistgen
528
529test-docs: ## Build HTML documentation.
530$(MAKE) -C Documentation html
531
532render-docs: ## Run server with live preview to render documentation.
533$(MAKE) -C Documentation live-preview
534
535manpages: ## Generate manpage for Cilium CLI.
536-rm -r man
537mkdir -p man
538cilium cmdman -d man
539
540install-manpages: ## Install manpages the Cilium CLI.
541cp man/* /usr/local/share/man/man1/
542mandb
543
544postcheck: build ## Run Cilium build postcheck (update-cmdref, build documentation etc.).
545$(QUIET) SKIP_BUILD=true $(MAKE) $(SUBMAKEOPTS) -C Documentation check
546
547licenses-all: ## Generate file with all the License from dependencies.
548@$(GO) run ./tools/licensegen > LICENSE.all || ( rm -f LICENSE.all ; false )
549
550dev-doctor: ## Run Cilium dev-doctor to validate local development environment.
551$(QUIET)$(GO) version 2>/dev/null || ( echo "go not found, see https://golang.org/doc/install" ; false )
552$(QUIET)$(GO) run ./tools/dev-doctor
553
554help: ## Display help for the Makefile, from https://www.thapaliya.com/en/writings/well-documented-makefiles/.
555$(call print_help_from_makefile)
556@# There is also a list of target we have to manually put the information about.
557@# These are templated targets.
558$(call print_help_line,"docker-cilium-image","Build cilium-agent docker image")
559$(call print_help_line,"dev-docker-image","Build cilium-agent development docker image")
560$(call print_help_line,"docker-plugin-image","Build cilium-docker plugin image")
561$(call print_help_line,"docker-hubble-relay-image","Build hubble-relay docker image")
562$(call print_help_line,"docker-clustermesh-apiserver-image","Build docker image for Cilium clustermesh APIServer")
563$(call print_help_line,"docker-operator-image","Build cilium-operator docker image")
564$(call print_help_line,"docker-operator-*-image","Build platform specific cilium-operator images(alibabacloud, aws, azure, generic)")
565$(call print_help_line,"docker-*-image-unstripped","Build unstripped version of above docker images(cilium, hubble-relay, operator etc.)")
566
567.PHONY: help clean clean-container dev-doctor force generate-api generate-health-api generate-operator-api generate-hubble-api install licenses-all veryclean check-sources
568force :;
569
570# this top level run_bpf_tests target will run the bpf unit tests inside the Cilium Builder container.
571# it exists here so the entire source code repo can be mounted into the container.
572CILIUM_BUILDER_IMAGE=$(shell cat images/cilium/Dockerfile | grep "ARG CILIUM_BUILDER_IMAGE=" | cut -d"=" -f2)
573run_bpf_tests:
574docker run -v $$(pwd):/src --privileged -w /src -e RUN_WITH_SUDO=false $(CILIUM_BUILDER_IMAGE) "make" "-C" "test/" "run_bpf_tests"
575
576run-builder:
577docker run -it --rm -v $$(pwd):/go/src/github.com/cilium/cilium $(CILIUM_BUILDER_IMAGE) bash
578