Skip to content

Commit

Permalink
makefile: containerize crd generation
Browse files Browse the repository at this point in the history
We encountered some version-specific differences related to golang tooling which impact
the resulting CRD generation from make generate. To solve this problem, let's containerize
the CRD generation workflow so that we can get consistent output through consistent
tooling. while we're at it, rename the generate target to crds to disambiguate it from
protobuf code generation. We keep the old generate target around as an alias for backward
compatibility.

Signed-off-by: William Findlay <[email protected]>
  • Loading branch information
willfindlay committed Feb 23, 2024
1 parent cc40a14 commit df6f4ac
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ help:
@echo ' tarball-release - build Tetragon release tarball'
@echo 'Generated files:'
@echo ' codegen - generate code based on .proto files'
@echo ' generate - generate kubebuilder files'
@echo ' crds - generate kubebuilder files'
@echo 'Linting and chores:'
@echo ' vendor - tidy and vendor Go modules'
@echo ' clang-format - run code formatter on BPF code'
Expand Down Expand Up @@ -290,8 +290,9 @@ tarball-clean:
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:
.PHONY: crdgen generate codegen protoc-gen-go-tetragon
generate: | crds
crds:
# 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ make codegen

And to run k8s CRD generation, run the following command from the root of the repository:
```shell
make generate
make crds
```

Finally, should you wish to modify any of the resulting codegen files (ending
Expand Down
16 changes: 13 additions & 3 deletions pkg/k8s/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# renovate: datasource=docker
BUILDER_IMAGE=docker.io/library/golang:1.20.5@sha256:fd9306e1c664bd49a11d4a4a04e41303430e069e437d137876e9290a555e06fb
GO ?= go
VERSION=$(shell git describe --tags --always)
GO_GCFLAGS ?= ""
Expand All @@ -10,18 +12,26 @@ GOLANGCILINT_VERSION = $(shell golangci-lint version 2>/dev/null)

all: generate

.PHONY: generate

.PHONY: help
help:
@echo 'Generated files:'
@echo ' generate - genereate kubebuilder files'
@echo ' generate - generate kubebuilder files'

ifeq (1,$(NOOPT))
GO_GCFLAGS = "all=-N -l"
endif

.PHONY: generate
generate:
docker container run --rm \
--volume $(CURDIR)/../..:/src \
--user "$(shell id -u):$(shell id -g)" \
--env GOCACHE=/go/.cache \
$(BUILDER_IMAGE) \
make -C /src/pkg/k8s __do_generate

.PHONY: __do_generate
__do_generate:
./tools/controller-gen crd paths=./apis/... output:dir=apis/cilium.io/client/crds/v1alpha1
# Do two invocations of generate-groups.sh, one with --plural-exceptions, one without
export GOPATH=$$(go env GOPATH); \
Expand Down

0 comments on commit df6f4ac

Please sign in to comment.