-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
261 lines (219 loc) · 8.75 KB
/
Makefile
File metadata and controls
261 lines (219 loc) · 8.75 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
# OpenFero Makefile for CRD and API management
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOMOD=$(GOCMD) mod
# Kubernetes/Controller parameters
CONTROLLER_GEN=$(GOCMD) run sigs.k8s.io/controller-tools/cmd/controller-gen
CRD_OPTIONS=crd:headerFile="hack/boilerplate.yaml.txt"
OBJECT_OPTIONS=object:headerFile="hack/boilerplate.go.txt"
# Directories
API_DIR=./api/...
CRD_DIR=charts/openfero/crds
.PHONY: help
help: ## Show this help message
@echo 'Usage: make [target]'
@echo ''
@echo 'Targets:'
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " %-15s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
.PHONY: generate
generate: ## Generate CRDs and DeepCopy methods
$(CONTROLLER_GEN) $(OBJECT_OPTIONS) paths=$(API_DIR)
$(CONTROLLER_GEN) $(CRD_OPTIONS) paths=$(API_DIR) output:crd:artifacts:config=$(CRD_DIR)
.PHONY: manifests
manifests: generate ## Generate CRD manifests (alias for generate)
.PHONY: test
test: ## Run tests
$(GOTEST) -v ./pkg/...
.PHONY: test-short
test-short: ## Run tests with -short flag
$(GOTEST) -v ./... -short
.PHONY: test-operarius
test-operarius: ## Run Operarius-specific tests
$(GOTEST) -v ./pkg/services -run TestOperarius
.PHONY: test-coverage
test-coverage: ## Run tests with coverage report
$(GOTEST) -coverprofile=coverage.out -covermode=atomic ./...
$(GOCMD) tool cover -html=coverage.out -o coverage.html
.PHONY: dev
dev: ## Run local development environment (backend with air, frontend with vite)
@echo "Starting local development environment..."
@echo "Backend will run on http://localhost:8080"
@echo "Frontend will run on http://localhost:5173"
@trap 'kill %1' INT; \
$(HOME)/go/bin/air & \
cd frontend && npm run dev
# E2E Test configuration
KIND_CLUSTER_NAME ?= openfero-e2e
OPENFERO_IMG ?= openfero:e2e-test
KIND ?= kind
E2E_NAMESPACE ?= openfero
.PHONY: test-e2e
test-e2e: test-e2e-setup ## Run E2E tests (requires Kind)
KIND=$(KIND) KIND_CLUSTER=$(KIND_CLUSTER_NAME) E2E_NAMESPACE=$(E2E_NAMESPACE) $(GOTEST) -v -tags=e2e ./test/e2e/... -timeout 30m
.PHONY: test-e2e-setup
test-e2e-setup: ## Set up Kind cluster for E2E tests
@command -v $(KIND) >/dev/null 2>&1 || { \
echo "Kind is not installed. Please install Kind manually."; \
exit 1; \
}
@case "$$($(KIND) get clusters)" in \
*"$(KIND_CLUSTER_NAME)"*) \
echo "Kind cluster '$(KIND_CLUSTER_NAME)' already exists. Skipping creation." ;; \
*) \
echo "Creating Kind cluster '$(KIND_CLUSTER_NAME)'..."; \
$(KIND) create cluster --name $(KIND_CLUSTER_NAME) ;; \
esac
@echo "Setting kubectl context..."
@kubectl cluster-info --context kind-$(KIND_CLUSTER_NAME)
@echo "Building OpenFero binary (static)..."
$(MAKE) build-static
@echo "Building OpenFero image..."
docker build -t $(OPENFERO_IMG) -f goreleaser.dockerfile .
@echo "Loading image into Kind..."
$(KIND) load docker-image $(OPENFERO_IMG) --name $(KIND_CLUSTER_NAME)
@echo "Installing CRDs..."
kubectl apply --server-side --context kind-$(KIND_CLUSTER_NAME) -f $(CRD_DIR)/
@echo "Deploying OpenFero..."
helm upgrade --install openfero charts/openfero \
--kube-context kind-$(KIND_CLUSTER_NAME) \
--namespace $(E2E_NAMESPACE) \
--create-namespace \
--set image.repository=openfero \
--set image.tag=e2e-test \
--set image.pullPolicy=Never \
--set serviceMonitor.enabled=false \
--wait --timeout 120s
@echo "OpenFero deployed successfully"
.PHONY: test-e2e-teardown
test-e2e-teardown: ## Tear down Kind cluster used for E2E tests
@echo "Deleting Kind cluster $(KIND_CLUSTER_NAME)..."
$(KIND) delete cluster --name $(KIND_CLUSTER_NAME)
.PHONY: build
build: ## Build the OpenFero binary
$(GOBUILD) -o openfero .
.PHONY: build-static
build-static: ## Build statically linked OpenFero binary for containers
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GOBUILD) -ldflags="-s -w" -o openfero .
.PHONY: clean
clean: ## Clean build artifacts
$(GOCLEAN)
rm -f openfero
.PHONY: deps
deps: ## Download and verify dependencies
$(GOMOD) download
$(GOMOD) verify
.PHONY: tidy
tidy: ## Clean up go.mod and go.sum
$(GOMOD) tidy
.PHONY: fmt
fmt: ## Format Go code
$(GOCMD) fmt ./...
.PHONY: vet
vet: ## Run go vet
$(GOCMD) vet ./...
.PHONY: lint
lint: fmt vet ## Run formatting and vetting
.PHONY: install-crds
install-crds: manifests ## Install CRDs into the current Kubernetes cluster
kubectl apply --server-side -f $(CRD_DIR)/
.PHONY: uninstall-crds
uninstall-crds: ## Uninstall CRDs from the current Kubernetes cluster
kubectl delete -f $(CRD_DIR)/ --ignore-not-found=true
.PHONY: sample-operarius
sample-operarius: ## Apply sample Operarius resources
kubectl apply -f $(SAMPLE_DIR)/openfero_v1alpha1_operarius_kubequota.yaml
kubectl apply -f $(SAMPLE_DIR)/openfero_v1alpha1_operarius_podrestart.yaml
.PHONY: delete-samples
delete-samples: ## Delete sample Operarius resources
kubectl delete -f $(SAMPLE_DIR)/ --ignore-not-found=true
.PHONY: validate-crds
validate-crds: ## Validate CRD YAML files
@echo "Validating CRD files..."
@for file in $(CRD_DIR)/*.yaml; do \
echo "Validating $$file"; \
kubectl --dry-run=client apply -f $$file; \
done
.PHONY: docs
docs: ## Generate documentation for APIs
@echo "API documentation is available in the generated CRD files"
@echo "Use 'kubectl explain operarius' after installing CRDs"
.PHONY: dev-setup
dev-setup: deps generate ## Set up development environment
@echo "Development environment set up!"
@echo "Run 'make install-crds' to install CRDs in your cluster"
.PHONY: ci
ci: lint test build ## Run CI pipeline locally
# Show CRD status in cluster
.PHONY: crd-status
crd-status: ## Show status of OpenFero CRDs in cluster
@echo "OpenFero CRDs in cluster:"
@kubectl get crd | grep openfero.io || echo "No OpenFero CRDs found"
@echo ""
@echo "Operarius resources:"
@kubectl get operarius -A || echo "No Operarius resources found"
# Debug target to show generated CRDs
.PHONY: show-crds
show-crds: ## Show generated CRD content
@echo "Generated CRD files:"
@ls -la $(CRD_DIR)/
@echo ""
@echo "Sample files:"
@ls -la $(SAMPLE_DIR)/
# Migration helper
.PHONY: migration-check
migration-check: ## Check for ConfigMap-based operarios that need migration
@echo "Checking for existing ConfigMap-based operarios..."
@kubectl get configmap -l app=openfero -A || echo "No openfero ConfigMaps found"
# Benchmark configuration
BENCH_COUNT ?= 5
BENCH_TIME ?= 5s
BENCH_TIMEOUT ?= 30m
BENCH_PATTERN ?= .
GO_OLD ?= 1.25.6
GO_NEW ?= 1.26.2
.PHONY: benchmark
benchmark: ## Run Go benchmarks locally
$(GOTEST) -bench=$(BENCH_PATTERN) -benchmem -benchtime=$(BENCH_TIME) -count=$(BENCH_COUNT) -timeout=$(BENCH_TIMEOUT) -run='^$$' ./pkg/services/ ./pkg/alertstore/memory/
.PHONY: benchmark-short
benchmark-short: ## Run quick benchmarks (1 iteration, 1s)
$(GOTEST) -bench=$(BENCH_PATTERN) -benchmem -benchtime=1s -count=1 -timeout=10m -run='^$$' ./pkg/services/ ./pkg/alertstore/memory/
.PHONY: benchmark-save
benchmark-save: ## Run benchmarks and save results to file
@mkdir -p benchmark-results
$(GOTEST) -bench=$(BENCH_PATTERN) -benchmem -benchtime=$(BENCH_TIME) -count=$(BENCH_COUNT) -timeout=$(BENCH_TIMEOUT) -run='^$$' ./pkg/services/ ./pkg/alertstore/memory/ | tee benchmark-results/bench-$$(date +%Y%m%d_%H%M%S).txt
.PHONY: benchmark-docker
benchmark-docker: ## Run benchmarks in Docker (Go version comparison)
./hack/run-benchmarks.sh $(GO_OLD) $(GO_NEW)
.PHONY: benchmark-analyze
benchmark-analyze: ## Analyze benchmark results (requires two result files)
@echo "Usage: make benchmark-analyze OLD=<old.txt> NEW=<new.txt>"
@echo "Example: make benchmark-analyze OLD=benchmark-results/go-1.25.5.txt NEW=benchmark-results/go-1.26.txt"
@test -n "$(OLD)" -a -n "$(NEW)" || { echo "Error: OLD and NEW must be set"; exit 1; }
$(GOCMD) run hack/benchanalyze/main.go -old $(OLD) -new $(NEW) -output benchmark-results/ -old-label "Go $(GO_OLD)" -new-label "Go $(GO_NEW)"
.PHONY: benchmark-visualize
benchmark-visualize: ## Generate charts from benchmark comparison JSON
@echo "Usage: make benchmark-visualize JSON=<comparison.json>"
@test -n "$(JSON)" || { echo "Error: JSON must be set (e.g. JSON=benchmark-results/comparison.json)"; exit 1; }
python3 hack/visualize-benchmarks.py $(JSON)
.PHONY: run-local-docker
run-local-docker: ## Build frontend, build docker image, and run locally connected to Kind
@echo "Building frontend..."
cd frontend && npm install && npm run build
@echo "Building static binary..."
$(MAKE) build-static
@echo "Building docker image..."
docker build -t openfero:local -f goreleaser.dockerfile .
@echo "Running openfero:local connected to Kind..."
docker run --rm --net=host -u 0 \
-v $(HOME)/.kube/config:/root/.kube/config \
-e KUBECONFIG=/root/.kube/config \
openfero:local \
--logLevel=debug \
--kubeconfig=/root/.kube/config \
--useOperariusCRDs=true \
--configmapNamespace=openfero \
--jobDestinationNamespace=openfero