Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backports/v1.0/2131 #2136

Merged
merged 2 commits into from
Feb 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Dockerfile.codegen

This file was deleted.

21 changes: 9 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -113,8 +113,8 @@ help:
@echo ' tarball - build Tetragon compressed tarball'
@echo ' tarball-release - build Tetragon release tarball'
@echo ' Generated files:'
@echo ' codegen - generate code based on .proto files'
@echo ' generate - generate kubebuilder files'
@echo ' protogen - generate code based on .proto 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'
@@ -282,7 +282,7 @@ update-copyright:
lint:
golint -set_exit_status $$(go list ./...)

.PHONY: image image-operator image-test image-codegen
.PHONY: image image-operator image-test
image:
$(CONTAINER_ENGINE) build -t "cilium/tetragon:${DOCKER_IMAGE_TAG}" --target release --build-arg TETRAGON_VERSION=$(VERSION) .
$(QUIET)@echo "Push like this when ready:"
@@ -298,11 +298,6 @@ image-test: image-clang
$(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:15.0.7-0ubuntu0.22.04.2 -t "cilium/clang:${DOCKER_IMAGE_TAG}" .
@@ -334,23 +329,25 @@ 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 protogen 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
$(MAKE) -C pkg/k8s/
$(MAKE) vendor

codegen: image-codegen
codegen: | protogen
protogen: protoc-gen-go-tetragon
# 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) -o bin/$@ ./cmd/protoc-gen-go-tetragon/
$(GO_BUILD) -o bin/$@ ./tools/protoc-gen-go-tetragon/

.PHONY: check
ifneq (,$(findstring $(GOLANGCILINT_WANT_VERSION),$(GOLANGCILINT_VERSION)))
7 changes: 4 additions & 3 deletions api/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Copyright 2017-2020 Authors of Cilium
# SPDX-License-Identifier: Apache-2.0

# renovate: datasource=docker
BUILDER_IMAGE=quay.io/cilium/cilium-builder@sha256:a2036a3f6420647e6702695dabd2ffa4d2832db45157042d0255bdc707b8e1f2
GO ?= go
BUILDER_IMAGE=cilium/tetragon-codegen:latest

.PHONY: all
all: proto
@@ -13,10 +14,10 @@ proto: v1
.PHONY: v1
v1:
docker container run --rm \
--volume $(CURDIR)/v1:/src \
--volume $(CURDIR)/..:/src \
--user "$(shell id -u):$(shell id -g)" \
$(BUILDER_IMAGE) \
make -C /src -f Makefile.protoc
make -C /src/api/v1 -f Makefile.protoc
./export-doc.sh ../docs/content/en/docs/reference/grpc-api.md

.PHONY: vendor
2 changes: 1 addition & 1 deletion api/v1/Makefile.protoc
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ TETRAGON_PROTOC_PLUGINS := \
--plugin=$(GOPATH)/bin/protoc-gen-go \
--plugin=$(GOPATH)/bin/protoc-gen-go-grpc \
--plugin=$(GOPATH)/bin/protoc-gen-go-json \
--plugin=$(GOPATH)/bin/protoc-gen-go-tetragon \
--plugin=../../bin/protoc-gen-go-tetragon \

.PHONY: all
all: protobuf codegen
21 changes: 17 additions & 4 deletions docs/content/en/docs/contribution-guide/development-setup.md
Original file line number Diff line number Diff line change
@@ -65,19 +65,32 @@ you will be required to re-run code generation before your PR can be accepted.
To run codegen from protoc, run the following command from the root of the
repository:
```shell
make codegen
make protogen
```

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
in` .pb.go`), do not modify them directly. Instead, you can edit the files in
`cmd/protoc-gen-go-tetragon` and then re-run `make codegen`.
`cmd/protoc-gen-go-tetragon` and then re-run `make protogen`.

### Building and running a Docker image
## Running vendor

