-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathMakefile
More file actions
270 lines (219 loc) · 8.98 KB
/
Makefile
File metadata and controls
270 lines (219 loc) · 8.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# Image URL to use all building/pushing image targets
HUB ?= ghcr.io/volcano-sh
TAG ?= latest
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
# CONTAINER_TOOL defines the container tool to be used for building images.
# Be aware that the target commands are only tested with Docker which is
# scaffolded by default. However, you might want to replace it to use other
# tools. (i.e. podman)
CONTAINER_TOOL ?= docker
# Setting SHELL to bash allows bash commands to be executed by recipes.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec
.PHONY: all
all: build
##@ General
# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk command is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php
.PHONY: help
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Development
.PHONY: gen-crd
gen-crd: controller-gen
$(CONTROLLER_GEN) crd paths="./pkg/apis/networking/..." output:crd:artifacts:config=charts/kthena/charts/networking/crds
$(CONTROLLER_GEN) crd paths="./pkg/apis/workload/..." output:crd:artifacts:config=charts/kthena/charts/workload/crds
.PHONY: gen-docs
gen-docs: crd-ref-docs helm-docs ## Generate CRD and CLI reference documentation
# Generate CRD ref docs
mkdir -p docs/kthena/docs/api
$(CRD_REF_DOCS) \
--source-path=./pkg/apis \
--config=docs/kthena/crd-ref-docs-config.yaml \
--output-path=docs/kthena/docs/reference/crd \
--renderer=markdown \
--output-mode=group
# Generate Kthena CLI docs using a standalone doc-gen program
go run ./cli/kthena/internal/tools/docgen/main.go
# Generate Helm Chart docs
$(HELM_DOCS) \
--chart-search-root=charts/kthena \
--template-files=charts/kthena/README.md.gotmpl \
--dry-run \
> docs/kthena/docs/reference/helm-chart-values.md
.PHONY: generate
generate: gen-crd ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
go mod tidy
./hack/update-codegen.sh
$(MAKE) gen-docs
$(MAKE) gen-copyright
.PHONY: gen-check
gen-check: generate
git diff --exit-code
.PHONY: test
test: generate ## Run tests. Exclude e2e, client-go.
go test $$(go list ./... | grep -v /e2e | grep -v /client-go) -coverprofile cover.out
.PHONY: test-docs
test-docs: ## Run documentation tests (type check and build)
cd docs/kthena && npm run typecheck
cd docs/kthena && npm run build
.PHONY: test-e2e
test-e2e: ## Run the e2e tests. Expected an isolated environment using Kind.
@command -v kind >/dev/null 2>&1 || { \
echo "Kind is not installed. Please install Kind manually."; \
exit 1; \
}
@echo "Setting up Kind cluster for E2E tests..."
@./test/e2e/setup.sh
@echo "Running E2E tests sequentially..."
@KUBECONFIG=/tmp/kubeconfig-e2e go test -p 1 $$(go list ./... | grep /test/e2e) -v -timeout=15m
@echo "E2E tests completed"
.PHONY: test-e2e-cleanup
test-e2e-cleanup: ## Clean up the Kind cluster used for E2E tests.
@./test/e2e/cleanup.sh
.PHONY: lint
lint: golangci-lint ## Run golangci-lint linter
$(GOLANGCI_LINT) run
.PHONY: lint-fix
lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes
$(GOLANGCI_LINT) run --fix
.PHONY: lint-python
lint-python: ## Run python linter
pip install ruff
ruff check . --config python/kthena/pyproject.toml
.PHONY: fmt
fmt: ## Run go fmt against code.
go fmt ./...
.PHONY: vet
vet: ## Run go vet against code.
go vet ./...
##@ Build
.PHONY: build
build: generate fmt vet
go build -o bin/kthena-router cmd/kthena-router/main.go
go build -o bin/kthena-controller-manager cmd/kthena-controller-manager/main.go
go build -o bin/kthena cli/kthena/main.go
IMG_CONTROLLER ?= ${HUB}/kthena-controller-manager:${TAG}
IMG_ROUTER ?= ${HUB}/kthena-router:${TAG}
IMG_DOWNLOADER ?= ${HUB}/downloader:${TAG}
IMG_RUNTIME ?= ${HUB}/runtime:${TAG}
.PHONY: docker-build-router
docker-build-router: generate
$(CONTAINER_TOOL) build -t ${IMG_ROUTER} -f docker/Dockerfile.kthena-router .
.PHONY: docker-build-controller
docker-build-controller: generate
$(CONTAINER_TOOL) build -t ${IMG_CONTROLLER} -f docker/Dockerfile.kthena-controller-manager .
.PHONY: docker-build-downloader
docker-build-downloader: generate
$(CONTAINER_TOOL) build -t ${IMG_DOWNLOADER} --target downloader -f python/Dockerfile python
.PHONY: docker-build-runtime
docker-build-runtime: generate
$(CONTAINER_TOOL) build -t ${IMG_RUNTIME} --target runtime -f python/Dockerfile python
.PHONY: docker-build-all
docker-build-all: docker-build-router docker-build-controller docker-build-downloader docker-build-runtime## Build all images.
@echo "All images built."
.PHONY: docker-push
docker-push: docker-build-router docker-build-controller ## Push all images to the registry.
$(CONTAINER_TOOL) push ${IMG_ROUTER}
$(CONTAINER_TOOL) push ${IMG_CONTROLLER}
# PLATFORMS defines the target platforms for the images be built to provide support to multiple
# architectures.
PLATFORMS ?= linux/arm64,linux/amd64
# Make sure Buildx is set up:
# docker buildx create --name mybuilder --driver docker-container --use
# docker buildx inspect --bootstrap
.PHONY: docker-buildx
docker-buildx: ## Build and push docker image for cross-platform support
$(CONTAINER_TOOL) buildx build \
--platform ${PLATFORMS} \
-t ${IMG_ROUTER} \
-f docker/Dockerfile.kthena-router \
--push .
$(CONTAINER_TOOL) buildx build \
--platform ${PLATFORMS} \
-t ${IMG_CONTROLLER} \
-f docker/Dockerfile.kthena-controller-manager \
--push .
##@ Dependencies
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
## Tool Binaries
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint
CRD_REF_DOCS ?= $(LOCALBIN)/crd-ref-docs
HELM_DOCS ?= $(LOCALBIN)/helm-docs
## Tool Versions
CONTROLLER_TOOLS_VERSION ?= v0.17.2
GOLANGCI_LINT_VERSION ?= v1.64.8
CRD_REF_DOCS_VERSION ?= v0.2.0
HELM_DOCS_VERSION ?= v1.14.2
.PHONY: golangci-lint
golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary.
$(GOLANGCI_LINT): $(LOCALBIN)
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
$(CONTROLLER_GEN): $(LOCALBIN)
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen,$(CONTROLLER_TOOLS_VERSION))
.PHONY: crd-ref-docs
crd-ref-docs: $(CRD_REF_DOCS) ## Download crd-ref-docs locally if necessary.
$(CRD_REF_DOCS): $(LOCALBIN)
$(call go-install-tool,$(CRD_REF_DOCS),github.com/elastic/crd-ref-docs,$(CRD_REF_DOCS_VERSION))
.PHONY: helm-docs
helm-docs: $(HELM_DOCS) ## Download helm-docs locally if necessary.
$(HELM_DOCS): $(LOCALBIN)
$(call go-install-tool,$(HELM_DOCS),github.com/norwoodj/helm-docs/cmd/helm-docs,$(HELM_DOCS_VERSION))
.PHONY: gen-copyright
gen-copyright:
@echo "Adding copyright headers..."
@hack/update-copyright.sh
mod-download-go:
@-GOFLAGS="-mod=readonly" find -name go.mod -execdir go mod download \;
# go mod tidy is needed with Golang 1.16+ as go mod download affects go.sum
# https://github.com/golang/go/issues/43994
# exclude docs folder
@find . -path ./docs -prune -o -name go.mod -execdir go mod tidy \;
.PHONY: mirror-licenses
mirror-licenses: mod-download-go; \
go install istio.io/tools/cmd/license-lint@v0.0.0-20240221165422-57f6bfb4cd73; \
rm -fr licenses; \
license-lint --mirror
.PHONY: lint-licenses
lint-licenses:
@if test -d licenses; then license-lint --config config/licenses-lint.yaml; fi
.PHONY: licenses-check
licenses-check: mirror-licenses; \
hack/licenses-check.sh
# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
# $1 - target path with name of binary
# $2 - package url which can be installed
# $3 - specific version of package
define go-install-tool
@[ -f "$(1)-$(3)" ] || { \
set -e; \
package=$(2)@$(3) ;\
echo "Downloading $${package}" ;\
rm -f $(1) || true ;\
GOBIN=$(LOCALBIN) go install $${package} ;\
mv $(1) $(1)-$(3) ;\
} ;\
ln -sf $(1)-$(3) $(1)
endef