1111GOBIN =$(shell go env GOBIN)
1212endif
1313
14- KIND_CLUSTER ?= kind
14+ KIND_CLUSTER ?= dbaas-controller
15+ KIND_NETWORK ?= dbaas-controller
16+
17+ KIND_VERSION = v0.25.0
18+ KUBECTL_VERSION := v1.31.0
19+ HELM_VERSION := v3.16.1
20+ GOJQ_VERSION = v0.12.16
21+ KUSTOMIZE_VERSION := v5.4.3
22+
23+ HELM = $(realpath ./local-dev/helm)
24+ KUBECTL = $(realpath ./local-dev/kubectl)
25+ JQ = $(realpath ./local-dev/jq)
26+ KIND = $(realpath ./local-dev/kind)
27+ KUSTOMIZE = $(realpath ./local-dev/kustomize)
28+
29+ ARCH := $(shell uname | tr '[:upper:]' '[:lower:]')
30+
31+ .PHONY : local-dev/kind
32+ local-dev/kind :
33+ ifeq ($(KIND_VERSION ) , $(shell kind version 2>/dev/null | sed -nE 's/kind (v[0-9.]+) .*/\1/p'))
34+ $(info linking local kind version $(KIND_VERSION))
35+ ln -sf $(shell command -v kind) ./local-dev/kind
36+ else
37+ ifneq ($(KIND_VERSION ) , $(shell ./local-dev/kind version 2>/dev/null | sed -nE 's/kind (v[0-9.]+) .*/\1/p'))
38+ $(info downloading kind version $(KIND_VERSION) for $(ARCH))
39+ mkdir -p local-dev
40+ rm local-dev/kind || true
41+ curl -sSLo local-dev/kind https://kind.sigs.k8s.io/dl/$(KIND_VERSION)/kind-$(ARCH)-amd64
42+ chmod a+x local-dev/kind
43+ endif
44+ endif
45+
46+ .PHONY : local-dev/kustomize
47+ local-dev/kustomize :
48+ ifeq ($(KUSTOMIZE_VERSION ) , $(shell kustomize version 2>/dev/null | sed -nE 's/(v[0-9.]+) .*/\1/p'))
49+ $(info linking local kustomize version $(KUSTOMIZE_VERSION))
50+ ln -sf $(shell command -v kustomize) ./local-dev/kustomize
51+ else
52+ ifneq ($(KUSTOMIZE_VERSION ) , $(shell ./local-dev/kustomize version 2>/dev/null | sed -nE 's/(v[0-9.]+) .*/\1/p'))
53+ $(info downloading kustomize version $(KUSTOMIZE_VERSION) for $(ARCH))
54+ rm local-dev/kustomize || true
55+ curl -sSL https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize%2F$(KUSTOMIZE_VERSION)/kustomize_$(KUSTOMIZE_VERSION)_$(ARCH)_amd64.tar.gz | tar -xzC local-dev
56+ chmod a+x local-dev/kustomize
57+ endif
58+ endif
59+
60+ .PHONY : local-dev/helm
61+ local-dev/helm :
62+ ifeq ($(HELM_VERSION ) , $(shell helm version --short --client 2>/dev/null | sed -nE 's/(v[0-9.]+) .*/\1/p'))
63+ $(info linking local helm version $(HELM_VERSION))
64+ ln -sf $(shell command -v helm) ./local-dev/helm
65+ else
66+ ifneq ($(HELM_VERSION ) , $(shell ./local-dev/helm version --short --client 2>/dev/null | sed -nE 's/(v[0-9.]+) .*/\1/p'))
67+ $(info downloading helm version $(HELM_VERSION) for $(ARCH))
68+ rm local-dev/helm || true
69+ curl -sSL https://get.helm.sh/helm-$(HELM_VERSION)-$(ARCH)-amd64.tar.gz | tar -xzC local-dev --strip-components=1 $(ARCH)-amd64/helm
70+ chmod a+x local-dev/helm
71+ endif
72+ endif
73+
74+ .PHONY : local-dev/jq
75+ local-dev/jq :
76+ ifeq ($(GOJQ_VERSION ) , $(shell gojq -v 2>/dev/null | sed -nE 's/gojq ([0-9.]+) .*/v\1/p'))
77+ $(info linking local gojq version $(GOJQ_VERSION))
78+ ln -sf $(shell command -v gojq) ./local-dev/jq
79+ else
80+ ifneq ($(GOJQ_VERSION ) , $(shell ./local-dev/jq -v 2>/dev/null | sed -nE 's/gojq ([0-9.]+) .*/v\1/p'))
81+ $(info downloading gojq version $(GOJQ_VERSION) for $(ARCH))
82+ rm local-dev/jq || true
83+ ifeq ($(ARCH ) , darwin)
84+ TMPDIR=$$(mktemp -d) \
85+ && curl -sSL https://github.com/itchyny/gojq/releases/download/$(GOJQ_VERSION)/gojq_$(GOJQ_VERSION)_$(ARCH)_arm64.zip -o $$TMPDIR/gojq.zip \
86+ && (cd $$TMPDIR && unzip gojq.zip) && cp $$TMPDIR/gojq_$(GOJQ_VERSION)_$(ARCH)_arm64/gojq ./local-dev/jq && rm -rf $$TMPDIR
87+ else
88+ curl -sSL https://github.com/itchyny/gojq/releases/download/$(GOJQ_VERSION)/gojq_$(GOJQ_VERSION)_$(ARCH)_amd64.tar.gz | tar -xzC local-dev --strip-components=1 gojq_$(GOJQ_VERSION)_$(ARCH)_amd64/gojq
89+ mv ./local-dev/{go,}jq
90+ endif
91+ chmod a+x local-dev/jq
92+ endif
93+ endif
94+
95+ .PHONY : local-dev/kubectl
96+ local-dev/kubectl :
97+ ifeq ($(KUBECTL_VERSION ) , $(shell kubectl version --client 2>/dev/null | grep Client | sed -E 's/Client Version : (v[0-9.]+).* /\1/'))
98+ $(info linking local kubectl version $(KUBECTL_VERSION ) )
99+ ln -sf $(shell command -v kubectl) ./local-dev/kubectl
100+ else
101+ ifneq ($(KUBECTL_VERSION ) , $(shell ./local-dev/kubectl version --client 2>/dev/null | grep Client | sed -E 's/Client Version : (v[0-9.]+).* /\1/'))
102+ $(info downloading kubectl version $(KUBECTL_VERSION ) for $(ARCH ) )
103+ rm local-dev/kubectl || true
104+ curl -sSLo local-dev/kubectl https://storage.googleapis.com/kubernetes-release/release/$(KUBECTL_VERSION ) /bin/$(ARCH ) /amd64/kubectl
105+ chmod a+x local-dev/kubectl
106+ endif
107+ endif
108+
109+ .PHONY : local-dev/tools
110+ local-dev/tools : local-dev/kind local-dev/kustomize local-dev/kubectl local-dev/jq local-dev/helm
111+
112+ .PHONY : helm/repos
113+ helm/repos : local-dev/helm
114+ # install repo dependencies required by the charts
115+ # $(HELM) repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
116+ # $(HELM) repo add metallb https://metallb.github.io/metallb
117+ # $(HELM) repo update
15118
16119# CONTAINER_TOOL defines the container tool to be used for building images.
17120# Be aware that the target commands are only tested with Docker which is
@@ -67,29 +170,52 @@ test: manifests generate fmt vet envtest ## Run tests.
67170 KUBEBUILDER_ASSETS=" $( shell $( ENVTEST) use $( ENVTEST_K8S_VERSION) --bin-dir $( LOCALBIN) -p path) " go test $$(go list ./... | grep -v /e2e ) -coverprofile cover.out
68171
69172.PHONY : create-kind-cluster
70- create-kind-cluster :
71- @if ! kind get clusters | grep -q $(KIND_CLUSTER ) ; then \
72- docker network inspect $(KIND_CLUSTER ) > /dev/null 2>&1 || docker network create $(KIND_CLUSTER ) ; \
73- kind create cluster --wait=60s --name=$(KIND_CLUSTER ) --config=kind-config.yaml; \
74- else \
75- echo " Cluster $( KIND_CLUSTER) already exists" ; \
76- fi
173+ create-kind-cluster : local-dev/tools helm/repos
174+ docker network inspect $(KIND_NETWORK ) > /dev/null || docker network create $(KIND_NETWORK ) \
175+ && LAGOON_KIND_CIDR_BLOCK=$$(docker network inspect $(KIND_NETWORK ) | $(JQ ) '. [0].IPAM.Config[0].Subnet' | tr -d '"' ) \
176+ && export KIND_NODE_IP=$$(echo $${LAGOON_KIND_CIDR_BLOCK%???} | awk -F'.' '{print $$1,$$2,$$3,240}' OFS='.' ) \
177+ && export KIND_EXPERIMENTAL_DOCKER_NETWORK=$(KIND_NETWORK ) \
178+ && $(KIND) create cluster --wait=60s --name=$(KIND_CLUSTER) --config=test-resources/test-suite.kind-config.yaml
179+
180+ # Create a kind cluster locally and run the test e2e test suite against it
181+ .PHONY : kind/test-e2e # Run the e2e tests against a Kind k8s instance that is spun up locally
182+ kind/test-e2e : create-kind-cluster kind/re-test-e2e
77183
78- .PHONY : delete-kind-cluster
79- delete-kind-cluster :
80- kind delete cluster --name=$(KIND_CLUSTER ) && docker network rm $(KIND_CLUSTER )
184+ .PHONY : local-kind/test-e2e # Run the e2e tests against a Kind k8s instance that is spun up locally
185+ kind/re-test-e2e :
186+ export KIND_PATH=$(KIND ) && \
187+ export KUBECTL_PATH=$(KUBECTL ) && \
188+ export KIND_CLUSTER=$(KIND_CLUSTER ) && \
189+ LAGOON_KIND_CIDR_BLOCK=$$(docker network inspect $(KIND_NETWORK ) | $(JQ ) '. [0].IPAM.Config[0].Subnet' | tr -d '"' ) && \
190+ export KIND_NODE_IP=$$(echo $${LAGOON_KIND_CIDR_BLOCK%???} | awk -F'.' '{print $$1,$$2,$$3,240}' OFS='.' ) && \
191+ $(KIND ) export kubeconfig --name=$(KIND_CLUSTER ) && \
192+ $(MAKE ) test-e2e
193+
194+ .PHONY : clean
195+ kind/clean :
196+ $(KIND ) delete cluster --name=$(KIND_CLUSTER ) && docker network rm $(KIND_NETWORK )
81197
82198# Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors.
83- .PHONY : github/ test-e2e # Run the e2e tests against a Kind k8s instance that is spun up inside github action.
84- github/ test-e2e :
199+ .PHONY : test-e2e # Run the e2e tests against a Kind k8s instance that is spun up inside github action.
200+ test-e2e :
85201 go test ./test/e2e/ -v -ginkgo.v
86202
87- # Create a kind cluster locally and run the test e2e test suite against it
88- .PHONY : local-kind/test-e2e # Run the e2e tests against a Kind k8s instance that is spun up locally
89- local-kind/test-e2e : create-kind-cluster
203+ # Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors.
204+ .PHONY : github/test-e2e # Run the e2e tests against a Kind k8s instance that is spun up inside github action.
205+ github/test-e2e : local-dev/tools test-e2e
206+
207+ .PHONY : kind/set-kubeconfig
208+ kind/set-kubeconfig :
90209 export KIND_CLUSTER=$(KIND_CLUSTER ) && \
91- kind export kubeconfig --name=$(KIND_CLUSTER ) && \
92- go test ./test/e2e/ -v -ginkgo.v
210+ $(KIND ) export kubeconfig --name=$(KIND_CLUSTER )
211+
212+ .PHONY : kind/logs-dbaas-controller
213+ kind/logs-dbaas-controller :
214+ export KIND_CLUSTER=$(KIND_CLUSTER ) && \
215+ $(KIND ) export kubeconfig --name=$(KIND_CLUSTER ) && \
216+ $(KUBECTL ) -n dbaas-controller-system logs -f \
217+ $$($(KUBECTL ) -n dbaas-controller-system get pod -l control-plane=controller-manager -o jsonpath="{.items[0].metadata.name}") \
218+ -c manager
93219
94220.PHONY : lint
95221lint : golangci-lint # # Run golangci-lint linter & yamllint
@@ -138,7 +264,7 @@ docker-buildx: ## Build and push docker image for the manager for cross-platform
138264 rm Dockerfile.cross
139265
140266.PHONY : build-installer
141- build-installer : manifests generate kustomize # # Generate a consolidated YAML with CRDs and deployment.
267+ build-installer : manifests generate local-dev/ kustomize # # Generate a consolidated YAML with CRDs and deployment.
142268 mkdir -p dist
143269 @if [ -d " config/crd" ]; then \
144270 $(KUSTOMIZE ) build config/crd > dist/install.yaml; \
@@ -154,20 +280,20 @@ ifndef ignore-not-found
154280endif
155281
156282.PHONY : install
157- install : manifests kustomize # # Install CRDs into the K8s cluster specified in ~/.kube/config.
283+ install : manifests local-dev/ kustomize # # Install CRDs into the K8s cluster specified in ~/.kube/config.
158284 $(KUSTOMIZE ) build config/crd | $(KUBECTL ) apply -f -
159285
160286.PHONY : uninstall
161- uninstall : manifests kustomize # # Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
287+ uninstall : manifests local-dev/ kustomize # # Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
162288 $(KUSTOMIZE ) build config/crd | $(KUBECTL ) delete --ignore-not-found=$(ignore-not-found ) -f -
163289
164290.PHONY : deploy
165- deploy : manifests kustomize # # Deploy controller to the K8s cluster specified in ~/.kube/config.
291+ deploy : manifests local-dev/ kustomize # # Deploy controller to the K8s cluster specified in ~/.kube/config.
166292 cd config/manager && $(KUSTOMIZE ) edit set image controller=${IMG}
167293 $(KUSTOMIZE ) build config/default | $(KUBECTL ) apply -f -
168294
169295.PHONY : undeploy
170- undeploy : kustomize # # Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
296+ undeploy : local-dev/ kustomize # # Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
171297 $(KUSTOMIZE ) build config/default | $(KUBECTL ) delete --ignore-not-found=$(ignore-not-found ) -f -
172298
173299# #@ Dependencies
@@ -178,23 +304,15 @@ $(LOCALBIN):
178304 mkdir -p $(LOCALBIN )
179305
180306# # Tool Binaries
181- KUBECTL ?= kubectl
182- KUSTOMIZE ?= $(LOCALBIN ) /kustomize-$(KUSTOMIZE_VERSION )
183307CONTROLLER_GEN ?= $(LOCALBIN ) /controller-gen-$(CONTROLLER_TOOLS_VERSION )
184308ENVTEST ?= $(LOCALBIN ) /setup-envtest-$(ENVTEST_VERSION )
185309GOLANGCI_LINT = $(LOCALBIN ) /golangci-lint-$(GOLANGCI_LINT_VERSION )
186310
187311# # Tool Versions
188- KUSTOMIZE_VERSION ?= v5.3.0
189- CONTROLLER_TOOLS_VERSION ?= v0.16.0
312+ CONTROLLER_TOOLS_VERSION ?= v0.16.5
190313ENVTEST_VERSION ?= latest
191314GOLANGCI_LINT_VERSION ?= v1.54.2
192315
193- .PHONY : kustomize
194- kustomize : $(KUSTOMIZE ) # # Download kustomize locally if necessary.
195- $(KUSTOMIZE ) : $(LOCALBIN )
196- $(call go-install-tool,$(KUSTOMIZE ) ,sigs.k8s.io/kustomize/kustomize/v5,$(KUSTOMIZE_VERSION ) )
197-
198316.PHONY : controller-gen
199317controller-gen : $(CONTROLLER_GEN ) # # Download controller-gen locally if necessary.
200318$(CONTROLLER_GEN ) : $(LOCALBIN )
0 commit comments