Tetragon uses multiple modules to separate the main module, from `api` from
`pkg/k8s`. Depending on your changes you might need to vendor those changes,
you can use:

```shell
make vendor
```

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

## Building and running a Docker image

The base kernel should support [BTF](https://github.com/cilium/tetragon#btf-requirement)
or a BTF file should be bind mounted on top of `/var/lib/tetragon/btf` inside
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
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ package eventchecker
import (
"fmt"

"github.com/cilium/tetragon/cmd/protoc-gen-go-tetragon/common"
"github.com/cilium/tetragon/tools/protoc-gen-go-tetragon/common"
"github.com/jpillora/longestcommon"
"google.golang.org/protobuf/compiler/protogen"
)
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ package eventchecker
import (
"fmt"

"github.com/cilium/tetragon/cmd/protoc-gen-go-tetragon/common"
"github.com/cilium/tetragon/tools/protoc-gen-go-tetragon/common"
"google.golang.org/protobuf/compiler/protogen"
)

Original file line number Diff line number Diff line change
@@ -8,8 +8,8 @@ import (
"path/filepath"
"strings"

"github.com/cilium/tetragon/cmd/protoc-gen-go-tetragon/common"
"github.com/cilium/tetragon/cmd/protoc-gen-go-tetragon/imports"
"github.com/cilium/tetragon/tools/protoc-gen-go-tetragon/common"
"github.com/cilium/tetragon/tools/protoc-gen-go-tetragon/imports"
"github.com/iancoleman/strcase"
"google.golang.org/protobuf/compiler/protogen"
"google.golang.org/protobuf/reflect/protoreflect"
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ import (
"path/filepath"
"strings"

"github.com/cilium/tetragon/cmd/protoc-gen-go-tetragon/common"
"github.com/cilium/tetragon/tools/protoc-gen-go-tetragon/common"
"google.golang.org/protobuf/compiler/protogen"
)

Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
package eventchecker

import (
"github.com/cilium/tetragon/cmd/protoc-gen-go-tetragon/common"
"github.com/cilium/tetragon/tools/protoc-gen-go-tetragon/common"
"google.golang.org/protobuf/compiler/protogen"
)

Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ import (
"fmt"
"strings"

"github.com/cilium/tetragon/cmd/protoc-gen-go-tetragon/common"
"github.com/cilium/tetragon/tools/protoc-gen-go-tetragon/common"
"github.com/iancoleman/strcase"
"google.golang.org/protobuf/compiler/protogen"
)
Original file line number Diff line number Diff line change
@@ -6,9 +6,9 @@ package generate
import (
"fmt"

"github.com/cilium/tetragon/cmd/protoc-gen-go-tetragon/eventchecker"
"github.com/cilium/tetragon/cmd/protoc-gen-go-tetragon/helpers"
"github.com/cilium/tetragon/cmd/protoc-gen-go-tetragon/types"
"github.com/cilium/tetragon/tools/protoc-gen-go-tetragon/eventchecker"
"github.com/cilium/tetragon/tools/protoc-gen-go-tetragon/helpers"
"github.com/cilium/tetragon/tools/protoc-gen-go-tetragon/types"
"google.golang.org/protobuf/compiler/protogen"
)

Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ import (
"fmt"
"strings"

"github.com/cilium/tetragon/cmd/protoc-gen-go-tetragon/common"
"github.com/cilium/tetragon/tools/protoc-gen-go-tetragon/common"
"google.golang.org/protobuf/compiler/protogen"
)

Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
package main

import (
"github.com/cilium/tetragon/cmd/protoc-gen-go-tetragon/generate"
"github.com/cilium/tetragon/tools/protoc-gen-go-tetragon/generate"
)

func main() {
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ package types
import (
"path/filepath"

"github.com/cilium/tetragon/cmd/protoc-gen-go-tetragon/common"
"github.com/cilium/tetragon/tools/protoc-gen-go-tetragon/common"
"google.golang.org/protobuf/compiler/protogen"
)

Loading