-
Notifications
You must be signed in to change notification settings - Fork 305
Expand file tree
/
Copy pathMakefile
More file actions
450 lines (364 loc) · 16.3 KB
/
Makefile
File metadata and controls
450 lines (364 loc) · 16.3 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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
SHELL:=/usr/bin/env bash
RUN_NAMESPACE = metal3
GO_TEST_FLAGS = $(TEST_FLAGS)
DEBUG = --debug
COVER_PROFILE = cover.out
GO := $(shell type -P go)
GO_VERSION ?= 1.25.9
ROOT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
# CRD Generation Options
#
# allowDangerousTypes=true lets use the float64 field for clock speeds
# crdVersions=v1 generates the v1 version of the CRD type
#
# NOTE: Assumes the default is preserveUnknownFields=false with
# crdVersions=v1, so that the API server discards "extra" data
# instead of storing it
#
#
BIN_DIR := bin
TOOLS_DIR := hack/tools
TOOLS_BIN_DIR := $(abspath $(TOOLS_DIR)/$(BIN_DIR))
CRD_OPTIONS ?= "crd:allowDangerousTypes=true,crdVersions=v1"
KUSTOMIZE = tools/bin/kustomize
CONTROLLER_GEN = tools/bin/controller-gen
GINKGO = tools/bin/ginkgo
DEPLOY_CLI = tools/bin/deploy-cli
CONTAINER_RUNTIME = docker
# See pkg/version.go for details
SOURCE_GIT_COMMIT ?= $(shell git rev-parse --short HEAD)
BUILD_VERSION ?= $(shell git describe --always --abbrev=40 --dirty)
VERSION_URI = "github.com/metal3-io/baremetal-operator/pkg/version"
export LDFLAGS="-X $(VERSION_URI).Raw=${BUILD_VERSION} \
-X $(VERSION_URI).Commit=${SOURCE_GIT_COMMIT} \
-X $(VERSION_URI).BuildTime=$(shell date +%Y-%m-%dT%H:%M:%S%z)"
# Set some variables the operator expects to have in order to work
# Those need to be the same as in config/default/ironic.env
export OPERATOR_NAME=baremetal-operator
export DEPLOY_KERNEL_URL=http://172.22.0.1:6180/images/ironic-python-agent.kernel
export DEPLOY_RAMDISK_URL=http://172.22.0.1:6180/images/ironic-python-agent.initramfs
export IRONIC_ENDPOINT=http://localhost:6385/v1/
export GO111MODULE=on
export GOFLAGS=
#
# Ginkgo configuration.
#
GINKGO_FOCUS ?=
GINKGO_SKIP ?=
GINKGO_SKIP_LABELS ?=
GINKGO_NODES ?= 2
GINKGO_TIMEOUT ?= 3h
GINKGO_POLL_PROGRESS_AFTER ?= 60m
GINKGO_POLL_PROGRESS_INTERVAL ?= 5m
E2E_CONF_FILE ?= $(ROOT_DIR)/test/e2e/config/fixture.yaml
E2E_BMCS_CONF_FILE ?= $(ROOT_DIR)/test/e2e/config/bmcs-fixture.yaml
USE_EXISTING_CLUSTER ?= false
SKIP_RESOURCE_CLEANUP ?= false
GINKGO_NOCOLOR ?= false
GOLANGCI_LINT_BIN := golangci-lint
GOLANGCI_LINT_VER := v2.10.1
GOLANGCI_LINT := $(abspath $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_BIN))
GOLANGCI_LINT_PKG := github.com/golangci/golangci-lint/v2/cmd/golangci-lint
# to set multiple ginkgo skip flags, if any
ifneq ($(strip $(GINKGO_SKIP)),)
_SKIP_ARGS := $(foreach arg,$(strip $(GINKGO_SKIP)),-skip="$(arg)")
endif
# to set multiple ginkgo skip labels, if any
ifneq ($(strip $(GINKGO_SKIP_LABELS)),)
_SKIP_LABELS_ARGS := --label-filter="!$(GINKGO_SKIP_LABELS)"
endif
.PHONY: help
help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
@echo
@echo "Variables:"
@echo " TEST_NAMESPACE -- project name to use ($(TEST_NAMESPACE))"
@echo " SETUP -- controls the --no-setup flag ($(SETUP))"
@echo " GO_TEST_FLAGS -- flags to pass to --go-test-flags ($(GO_TEST_FLAGS))"
@echo " DEBUG -- debug flag, if any ($(DEBUG))"
# Image URL to use all building/pushing image targets
REGISTRY ?= quay.io/metal3-io
IMG_NAME ?= baremetal-operator
IMG_TAG ?= latest
IMG ?= $(REGISTRY)/$(IMG_NAME)
ARCH ?= $(shell go env GOARCH)
ALL_ARCH = amd64
# Which configuration to use when deploying (from the config directory)
DEPLOY_CONFIG ?= default
## --------------------------------------
## Test Targets
## --------------------------------------
# Run tests
.PHONY: test
test: generate lint manifests unit ## Run common developer tests
.PHONY: unit
unit: ## Run unit tests
go test ./... $(GO_TEST_FLAGS) -coverprofile $(COVER_PROFILE)
cd apis/ && go test ./... $(GO_TEST_FLAGS) -coverprofile $(COVER_PROFILE)
cd pkg/hardwareutils && go test ./... $(GO_TEST_FLAGS) -coverprofile $(COVER_PROFILE)
.PHONY: unit-cover
unit-cover: ## Run unit tests with code coverage
go test -coverprofile=$(COVER_PROFILE) $(GO_TEST_FLAGS) ./...
go tool cover -func=$(COVER_PROFILE)
cd apis/ && go test -coverprofile=$(COVER_PROFILE) $(GO_TEST_FLAGS) ./...
cd apis/ && go tool cover -func=$(COVER_PROFILE)
cd pkg/hardwareutils/ && go test -coverprofile=$(COVER_PROFILE) $(GO_TEST_FLAGS) ./...
cd pkg/hardwareutils/ && go tool cover -func=$(COVER_PROFILE)
.PHONY: unit-verbose
unit-verbose: ## Run unit tests with verbose output
TEST_FLAGS=-v make unit
FUZZ_TIME ?= 30s
.PHONY: fuzz
fuzz: ## Run fuzz tests with seed corpus (no fuzzing, regression test only)
cd test/fuzz && go test --race -v ./...
.PHONY: fuzz-run
fuzz-run: ## Run all fuzz tests sequentially with fuzzing enabled (use FUZZ_TIME=duration)
@echo "Discovering fuzz tests..."
@cd test/fuzz && go test -list='Fuzz.*' | grep '^Fuzz' | while read -r fuzz_test; do \
echo "Running $$fuzz_test for $(FUZZ_TIME)..."; \
go test -fuzz=$$fuzz_test -fuzztime='$(FUZZ_TIME)' || exit 1; \
done
@echo "All fuzz tests completed successfully!"
ARTIFACTS ?= ${ROOT_DIR}/test/e2e/_artifacts
.PHONY: verify-e2e-prerequisites
verify-e2e-prerequisites: ## Check that required tools exist for e2e tests
@echo "Ensure the local environment is ready for e2e tests..."
VERIFY_ONLY=1 ./hack/e2e/ensure_e2e_prerequisites.sh
.PHONY: test-e2e
test-e2e: $(GINKGO) ## Run the end-to-end tests
$(GINKGO) -v --trace -poll-progress-after=$(GINKGO_POLL_PROGRESS_AFTER) \
-poll-progress-interval=$(GINKGO_POLL_PROGRESS_INTERVAL) --tags=e2e,vbmctl --focus="$(GINKGO_FOCUS)" \
$(_SKIP_ARGS) $(_SKIP_LABELS_ARGS) --nodes=$(GINKGO_NODES) --timeout=$(GINKGO_TIMEOUT) --no-color=$(GINKGO_NOCOLOR) \
--output-dir="$(ARTIFACTS)" --junit-report="junit.e2e_suite.1.xml" $(GINKGO_ARGS) test/e2e -- \
-e2e.config="$(E2E_CONF_FILE)" -e2e.bmcsConfig="$(E2E_BMCS_CONF_FILE)" \
-e2e.use-existing-cluster=$(USE_EXISTING_CLUSTER) \
-e2e.skip-resource-cleanup=$(SKIP_RESOURCE_CLEANUP) -e2e.artifacts-folder="$(ARTIFACTS)"
## --------------------------------------
## Linter Targets
## --------------------------------------
.PHONY: linters
linters: lint generate-check
$(GOLANGCI_LINT):
GOBIN=$(TOOLS_BIN_DIR) go install $(GOLANGCI_LINT_PKG)@$(GOLANGCI_LINT_VER)
.PHONY: $(GOLANGCI_LINT_BIN)
$(GOLANGCI_LINT_BIN): $(GOLANGCI_LINT) ## Build a local copy of golangci-lint.
.PHONY: lint
lint: $(GOLANGCI_LINT)
$(GOLANGCI_LINT) run -v $(GOLANGCI_LINT_EXTRA_ARGS) ./... --timeout=10m
cd apis; $(GOLANGCI_LINT) run -v $(GOLANGCI_LINT_EXTRA_ARGS) ./... --timeout=10m
cd test; $(GOLANGCI_LINT) run -v $(GOLANGCI_LINT_EXTRA_ARGS) ./... --timeout=10m
cd pkg/hardwareutils; $(GOLANGCI_LINT) run -v $(GOLANGCI_LINT_EXTRA_ARGS) ./... --timeout=10m
cd hack/tools; $(GOLANGCI_LINT) run -v $(GOLANGCI_LINT_EXTRA_ARGS) ./... --timeout=10m
./hack/check-e2e.sh
.PHONY: lint-fix
lint-fix: $(GOLANGCI_LINT) ## Lint the codebase and run auto-fixers if supported by the linter
GOLANGCI_LINT_EXTRA_ARGS=--fix $(MAKE) lint
.PHONY: manifest-lint
manifest-lint: ## Run manifest validation
./hack/manifestlint.sh
## --------------------------------------
## Build/Run Targets
## --------------------------------------
.PHONY: build
build: generate manifests manager tools build-e2e ## Build everything
.PHONY: manager
manager: generate lint ## Build manager binary
go build -ldflags $(LDFLAGS) -o bin/$(OPERATOR_NAME) main.go
.PHONY: run
run: generate lint manifests ## Run against the configured Kubernetes cluster in ~/.kube/config
go run -ldflags $(LDFLAGS) ./main.go -namespace=$(RUN_NAMESPACE) -dev -webhook-port=0 $(RUN_FLAGS)
.PHONY: demo
demo: generate lint manifests ## Run in demo mode
go run -ldflags $(LDFLAGS) ./main.go -namespace=$(RUN_NAMESPACE) -dev -demo-mode -webhook-port=0 $(RUN_FLAGS)
.PHONY: run-test-mode
run-test-mode: generate lint manifests ## Run against the configured Kubernetes cluster in ~/.kube/config
go run -ldflags $(LDFLAGS) ./main.go -namespace=$(RUN_NAMESPACE) -dev -test-mode -webhook-port=0 $(RUN_FLAGS)
.PHONY: install
install: $(KUSTOMIZE) manifests ## Install CRDs into a cluster
$< build config/base/crds | kubectl apply -f -
.PHONY: uninstall
uninstall: $(KUSTOMIZE) manifests ## Uninstall CRDs from a cluster
$< build config/base/crds | kubectl delete -f -
.PHONY: deploy
deploy: $(KUSTOMIZE) manifests ## Deploy controller in the configured Kubernetes cluster in ~/.kube/config
make set-manifest-image-bmo MANIFEST_IMG=$(IMG_NAME) MANIFEST_TAG=$(IMG_TAG)
$< build config/$(DEPLOY_CONFIG) | kubectl apply -f -
$(CONTROLLER_GEN): hack/tools/go.mod
cd hack/tools; go build -o $(abspath $@) sigs.k8s.io/controller-tools/cmd/controller-gen
$(KUSTOMIZE): hack/tools/go.mod
cd hack/tools; go build -o $(abspath $@) sigs.k8s.io/kustomize/kustomize/v5
.PHONY: deploy-cli
deploy-cli:
cd hack/tools/deploy-cli; go build -o $(abspath $(DEPLOY_CLI))
.PHONY: build-e2e
build-e2e:
cd test; go build --tags=e2e ./...
.PHONY: build-vbmctl
build-vbmctl:
cd test; go build --tags=e2e,vbmctl -ldflags $(LDFLAGS) -o $(abspath $(BIN_DIR)/vbmctl) ./vbmctl/cmd/vbmctl
.PHONY: unit-vbmctl
unit-vbmctl: ## Run vbmctl unit tests
cd test && go test --tags=e2e,vbmctl $(GO_TEST_FLAGS) ./vbmctl/...
.PHONY: manifests
manifests: manifests-generate manifests-kustomize ## Generate manifests e.g. CRD, RBAC etc.
.PHONY: manifests-generate
manifests-generate: $(CONTROLLER_GEN)
cd apis; $(abspath $<) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:webhook:dir=../config/base/webhook/ output:crd:artifacts:config=../config/base/crds/bases
$< rbac:roleName=manager-role paths="./..." output:rbac:artifacts:config=config/base/rbac
.PHONY: manifests-kustomize
manifests-kustomize: $(KUSTOMIZE)
$< build config/default > config/render/capm3.yaml
.PHONY: set-manifest-pull-policy
set-manifest-pull-policy:
$(info Updating kustomize pull policy file for manager resource)
sed -i'' -e 's@imagePullPolicy: .*@imagePullPolicy: '"$(PULL_POLICY)"'@' ./config/base/manager.yaml
.PHONY: set-manifest-image-bmo
set-manifest-image-bmo: $(KUSTOMIZE) manifests
$(info Updating container image for BMO to use ${MANIFEST_IMG}:${MANIFEST_TAG})
sed -i'' -e 's@image: .*@image: \"'"${MANIFEST_IMG}:$(MANIFEST_TAG)"'\"@' ./config/base/manager.yaml
.PHONY: set-manifest-image-ironic
set-manifest-image-ironic: $(KUSTOMIZE) manifests
$(info Updating container image for Ironic to use ${MANIFEST_IMG}:${MANIFEST_TAG})
cd ironic-deployment/base && $(abspath $(KUSTOMIZE)) edit set image quay.io/metal3-io/ironic=${MANIFEST_IMG}:${MANIFEST_TAG}
.PHONY: set-manifest-image-mariadb
set-manifest-image-mariadb: $(KUSTOMIZE) manifests
$(info Updating container image for Mariadb to use ${MANIFEST_IMG}:${MANIFEST_TAG})
cd ironic-deployment/components/mariadb && $(abspath $(KUSTOMIZE)) edit set image quay.io/metal3-io/mariadb=${MANIFEST_IMG}:${MANIFEST_TAG}
.PHONY: set-manifest-image-keepalived
set-manifest-image-keepalived: $(KUSTOMIZE) manifests
$(info Updating container image for keepalived to use ${MANIFEST_IMG}:${MANIFEST_TAG})
cd ironic-deployment/components/keepalived && $(abspath $(KUSTOMIZE)) edit set image quay.io/metal3-io/keepalived=${MANIFEST_IMG}:${MANIFEST_TAG}
.PHONY: set-manifest-image-ipa-downloader
set-manifest-image-ipa-downloader: $(KUSTOMIZE) manifests
$(info Updating container image for IPA downloader to use ${MANIFEST_IMG}:${MANIFEST_TAG})
cd ironic-deployment/base && $(abspath $(KUSTOMIZE)) edit set image quay.io/metal3-io/ironic-ipa-downloader=${MANIFEST_IMG}:${MANIFEST_TAG}
.PHONY: generate
generate: $(CONTROLLER_GEN) ## Generate code
cd apis; $(abspath $<) object:headerFile="../hack/boilerplate.go.txt" paths="./..."
$< object:headerFile="hack/boilerplate.go.txt" paths="./..."
## --------------------------------------
## Docker Targets
## --------------------------------------
.PHONY: docker
docker: docker-build ## Alias for docker-build (for backwards compatibility)
docker-build: generate manifests ## Build the docker image for controller-manager
$(CONTAINER_RUNTIME) build --platform=linux/$(ARCH) \
--build-arg ARCH=$(ARCH) \
--build-arg http_proxy=$(http_proxy) \
--build-arg https_proxy=$(https_proxy) \
. -t ${IMG}-$(ARCH):${IMG_TAG}
@# Tag with base image name for backward compatibility (amd64 is the default)
@if [ "$(ARCH)" = "amd64" ]; then \
$(CONTAINER_RUNTIME) tag ${IMG}-$(ARCH):${IMG_TAG} ${IMG}:${IMG_TAG}; \
fi
.PHONY: docker-debug
docker-debug: generate manifests ## Build the docker image with debug info
$(CONTAINER_RUNTIME) build --platform=linux/$(ARCH) \
--build-arg ARCH=$(ARCH) \
--build-arg http_proxy=$(http_proxy) \
--build-arg https_proxy=$(https_proxy) \
--build-arg LDFLAGS="-extldflags=-static" \
. -t ${IMG}-$(ARCH):${IMG_TAG}
## --------------------------------------
## Docker — All ARCH
## --------------------------------------
.PHONY: docker-build-all
docker-build-all: $(addprefix docker-build-,$(ALL_ARCH)) ## Build all the architecture docker images
docker-build-%:
$(MAKE) ARCH=$* docker-build
## --------------------------------------
## CI Targets
## --------------------------------------
.PHONY: generate-check
generate-check:
./hack/generate.sh
.PHONY: generate-check-local
generate-check-local:
IS_CONTAINER=local ./hack/generate.sh
## --------------------------------------
## Documentation
## --------------------------------------
.PHONY: docs
docs: $(patsubst %.dot,%.png,$(wildcard docs/*.dot))
%.png: %.dot
dot -Tpng $< >$@
## --------------------------------------
## Tool apps
## --------------------------------------
.PHONY: tools
tools:
go build -o bin/get-hardware-details cmd/get-hardware-details/main.go
go build -o bin/make-bm-worker cmd/make-bm-worker/main.go
go build -o bin/make-virt-host cmd/make-virt-host/main.go
$(GINKGO): ## Install ginkgo in tools/bin. Take ginkgo version from `test/go.mod`.
cd test; GOBIN=$(abspath tools/bin) go install github.com/onsi/ginkgo/v2/ginkgo
## --------------------------------------
## Tilt / Kind
## --------------------------------------
.PHONY: kind-create
kind-create: ## create bmo kind cluster if needed
./hack/kind_with_registry.sh
.PHONY: tilt-up
tilt-up: $(KUSTOMIZE) kind-create ## start tilt and build kind cluster if needed
tilt up
.PHONY: kind-reset
kind-reset: ## Destroys the "bmo" kind cluster.
kind delete cluster --name=bmo || true
## --------------------------------------
## Go module Targets
## --------------------------------------
.PHONY:
mod: ## Clean up go module settings
go mod tidy
go mod verify
cd apis; go mod tidy
cd apis; go mod verify
cd pkg/hardwareutils; go mod tidy
cd pkg/hardwareutils; go mod verify
cd hack/tools; go mod tidy
cd hack/tools; go mod verify
cd test; go mod tidy
cd test; go mod verify
## --------------------------------------
## Release
## --------------------------------------
RELEASE_TAG ?= $(shell git describe --abbrev=0 2>/dev/null)
ifneq (,$(findstring -,$(RELEASE_TAG)))
PRE_RELEASE=true
endif
# the previous release tag, e.g., v1.7.0, excluding pre-release tags
PREVIOUS_TAG ?= $(shell git tag -l | grep -E "^v[0-9]+\.[0-9]+\.[0-9]+" | sort -V | grep -B1 $(RELEASE_TAG) | grep -E "^v[0-9]+\.[0-9]+\.[0-9]+$$" | head -n 1 2>/dev/null)
RELEASE_DIR := out
RELEASE_NOTES_DIR := releasenotes
$(RELEASE_DIR):
mkdir -p $(RELEASE_DIR)/
$(RELEASE_NOTES_DIR):
mkdir -p $(RELEASE_NOTES_DIR)/
.PHONY: release-notes
release-notes: $(RELEASE_NOTES_DIR) $(RELEASE_NOTES)
cd hack/tools && $(GO) run release/notes.go --releaseTag=$(RELEASE_TAG) > $(realpath $(RELEASE_NOTES_DIR))/$(RELEASE_TAG).md
.PHONY: release-manifests
release-manifests: $(KUSTOMIZE) $(RELEASE_DIR) ## Builds the manifests to publish with a release
$(KUSTOMIZE) build config > $(RELEASE_DIR)/baremetal-operator.yaml
.PHONY: release
release:
@if [ -z "${RELEASE_TAG}" ]; then echo "RELEASE_TAG is not set"; exit 1; fi
@if ! [ -z "$$(git status --porcelain)" ]; then echo "You have uncommitted changes"; exit 1; fi
git checkout "${RELEASE_TAG}"
MANIFEST_IMG=$(IMG) MANIFEST_TAG=$(RELEASE_TAG) $(MAKE) set-manifest-image-bmo
PULL_POLICY=IfNotPresent $(MAKE) set-manifest-pull-policy
$(MAKE) release-manifests
$(MAKE) release-notes
go-version: ## Print the go version we use to compile our binaries and images
@echo $(GO_VERSION)
## --------------------------------------
## Clean
## --------------------------------------
.PHONY: clean
clean: ## Remove all temporary files, directories and tools
rm -rf ironic-deployment/overlays/temp
rm -rf config/overlays/temp
rm -rf $(TOOLS_BIN_DIR)
.PHONY: clean-e2e
clean-e2e: ## Remove everything related to e2e tests
./hack/clean-e2e.sh