-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMakefile
More file actions
235 lines (183 loc) · 7.14 KB
/
Copy pathMakefile
File metadata and controls
235 lines (183 loc) · 7.14 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
# Makefile for secure-inference
# Build params
PROJECT_NAME ?= secure-inference
CGO_ENABLED ?= 0
export GO111MODULE=on
# Container runtime
CONTAINER_RUNTIME ?= docker
# Image names
REGISTRY ?= ghcr.io/llm-d
IMAGE ?= $(REGISTRY)/$(PROJECT_NAME)
IMG ?= $(PROJECT_NAME):latest
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
PLATFORMS ?= linux/amd64
# Sidecars to build/load: comma-separated <folder>=<image> pairs
# Example: SIDECARS=adapter-selection=adapter-selection:latest
SIDECARS ?=
# Helpers to parse SIDECARS entries
sidecar_dir = $(word 1,$(subst =, ,$(1)))
sidecar_img = $(word 2,$(subst =, ,$(1)))
comma := ,
# Go configuration
GOFLAGS ?=
LDFLAGS ?= -s -w -X main.version=$(VERSION)
# Directories
LOCALBIN ?= $(shell pwd)/bin
CHART_DIR = ./charts/secure-inference
# Demo/deployment env variables
MINIKUBE_PROFILE ?= minikube
GATEWAY_TYPE ?= istio
K8S_NAMESPACE ?= llm-d-inference-scheduler
LLMD_HTTP_ROUTE ?= llm-d-inference-scheduling
LLMD_GATEWAY_NAME ?= infra-inference-scheduling-inference-gateway
# Tools
GOLANGCI_LINT_VERSION ?= v2.10.1
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
CONTROLLER_TOOLS_VERSION ?= v0.18.0
ENVTEST ?= $(LOCALBIN)/setup-envtest
ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
ENVTEST_K8S_VERSION ?= $(shell go list -m -f "{{ .Version }}" k8s.io/api | awk -F'[v.]' '{printf "1.%d", $$3}')
.DEFAULT_GOAL := help
##@ General
.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%-20s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Development
.PHONY: fmt
fmt: ## Format Go and Python code
gofmt -w .
@if ls *.py **/*.py 2>/dev/null | head -1 > /dev/null 2>&1; then \
ruff format .; \
fi
.PHONY: vet
vet: ## Run go vet
go vet ./...
.PHONY: tidy
tidy: ## Run go mod tidy
go mod tidy
.PHONY: lint
lint: lint-go lint-python ## Run all linters
.PHONY: lint-go
lint-go: ## Run Go linter (golangci-lint v2)
golangci-lint run
.PHONY: lint-python
lint-python: ## Run Python linter (ruff) — skipped if no Python files found
@if ls *.py **/*.py 2>/dev/null | head -1 > /dev/null 2>&1; then \
ruff check . && ruff format --check .; \
else \
echo "No Python files found, skipping Python lint"; \
fi
.PHONY: pre-commit
pre-commit: ## Run pre-commit hooks on all files
pre-commit run --all-files
##@ Code Generation
.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
$(CONTROLLER_GEN): $(LOCALBIN)
@test -s $(LOCALBIN)/controller-gen || \
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)
$(LOCALBIN):
mkdir -p $(LOCALBIN)
.PHONY: manifests
manifests: controller-gen ## Generate CRD manifests
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./api/..." output:crd:artifacts:config=config/crd/bases
.PHONY: generate
generate: controller-gen ## Generate code (DeepCopy)
$(CONTROLLER_GEN) object paths="./api/..."
.PHONY: setup-envtest
setup-envtest: $(ENVTEST) ## Download setup-envtest locally if necessary.
$(ENVTEST): $(LOCALBIN)
@test -s $(LOCALBIN)/setup-envtest || \
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@$(ENVTEST_VERSION)
##@ Build
.PHONY: build
build: ## Build secure-inference binary
CGO_ENABLED=$(CGO_ENABLED) go build $(GOFLAGS) -ldflags "$(LDFLAGS)" -o bin/$(PROJECT_NAME) ./cmd/secure-inference
.PHONY: build-cli
build-cli: ## Build llmd-admin CLI binary
CGO_ENABLED=$(CGO_ENABLED) go build -o bin/llmd-admin ./cmd/llmd-admin
.PHONY: build-deployment-customizer
build-deployment-customizer: ## Build deployment-customizer binary
CGO_ENABLED=$(CGO_ENABLED) go build -o bin/deployment-customizer ./cmd/deployment-customizer
.PHONY: build-all
build-all: build build-cli build-deployment-customizer ## Build all binaries
##@ Docker Images
.PHONY: image-build
image-build: ## Build Docker images (main + SIDECARS)
$(CONTAINER_RUNTIME) build --platform $(PLATFORMS) --rm --tag $(IMG) -f Dockerfile .
$(foreach s,$(subst $(comma), ,$(SIDECARS)), \
$(CONTAINER_RUNTIME) build --rm \
--tag $(call sidecar_img,$(s)) \
-f sidecar/$(call sidecar_dir,$(s))/Dockerfile \
sidecar/$(call sidecar_dir,$(s)) ;)
.PHONY: image-push
image-push: ## Build and push multi-arch container image
$(CONTAINER_RUNTIME) buildx build \
--platform $(PLATFORMS) \
--push \
--annotation "index:org.opencontainers.image.source=https://github.com/llm-d/$(PROJECT_NAME)" \
--annotation "index:org.opencontainers.image.licenses=Apache-2.0" \
--tag $(IMAGE):$(VERSION) \
--tag $(IMAGE):latest \
.
##@ Testing
.PHONY: test
test: setup-envtest ## Run unit tests
KUBEBUILDER_ASSETS="$$($(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN)/k8s -p path)" \
go test -race -count=1 ./pkg/...
.PHONY: test-coverage
test-coverage: setup-envtest ## Run tests with coverage report
KUBEBUILDER_ASSETS="$$($(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN)/k8s -p path)" \
go test -race -coverprofile=coverage.out -covermode=atomic ./pkg/...
go tool cover -html=coverage.out -o coverage.html
.PHONY: test-e2e
test-e2e: ## Run e2e tests
go test -race -count=1 ./test/e2e/... -v
.PHONY: test-all
test-all: test test-e2e ## Run all tests
##@ Deployment
.PHONY: install-crds
install-crds: manifests ## Install CRDs to cluster
kubectl apply -k config/crd
.PHONY: uninstall-crds
uninstall-crds: ## Uninstall CRDs from cluster
kubectl delete -k config/crd
HELM_VALUES ?=
HELM_SETS = --set image=$(IMG) \
--set gateway=$(GATEWAY_TYPE) \
--set target_http_route=$(LLMD_HTTP_ROUTE) \
--set gateway_name=$(LLMD_GATEWAY_NAME)
.PHONY: deploy-helm
deploy-helm: ## Deploy using Helm chart
helm install $(PROJECT_NAME) $(CHART_DIR) \
$(if $(HELM_VALUES),-f $(HELM_VALUES),$(HELM_SETS)) \
--namespace $(K8S_NAMESPACE)
.PHONY: upgrade-helm
upgrade-helm: ## Upgrade Helm deployment
helm upgrade $(PROJECT_NAME) $(CHART_DIR) \
$(if $(HELM_VALUES),-f $(HELM_VALUES),$(HELM_SETS)) \
--namespace $(K8S_NAMESPACE)
.PHONY: uninstall-helm
uninstall-helm: ## Uninstall Helm deployment
helm uninstall $(PROJECT_NAME) --namespace $(K8S_NAMESPACE)
##@ Minikube
.PHONY: load-images-minikube
load-images-minikube: ## Load images to Minikube (main + SIDECARS)
minikube image load $(IMG) -p $(MINIKUBE_PROFILE)
$(foreach s,$(subst $(comma), ,$(SIDECARS)), \
minikube image load $(call sidecar_img,$(s)) -p $(MINIKUBE_PROFILE) ;)
##@ Full Deployment
.PHONY: deploy
deploy: ## Deploy all components to cluster
./bin/llmd-admin init
kubectl create secret generic llm-d-access --from-file=publickey=./certs/llm-d-ca.pem -n $(K8S_NAMESPACE) --dry-run=client -o yaml | kubectl apply -f -
kubectl apply -k config/crd
$(MAKE) deploy-helm
##@ CI Helpers
.PHONY: ci-lint
ci-lint: ## CI: install and run golangci-lint
@which golangci-lint > /dev/null 2>&1 || go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
golangci-lint run
.PHONY: clean
clean: ## Remove build artifacts
rm -rf bin/ coverage.out coverage.html