-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
252 lines (212 loc) · 9.05 KB
/
Makefile
File metadata and controls
252 lines (212 loc) · 9.05 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
# Image URL to use all building/pushing image targets
IMG ?= quix-environment-operator:latest
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.28.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
# 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
## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
## Tool Binaries
ENVTEST ?= $(LOCALBIN)/setup-envtest
.PHONY: all
all: build
##@ General
# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk commands is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php
.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: manifests
manifests: ## Generate CRDs and RBAC manifests
@echo "Cleaning CRD directory..."
@mkdir -p config/crd/bases
@rm -f config/crd/bases/*.yaml
@echo "Generating CRDs using controller-gen..."
$(LOCALBIN)/controller-gen crd:crdVersions=v1 rbac:roleName=manager-role paths="./api/..." output:crd:artifacts:config=config/crd/bases
@echo "CRD generation complete."
.PHONY: generate
generate: ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
@echo "Generating DeepCopy code..."
$(LOCALBIN)/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./api/..."
@echo "Generated files:"
# @ls -ls ./api | grep "zz_"
@echo "DeepCopy code generation complete."
.PHONY: fmt
fmt: ## Run go fmt against code.
go fmt ./...
.PHONY: vet
vet: ## Run go vet against code.
go vet ./...
.PHONY: test
test: manifests generate fmt vet ## Run tests.
$(eval export KUBEBUILDER_ASSETS=$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path))
@echo "Using KUBEBUILDER_ASSETS: $(KUBEBUILDER_ASSETS)"
make test-unit test-integration
.PHONY: test-unit
test-unit: ## Run unit tests.
$(eval export KUBEBUILDER_ASSETS=$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path))
mkdir -p ./coverlet
go test ./... -v -coverprofile=./coverlet/cover-unit.out
.PHONY: test-integration
test-integration: manifests ## Run integration tests.
$(eval export KUBEBUILDER_ASSETS=$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path))
mkdir -p ./coverlet
go test ./... -v -coverprofile=./coverlet/cover-integration.out -tags=integration
.PHONY: docker-test
docker-test: ## Run all tests in Docker container.
@echo "Running all tests in Docker container..."
@if ! command -v docker &> /dev/null; then \
echo "Error: Docker is required but not found. Please install Docker first."; \
exit 1; \
fi
@chmod +x build/run-tests.sh
./build/run-tests.sh all
.PHONY: docker-test-unit
docker-test-unit: ## Run only unit tests in Docker container.
@echo "Running unit tests in Docker container..."
@if ! command -v docker &> /dev/null; then \
echo "Error: Docker is required but not found. Please install Docker first."; \
exit 1; \
fi
@chmod +x build/run-tests.sh
./build/run-tests.sh unit
.PHONY: docker-test-integration
docker-test-integration: ## Run only integration tests in Docker container.
@echo "Running integration tests in Docker container..."
@if ! command -v docker &> /dev/null; then \
echo "Error: Docker is required but not found. Please install Docker first."; \
exit 1; \
fi
@chmod +x build/run-tests.sh
./build/run-tests.sh integration
##@ Build
.PHONY: generate-crds
generate-crds: ## Generate CRD files
@echo "Regenerating CRD files..."
@mkdir -p config/crd/bases
@rm -f config/crd/bases/*.yaml
@echo "Generating CRDs using controller-gen..."
$(LOCALBIN)/controller-gen \
crd:crdVersions=v1 \
paths="./api/..." \
output:crd:artifacts:config=config/crd/bases
@echo "CRD files regenerated successfully"
.PHONY: helm-copy-crds
helm-copy-crds: generate-crds ## Copy CRDs to Helm chart templates directory
@echo "Copying CRDs to Helm chart templates directory..."
@mkdir -p deploy/quix-environment-operator/templates
@cp config/crd/bases/quix.io_environments.yaml deploy/quix-environment-operator/templates/crds.yaml
@echo "CRDs copied successfully"
.PHONY: build
build: generate-crds generate fmt vet helm-copy-crds ## Build manager binary.
go build -o bin/operator cmd/operator/main.go
# If you wish built the manager image targeting other platforms you can use the --platform flag.
# (i.e. docker build --platform linux/arm64 ). However, you must enable docker buildKit for it.
# More info: https://docs.docker.com/develop/develop-images/build_enhancements/
.PHONY: docker-build
docker-build: ## Build docker image with the manager.
docker build -t ${IMG} . -f build/dockerfile
.PHONY: docker-push
docker-push: ## Push docker image with the manager.
docker push ${IMG}
##@ Deployment
ifndef ignore-not-found
ignore-not-found = false
endif
.PHONY: install
install: manifests ## Install CRDs into the K8s cluster specified in ~/.kube/config.
@echo "Current kubectl context: $$(kubectl config current-context)"
@if [ "$(FORCE)" != "true" ]; then \
read -p "Continue installing CRDs into this cluster? [y/N] " confirm; \
if [ "$${confirm}" != "y" ] && [ "$${confirm}" != "Y" ]; then \
echo "Installation aborted."; \
exit 1; \
fi; \
fi
kubectl apply -f config/crd/bases/
.PHONY: uninstall
uninstall: ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config.
@echo "Current kubectl context: $$(kubectl config current-context)"
@if [ "$(FORCE)" != "true" ]; then \
read -p "Continue uninstalling CRDs from this cluster? [y/N] " confirm; \
if [ "$${confirm}" != "y" ] && [ "$${confirm}" != "Y" ]; then \
echo "Uninstallation aborted."; \
exit 1; \
fi; \
fi
kubectl delete --ignore-not-found=$(ignore-not-found) -f config/crd/bases/
.PHONY: deploy
deploy: manifests ## Deploy controller to the K8s cluster specified in ~/.kube/config.
@echo "Current kubectl context: $$(kubectl config current-context)"
@if [ "$(FORCE)" != "true" ]; then \
read -p "Continue deploying controller to this cluster? [y/N] " confirm; \
if [ "$${confirm}" != "y" ] && [ "$${confirm}" != "Y" ]; then \
echo "Deployment aborted."; \
exit 1; \
fi; \
fi
helm upgrade --install quix-environment-operator ./deploy/quix-environment-operator \
--namespace quix-operator --create-namespace \
--set image.repository=$(shell echo ${IMG} | cut -d: -f1) \
--set image.tag=$(shell echo ${IMG} | cut -d: -f2)
.PHONY: undeploy
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config.
@echo "Current kubectl context: $$(kubectl config current-context)"
@if [ "$(FORCE)" != "true" ]; then \
read -p "Continue undeploying controller from this cluster? [y/N] " confirm; \
if [ "$${confirm}" != "y" ] && [ "$${confirm}" != "Y" ]; then \
echo "Undeployment aborted."; \
exit 1; \
fi; \
fi
helm uninstall quix-environment-operator -n quix-operator
.PHONY: helm-package
helm-package: ## Package the Helm chart.
@echo "Packaging Helm chart..."
@mkdir -p ./helm
@helm package ./deploy/quix-environment-operator -d ./helm
.PHONY: helm-lint
helm-lint: ## Validate the Helm chart.
@echo "Linting Helm chart..."
@helm lint ./deploy/quix-environment-operator
##@ Development Environment
.PHONY: kind-setup
kind-setup: ## Set up a local kind cluster for development.
@echo "Setting up kind cluster for development..."
@which kind > /dev/null || (echo "kind not found, please install kind first: https://kind.sigs.k8s.io/docs/user/quick-start/#installation" && exit 1)
kind create cluster --name quix-operator || echo "Cluster already exists"
kubectl cluster-info
.PHONY: kind-delete
kind-delete: ## Delete the kind cluster.
@echo "Deleting kind cluster..."
kind delete cluster --name quix-operator
.PHONY: setup-dev
setup-dev: ## Set up the complete development environment.
@echo "Setting up development environment..."
@chmod +x hack/setup-dev-env.sh
@hack/setup-dev-env.sh
.PHONY: tidy
tidy: fmt ## Run go mod tidy and clean up imports.
@echo "Cleaning up imports in Go files..."
@find . -type f -name "*.go" -not -path "./vendor/*" | xargs $(LOCALBIN)/goimports -w
@echo "Running go mod tidy..."
go mod tidy