-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
279 lines (218 loc) · 9.19 KB
/
Makefile
File metadata and controls
279 lines (218 loc) · 9.19 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
271
272
273
274
275
276
277
278
279
.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: fmt
fmt: ## Run go fmt against code
go fmt ./...
.PHONY: vet
vet: ## Run go vet against code
go vet ./...
.PHONY: goimport
goimport:
go install golang.org/x/tools/cmd/goimports@latest
goimports -w -local="kubevirt.io,github.com/kubevirt,github.com/kubevirt/hyperconverged-cluster-operator" $(shell find . -type f -name '*.go' ! -path "*/vendor/*" ! -path "./_kubevirtci/*" ! -path "*zz_generated*" )
.PHONY: test
test: fmt vet goimport ## Run unit tests
go test ./pkg/... -coverprofile cover.out
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.35.0
ENVTEST = $(shell pwd)/bin/setup-envtest
GINKGO = $(shell pwd)/bin/ginkgo
# Tool versions derived from go.mod to stay in sync with the module dependency graph.
# setup-envtest lives in a sub-module (tools/setup-envtest) that does not share the
# parent module's vX.Y.Z tags. We use the branch reference (e.g. release-0.23) instead,
# which is how the sub-module is published and what `go install @<branch>` resolves to.
CONTROLLER_RUNTIME_BRANCH := $(shell grep 'sigs.k8s.io/controller-runtime ' go.mod | awk '{print $$2}' | sed 's/v\([0-9]*\.[0-9]*\)\..*/release-\1/')
GINKGO_VERSION := $(shell grep 'github.com/onsi/ginkgo/v2 ' go.mod | awk '{print $$2}')
.PHONY: test-integration
test-integration: envtest ginkgo ## Run integration tests with envtest
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(shell pwd)/bin -p path)" $(GINKGO) -v --trace ./test/
.PHONY: test-e2e
test-e2e: docker-build ## Run E2E tests on kind cluster
./hack/run-e2e.sh
.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary
$(ENVTEST): $(LOCALBIN)
GOBIN=$(shell pwd)/bin go install sigs.k8s.io/controller-runtime/tools/setup-envtest@$(CONTROLLER_RUNTIME_BRANCH)
.PHONY: ginkgo
ginkgo: $(GINKGO) ## Download ginkgo locally if necessary
$(GINKGO): $(LOCALBIN)
GOBIN=$(shell pwd)/bin go install github.com/onsi/ginkgo/v2/ginkgo@$(GINKGO_VERSION)
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
# Container tool - auto-detects docker or podman, or can be overridden
# Usage: make docker-build
# CONTAINER_TOOL=podman make docker-build
CONTAINER_TOOL ?= $(shell command -v docker 2>/dev/null || command -v podman 2>/dev/null)
ifeq ($(CONTAINER_TOOL),)
$(error Neither docker nor podman found in PATH. Please install one of them.)
endif
##@ Build
.PHONY: build
build: fmt vet ## Build manager binary and csv-generator
go build -o bin/manager cmd/main.go
go build -o bin/csv-generator cmd/csv-generator/main.go
.PHONY: build-csv-gen
build-csv-gen: fmt vet ## Build csv-generator binary only
go build -o bin/csv-generator cmd/csv-generator/main.go
.PHONY: generate-csv
generate-csv: build-csv-gen ## Generate sample CSV to stdout (for inspection)
@echo "Generating ClusterServiceVersion..."
@bin/csv-generator --csv-version=0.0.1 --operator-image=quay.io/openshift-virtualization/virt-platform-autopilot:latest
.PHONY: run
run: fmt vet ## Run from your host
go run cmd/main.go
IMAGE_REGISTRY ?= quay.io/openshift-virtualization
IMAGE_TAG ?= latest
OPERATOR_IMAGE ?= $(IMAGE_REGISTRY)/virt-platform-autopilot:$(IMAGE_TAG)
.PHONY: docker-build
docker-build: ## Build container image (local arch only)
$(CONTAINER_TOOL) build -t $(IMAGE_NAME) .
.PHONY: docker-push
docker-push: ## Push container image
$(CONTAINER_TOOL) push $(IMAGE_NAME)
.PHONY: build-push-multi-arch
build-push-multi-arch: ## Build and push multi-arch operator image (amd64, arm64, s390x)
IMAGE_NAME=$(OPERATOR_IMAGE) DOCKER_FILE=Dockerfile ./hack/build-push-multi-arch-images.sh
##@ Deployment
.PHONY: deploy
deploy: ## Deploy controller to the cluster
kubectl apply -k config/default
.PHONY: undeploy
undeploy: ## Undeploy controller from the cluster
kubectl delete -k config/default
##@ Code Generation
.PHONY: generate-rbac
generate-rbac: ## Generate RBAC from assets
@echo "Generating RBAC from assets..."
@go run cmd/rbac-gen/main.go
.PHONY: verify-rbac
verify-rbac: ## Verify RBAC matches generated (for CI)
@echo "Verifying RBAC is up-to-date..."
@go run cmd/rbac-gen/main.go --dry-run > /tmp/generated-rbac.yaml
@if ! diff -u config/rbac/role.yaml /tmp/generated-rbac.yaml; then \
echo ""; \
echo "❌ ERROR: RBAC is out of sync with assets!"; \
echo ""; \
echo "The committed config/rbac/role.yaml does not match the generated RBAC."; \
echo ""; \
echo "To fix:"; \
echo " 1. Run: make generate-rbac"; \
echo " 2. Commit the updated config/rbac/role.yaml"; \
echo ""; \
rm -f /tmp/generated-rbac.yaml; \
exit 1; \
fi
@rm -f /tmp/generated-rbac.yaml
@echo "✓ RBAC is up-to-date"
.PHONY: update-crds
update-crds: ## Update CRD collection from upstream
hack/update-crds.sh
.PHONY: verify-crds
verify-crds: ## Verify CRDs match upstream (for CI)
@echo "Verifying CRDs match upstream..."
@hack/update-crds.sh --verify
.PHONY: validate-crds
validate-crds: ## Validate CRDs can be loaded (parser check)
@echo "Validating CRDs can be parsed..."
@go test ./test/crd_test.go -v
##@ Dependencies
.PHONY: tidy
tidy: ## Run go mod tidy
go mod tidy
.PHONY: vendor
vendor: ## Run go mod vendor
go mod vendor
##@ Linting
GOLANGCI_LINT ?= $(shell which golangci-lint)
ifeq ($(GOLANGCI_LINT),)
GOLANGCI_LINT = $(shell go env GOPATH)/bin/golangci-lint
endif
.PHONY: lint
lint: ## Run golangci-lint
@if ! command -v $(GOLANGCI_LINT) >/dev/null 2>&1; then \
echo "golangci-lint v2 not found. Installing..."; \
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest; \
fi
$(GOLANGCI_LINT) run
SHELLCHECK ?= $(shell which shellcheck)
.PHONY: shellcheck
shellcheck: ## Run shellcheck on all shell scripts
@if ! command -v shellcheck >/dev/null 2>&1; then \
echo "shellcheck not found. Please install it:"; \
echo " On Fedora/RHEL: sudo dnf install shellcheck"; \
echo " On Ubuntu/Debian: sudo apt-get install shellcheck"; \
echo " On macOS: brew install shellcheck"; \
exit 1; \
fi
@echo "Running shellcheck on hack/ scripts..."
@find hack -name '*.sh' -type f -exec shellcheck -x {} +
##@ Observability
.PHONY: test-alerts
test-alerts: ## Test Prometheus alert rules with promtool
@hack/test-alert-rules.sh
.PHONY: lint-metrics
lint-metrics: ## Lint Prometheus metric naming conventions with prom-metrics-linter
./hack/prom_metric_linter.sh --operator-name="kubevirt" --sub-operator-name="autopilot"
##@ Local Development (Kind)
CLUSTER_NAME ?= virt-platform-autopilot
IMAGE_NAME ?= virt-platform-autopilot:latest
.PHONY: kind-setup
kind-setup: ## Setup local Kind cluster with CRDs and mock HCO
CLUSTER_NAME=$(CLUSTER_NAME) ./hack/kind-cluster.sh setup
.PHONY: kind-create
kind-create: ## Create local Kind cluster
CLUSTER_NAME=$(CLUSTER_NAME) ./hack/kind-cluster.sh create
.PHONY: kind-delete
kind-delete: ## Delete local Kind cluster
CLUSTER_NAME=$(CLUSTER_NAME) ./hack/kind-cluster.sh delete
.PHONY: kind-status
kind-status: ## Check Kind cluster status
CLUSTER_NAME=$(CLUSTER_NAME) ./hack/kind-cluster.sh status
.PHONY: kind-install-crds
kind-install-crds: ## Install CRDs into Kind cluster
CLUSTER_NAME=$(CLUSTER_NAME) ./hack/kind-cluster.sh install-crds
.PHONY: kind-create-mock-hco
kind-create-mock-hco: ## Create mock HCO instance
CLUSTER_NAME=$(CLUSTER_NAME) ./hack/kind-cluster.sh create-mock-hco
.PHONY: kind-load
kind-load: docker-build ## Build and load operator image into Kind
CLUSTER_NAME=$(CLUSTER_NAME) IMAGE_NAME=$(IMAGE_NAME) ./hack/deploy-local.sh load
.PHONY: deploy-local
deploy-local: ## Deploy operator to local Kind cluster (full)
CLUSTER_NAME=$(CLUSTER_NAME) IMAGE_NAME=$(IMAGE_NAME) ./hack/deploy-local.sh deploy
.PHONY: redeploy-local
redeploy-local: ## Quick redeploy to Kind (rebuild + restart)
CLUSTER_NAME=$(CLUSTER_NAME) IMAGE_NAME=$(IMAGE_NAME) ./hack/deploy-local.sh redeploy
.PHONY: undeploy-local
undeploy-local: ## Undeploy operator from Kind cluster
CLUSTER_NAME=$(CLUSTER_NAME) ./hack/deploy-local.sh undeploy
.PHONY: logs-local
logs-local: ## Tail operator logs from Kind cluster
kubectl logs -f -n openshift-cnv \
-l app=virt-platform-autopilot \
--context kind-$(CLUSTER_NAME) \
--tail=100
.PHONY: status-local
status-local: ## Show operator status in Kind cluster
CLUSTER_NAME=$(CLUSTER_NAME) ./hack/deploy-local.sh status
.PHONY: debug-local
debug-local: ## Show debugging info for local deployment
@echo "=== Cluster Info ==="
kubectl cluster-info --context kind-$(CLUSTER_NAME)
@echo ""
@echo "=== Operator Pods ==="
kubectl get pods -n openshift-cnv --context kind-$(CLUSTER_NAME)
@echo ""
@echo "=== HyperConverged CR ==="
kubectl get hyperconverged -n openshift-cnv --context kind-$(CLUSTER_NAME) -o wide
@echo ""
@echo "=== Managed Resources ==="
kubectl get machineconfigs,kubeletconfigs,nodehealthchecks --context kind-$(CLUSTER_NAME)
##@ All-in-one targets
.PHONY: all
all: fmt vet test build ## Build and test everything
.PHONY: dev-cycle
dev-cycle: fmt vet test redeploy-local ## Full dev cycle: format, test, redeploy