-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathMakefile
More file actions
320 lines (244 loc) · 11.1 KB
/
Makefile
File metadata and controls
320 lines (244 loc) · 11.1 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
# Copyright 2024 Stefan Prodan.
# SPDX-License-Identifier: AGPL-3.0
# Makefile for building, testing, and deploying the Flux Operator, CLI and MCP server.
# Image URL to use for all building/pushing image targets
IMG ?= ghcr.io/controlplaneio-fluxcd/flux-operator:latest
FLUX_OPERATOR_VERSION ?= $(shell gh release view --json tagName -q '.tagName')
FLUX_OPERATOR_DEV_VERSION?=0.0.0-$(shell git rev-parse --abbrev-ref HEAD)-$(shell git rev-parse --short HEAD)-$(shell date +%s)
FLUX_VERSION = $(shell gh release view --repo fluxcd/flux2 --json tagName -q '.tagName')
ENVTEST_K8S_VERSION = 1.35.0
# 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.
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: test lint build cli-build mcp-build ## Run all build and test targets.
##@ Development
.PHONY: generate
generate: controller-gen ## Generate deep copies and CRDs from API types.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
$(CONTROLLER_GEN) rbac:roleName=manager-role crd paths="./..." output:crd:artifacts:config=config/crd/bases
.PHONY: fmt
fmt: web-fmt ## Run go fmt and ESLint fix against code.
go fmt ./...
.PHONY: vet
vet: ## Run go vet against code.
go vet ./...
.PHONY: tidy
tidy: ## Run go mod tidy.
go mod tidy
.PHONY: test
test: tidy generate fmt vet envtest ## Run all unit tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $$(go list ./... | grep -v -e /e2e -e /olm) -coverprofile cover.out
.PHONY: test-e2e
test-e2e: ## Run the e2e tests on the Kind cluster.
go test ./test/e2e/ -v -ginkgo.v
.PHONY: lint
lint: web-lint golangci-lint ## Run golangci linters and ESLint.
$(GOLANGCI_LINT) run
.PHONY: lint-fix
lint-fix: golangci-lint ## Run golangci linters and perform fixes.
$(GOLANGCI_LINT) run --fix
##@ Build
.PHONY: build
build: generate fmt vet web-build build-only ## Build the flux-operator binary with frontend assets.
.PHONY: build-only ## Build the flux-operator binary.
build-only:
CGO_ENABLED=0 GOFIPS140=latest go build -ldflags="-s -w -X main.VERSION=$(FLUX_OPERATOR_DEV_VERSION)" -o ./bin/flux-operator ./cmd/operator/
.PHONY: run
run: generate fmt vet web-build ## Run the flux-operator locally.
CGO_ENABLED=0 GOFIPS140=latest go run ./cmd/operator/main.go --enable-leader-election=false
.PHONY: docker-build
docker-build: web-build ## Build flux-operator docker image.
$(CONTAINER_TOOL) build -t ${IMG} --build-arg VERSION=$(FLUX_OPERATOR_DEV_VERSION) .
.PHONY: docker-build-push
docker-build-push: web-build ## Build flux-operator docker image and push.
$(CONTAINER_TOOL) buildx build -t ${IMG} \
--platform=linux/amd64,linux/arm64 \
--build-arg VERSION=$(FLUX_OPERATOR_DEV_VERSION) \
--push .
.PHONY: docker-push
docker-push: ## Push flux-operator docker image.
$(CONTAINER_TOOL) push ${IMG}
.PHONY: build-installer
build-installer: generate kustomize ## Generate a consolidated YAML with CRDs and deployment.
mkdir -p dist
$(KUSTOMIZE) build config/default > dist/install.yaml
.PHONY: build-manifests
build-manifests: ## Generate release manifests with CRDs, RBAC and deployment.
hack/build-dist-manifests.sh
.PHONY: vendor-flux
vendor-flux: ## Download Flux base manifests and image patches to config/flux dir.
hack/vendor-flux-manifests.sh $(FLUX_VERSION)
##@ Frontend
.PHONY: web-test
web-test: web-lint ## Run frontend tests.
cd web && npm test
.PHONY: web-lint
web-lint: ## Run ESLint on frontend code.
cd web && npm run lint
.PHONY: web-fmt
web-fmt: ## Run ESLint fix on frontend code.
cd web && npm run lint:fix
.PHONY: web-install
web-install: ## Install frontend dependencies.
cd web && npm install
.PHONY: web-ci-install
web-ci-install: ## Install frontend dependencies in CI (uses npm ci).
cd web && npm ci
.PHONY: web-dev
web-dev: ## Start frontend dev server connected to backend.
cd web && npm run dev
.PHONY: web-dev-mock
web-dev-mock: ## Start frontend dev server with mock data enabled.
cd web && VITE_USE_MOCK_DATA=true npm run dev
WEB_RUN_ARGS ?=
.PHONY: web-run
web-run: build ## Start operator with frontend server only.
./bin/flux-operator --log-level=debug --web-server-only --web-server-port=9080 $(WEB_RUN_ARGS)
.PHONY: web-build
web-build: web-fmt ## Build frontend for production.
cd web && npm run build
##@ OLM
OLM_VERSION ?= 0.28.0
.PHONY: build-olm-manifests
build-olm-manifests: ## Generate OLM manifests for OperatorHub.
./hack/build-olm-manifests.sh $(FLUX_OPERATOR_VERSION:v%=%)
.PHONY: build-olm-manifests-ubi
build-olm-manifests-ubi: ## Generate OLM manifests for Red Hat Marketplace.
./hack/build-olm-manifests.sh $(FLUX_OPERATOR_VERSION:v%=%) true
.PHONY: docker-build-ubi
docker-build-ubi: ## Build flux-operator docker image using UBI base image.
$(CONTAINER_TOOL) build -t ${IMG}-ubi --build-arg VERSION=$(FLUX_OPERATOR_VERSION) -f config/olm/build/Dockerfile .
.PHONY: test-olm-e2e
test-olm-e2e: build-olm-manifests operator-sdk ## Test OLM manifests for current version.
./hack/build-olm-images.sh $(FLUX_OPERATOR_VERSION:v%=%)
export OLM_VERSION=${OLM_VERSION} && \
export FLUX_OPERATOR_VERSION=$(FLUX_OPERATOR_VERSION:v%=%) && \
export OPERATOR_SDK_BIN=$(OPERATOR_SDK) && \
go test ./test/olm/ -v -ginkgo.v
##@ CLI
CLI_IMG ?= ghcr.io/controlplaneio-fluxcd/flux-operator-cli:latest
.PHONY: cli-test
cli-test: tidy fmt vet ## Run CLI tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./cmd/cli/... -v
.PHONY: cli-build
cli-build: tidy fmt vet ## Build CLI binary.
CGO_ENABLED=0 go build -ldflags="-s -w -X main.VERSION=$(FLUX_OPERATOR_DEV_VERSION)" -o ./bin/flux-operator-cli ./cmd/cli/
.PHONY: cli-docker-build
cli-docker-build: ## Build docker image with the CLI.
$(CONTAINER_TOOL) build -t ${CLI_IMG} --build-arg VERSION=$(FLUX_OPERATOR_VERSION) -f cmd/cli/Dockerfile .
##@ MCP
MCP_IMG ?= ghcr.io/controlplaneio-fluxcd/flux-operator-mcp:latest
.PHONY: mcp-build-search-index
mcp-build-search-index: ## Build search index for MCP docs tool.
@echo "Building MCP search index..."
@mkdir -p cmd/mcp/toolbox/library
@go run cmd/mcp/toolbox/indexer/main.go
@echo "MCP search index built successfully"
.PHONY: mcp-test
mcp-test: tidy fmt vet ## Run MCP tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./cmd/mcp/... -v
.PHONY: mcp-build
mcp-build: tidy fmt vet ## Build MCP server binary.
CGO_ENABLED=0 go build -ldflags="-s -w -X main.VERSION=$(FLUX_OPERATOR_DEV_VERSION)" -o ./bin/flux-operator-mcp ./cmd/mcp/
.PHONY: mcp-docker-build
mcp-docker-build: ## Build docker image with the MCP server.
$(CONTAINER_TOOL) build -t ${MCP_IMG} --build-arg VERSION=$(FLUX_OPERATOR_VERSION) -f cmd/mcp/Dockerfile .
##@ Deployment
ifndef ignore-not-found
ignore-not-found = false
endif
.PHONY: load-image
load-image: ## Load flux-operator image into the local Kind cluster.
kind load docker-image ${IMG}
.PHONY: install
install: generate kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | $(KUBECTL) apply -f -
.PHONY: uninstall
uninstall: generate kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/crd | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
.PHONY: deploy
deploy: generate kustomize ## Deploy flux-operator to the K8s cluster specified in ~/.kube/config.
mkdir -p config/dev && cp config/default/* config/dev
cd config/dev && $(KUSTOMIZE) edit set image ghcr.io/controlplaneio-fluxcd/flux-operator=${IMG}
$(KUSTOMIZE) build config/dev | $(KUBECTL) apply -f -
rm -rf config/dev
.PHONY: undeploy
undeploy: kustomize ## Delete flux-operator from the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) build config/default | $(KUBECTL) delete --ignore-not-found=$(ignore-not-found) -f -
##@ Release
NEXT_VERSION ?= ""
.PHONY: prep-release
prep-release: ## Create release PR for the next version (auto minor bump).
hack/vendor-flux-manifests.sh $(FLUX_VERSION)
hack/prep-release.sh $(NEXT_VERSION)
.PHONY: release
release: ## Create a release for the next version.
@next=$(shell yq '.images[0].newTag' "config/manager/kustomization.yaml") && \
git tag -s -m "$$next" "$$next" && \
git push origin "$$next"
##@ Dependencies
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
## Tool Binaries
KUBECTL ?= kubectl
KUSTOMIZE ?= $(LOCALBIN)/kustomize-$(KUSTOMIZE_VERSION)
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen-$(CONTROLLER_TOOLS_VERSION)
ENVTEST ?= $(LOCALBIN)/setup-envtest-$(ENVTEST_VERSION)
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION)
OPERATOR_SDK ?= $(LOCALBIN)/operator-sdk-$(OPERATOR_SDK_VERSION)
## Tool Versions
KUSTOMIZE_VERSION ?= v5.8.0
CONTROLLER_TOOLS_VERSION ?= v0.20.0
ENVTEST_VERSION ?= $(shell go list -m -f "{{ .Version }}" sigs.k8s.io/controller-runtime | awk -F'[v.]' '{printf "release-%d.%d", $$2, $$3}')
GOLANGCI_LINT_VERSION ?= v2.9.0
OPERATOR_SDK_VERSION ?= v1.41.1
.PHONY: operator-sdk
operator-sdk: $(OPERATOR_SDK) ## Download operator-sdk locally if necessary.
$(OPERATOR_SDK): $(LOCALBIN)
./hack/install-operator-sdk.sh $(OPERATOR_SDK_VERSION)
.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
$(KUSTOMIZE): $(LOCALBIN)
$(call go-install-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v5,$(KUSTOMIZE_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: envtest
envtest: $(ENVTEST) ## Download setup-envtest locally if necessary.
$(ENVTEST): $(LOCALBIN)
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION))
.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/v2/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION))
# 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 (ideally with version)
# $2 - package url which can be installed
# $3 - specific version of package
define go-install-tool
@[ -f $(1) ] || { \
set -e; \
package=$(2)@$(3) ;\
echo "Downloading $${package}" ;\
GOBIN=$(LOCALBIN) go install $${package} ;\
mv "$$(echo "$(1)" | sed "s/-$(3)$$//")" $(1) ;\
}
endef
##@ 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%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)