Skip to content

Commit 3f55aca

Browse files
committed
build: setups for API generations
Signed-off-by: Takeshi Yoneda <[email protected]>
1 parent 9c11a36 commit 3f55aca

File tree

6 files changed

+76
-3
lines changed

6 files changed

+76
-3
lines changed

Makefile

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# The Go-based tools are defined in Makefile.tools.mk.
22
include Makefile.tools.mk
33

4+
# This runs the linter, formatter, and tidy on the codebase.
45
.PHONY: lint
56
lint: golangci-lint
67
@echo "lint => ./..."
7-
@$(GOLANGCI_LINT) run --build-tags=$(LINT_BUILD_TAGS) ./...
8+
@$(GOLANGCI_LINT) run ./...
89

10+
# This runs the formatter on the codebase as well as goimports via gci.
911
.PHONY: format
1012
format: gci gofumpt
1113
@echo "format => *.go"
@@ -14,16 +16,25 @@ format: gci gofumpt
1416
@echo "gci => *.go"
1517
@$(GCI) write -s standard -s default -s "prefix(github.com/envoyproxy/ai-gateway)" `find . -name '*.go'`
1618

19+
# This runs go mod tidy on every module.
1720
.PHONY: tidy
18-
tidy: ## Runs go mod tidy on every module
21+
tidy:
1922
@find . -name "go.mod" \
2023
| grep go.mod \
2124
| xargs -I {} bash -c 'dirname {}' \
2225
| xargs -I {} bash -c 'echo "tidy => {}"; cd {}; go mod tidy -v; '
2326

27+
# This re-generates the CRDs for the API defined in the api/v1alpha1 directory.
28+
.PHONY: apigen
29+
apigen: controller-gen
30+
@echo "apigen => ./api/v1alpha1/..."
31+
@$(CONTROLLER_GEN) object crd paths="./api/v1alpha1/..." output:dir=./api/v1alpha1 output:crd:dir=./manifests/charts/ai-gateway-helm/crds
32+
33+
# This runs all necessary steps to prepare for a commit.
2434
.PHONY: precommit
25-
precommit: format tidy lint
35+
precommit: apigen format tidy lint
2636

37+
# This runs precommit and checks for any differences in the codebase, failing if there are any.
2738
.PHONY: check
2839
check:
2940
@$(MAKE) precommit
@@ -32,6 +43,7 @@ check:
3243
git diff --exit-code; \
3344
fi
3445

46+
# This runs the unit tests for the codebase.
3547
.PHONY: test
3648
test:
3749
@echo "test => ./..."

Makefile.tools.mk

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ $(LOCALBIN):
33
mkdir -p $(LOCALBIN)
44

55
## Tool binary names.
6+
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
67
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
78
GO_FUMPT = $(LOCALBIN)/gofumpt
89
GCI = $(LOCALBIN)/gci
910

1011
## Tool versions.
12+
CONTROLLER_TOOLS_VERSION ?= v0.16.2
1113
GOLANGCI_LINT_VERSION ?= v1.60.1
1214
GO_FUMPT_VERSION ?= v0.6.0
1315
GCI_VERSION ?= v0.13.5
@@ -27,6 +29,11 @@ gci: $(GCI)
2729
$(GCI): $(LOCALBIN)
2830
$(call go-install-tool,$(GCI),github.com/daixiang0/gci,$(GCI_VERSION))
2931

32+
.PHONY: controller-gen
33+
controller-gen: $(CONTROLLER_GEN)
34+
$(CONTROLLER_GEN): $(LOCALBIN)
35+
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION))
36+
3037
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
3138
# $1 - target path with name of binary
3239
# $2 - package url which can be installed

api/v1alpha1/api.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package v1alpha1
2+
3+
// +kubebuilder:object:root=true

api/v1alpha1/doc.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Package v1alpha1 contains API schema definitions for the aigateway.envoyproxy.io
2+
// API group.
3+
//
4+
// +kubebuilder:object:generate=true
5+
// +groupName=aigateway.envoyproxy.io
6+
package v1alpha1

api/v1alpha1/registry.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package v1alpha1
2+
3+
import (
4+
"k8s.io/apimachinery/pkg/runtime/schema"
5+
"sigs.k8s.io/controller-runtime/pkg/scheme"
6+
)
7+
8+
const GroupName = "aigateway.envoyproxy.io"
9+
10+
var (
11+
// schemeGroupVersion is group version used to register these objects
12+
schemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha1"}
13+
14+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
15+
SchemeBuilder = &scheme.Builder{GroupVersion: schemeGroupVersion}
16+
17+
// AddToScheme adds the types in this group-version to the given scheme.
18+
AddToScheme = SchemeBuilder.AddToScheme
19+
)

go.mod

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
11
module github.com/envoyproxy/ai-gateway
22

33
go 1.23.2
4+
5+
require (
6+
k8s.io/apimachinery v0.31.0
7+
sigs.k8s.io/controller-runtime v0.19.2
8+
)
9+
10+
require (
11+
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
12+
github.com/go-logr/logr v1.4.2 // indirect
13+
github.com/gogo/protobuf v1.3.2 // indirect
14+
github.com/google/gofuzz v1.2.0 // indirect
15+
github.com/json-iterator/go v1.1.12 // indirect
16+
github.com/kr/text v0.2.0 // indirect
17+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
18+
github.com/modern-go/reflect2 v1.0.2 // indirect
19+
github.com/x448/float16 v0.8.4 // indirect
20+
golang.org/x/net v0.26.0 // indirect
21+
golang.org/x/text v0.16.0 // indirect
22+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
23+
gopkg.in/inf.v0 v0.9.1 // indirect
24+
gopkg.in/yaml.v2 v2.4.0 // indirect
25+
k8s.io/klog/v2 v2.130.1 // indirect
26+
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
27+
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
28+
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
29+
)

0 commit comments

Comments
 (0)