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 <will@isovalent.com>
  • Loading branch information
willfindlay committed Feb 22, 2024
1 parent 1a8e6f6 commit c26e483
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,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 ' generate-flags - generate Tetragon daemon flags for documentation'
@echo ' Linting and chores:'
@echo ' vendor - tidy and vendor Go modules'
Expand Down Expand Up @@ -330,8 +330,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
4 changes: 2 additions & 2 deletions docs/content/en/docs/contribution-guide/development-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,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 All @@ -100,7 +100,7 @@ you can use:
make vendor
```

Note that the `make codegen` and `make generate` commands already vendor
Note that the `make codegen` and `make crds` commands already vendor
changes automatically.

## Building and running a Docker image
Expand Down
16 changes: 13 additions & 3 deletions pkg/k8s/Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
# renovate: datasource=docker
BUILDER_IMAGE=docker.io/library/golang:1.22.0@sha256:7b297d9abee021bab9046e492506b3c2da8a3722cbf301653186545ecc1e00bb
GO ?= go

all: generate

.PHONY: generate

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

.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
chmod +x vendor/k8s.io/code-generator/generate-internal-groups.sh
# Do two invocations of generate-groups.sh, one with --plural-exceptions, one without
Expand Down

0 comments on commit c26e483

Please sign in to comment.