Skip to content

Commit 3de5c7f

Browse files
Merge pull request #35 from uselagoon/local-dev
chore: update local development to match other tools
2 parents fedbd5f + 71b0b78 commit 3de5c7f

File tree

9 files changed

+223
-138
lines changed

9 files changed

+223
-138
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@ go.work
2626
*.swp
2727
*.swo
2828
*~
29+
30+
local-dev

Makefile

Lines changed: 150 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,110 @@ else
1111
GOBIN=$(shell go env GOBIN)
1212
endif
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
95221
lint: 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
154280
endif
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)
183307
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen-$(CONTROLLER_TOOLS_VERSION)
184308
ENVTEST ?= $(LOCALBIN)/setup-envtest-$(ENVTEST_VERSION)
185309
GOLANGCI_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
190313
ENVTEST_VERSION ?= latest
191314
GOLANGCI_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
199317
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
200318
$(CONTROLLER_GEN): $(LOCALBIN)

config/crd/bases/crd.lagoon.sh_databaserequests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.16.0
6+
controller-gen.kubebuilder.io/version: v0.16.5
77
name: databaserequests.crd.lagoon.sh
88
spec:
99
group: crd.lagoon.sh

config/crd/bases/crd.lagoon.sh_mongodbproviders.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.16.0
6+
controller-gen.kubebuilder.io/version: v0.16.5
77
name: mongodbproviders.crd.lagoon.sh
88
spec:
99
group: crd.lagoon.sh

config/crd/bases/crd.lagoon.sh_relationaldatabaseproviders.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.16.0
6+
controller-gen.kubebuilder.io/version: v0.16.5
77
name: relationaldatabaseproviders.crd.lagoon.sh
88
spec:
99
group: crd.lagoon.sh

config/rbac/role.yaml

Lines changed: 4 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,6 @@ rules:
1515
- ""
1616
resources:
1717
- secrets
18-
verbs:
19-
- create
20-
- delete
21-
- get
22-
- list
23-
- patch
24-
- update
25-
- watch
26-
- apiGroups:
27-
- ""
28-
resources:
2918
- services
3019
verbs:
3120
- create
@@ -39,57 +28,7 @@ rules:
3928
- crd.lagoon.sh
4029
resources:
4130
- databaserequests
42-
verbs:
43-
- create
44-
- delete
45-
- get
46-
- list
47-
- patch
48-
- update
49-
- watch
50-
- apiGroups:
51-
- crd.lagoon.sh
52-
resources:
53-
- databaserequests/finalizers
54-
verbs:
55-
- update
56-
- apiGroups:
57-
- crd.lagoon.sh
58-
resources:
59-
- databaserequests/status
60-
verbs:
61-
- get
62-
- patch
63-
- update
64-
- apiGroups:
65-
- crd.lagoon.sh
66-
resources:
6731
- mongodbproviders
68-
verbs:
69-
- create
70-
- delete
71-
- get
72-
- list
73-
- patch
74-
- update
75-
- watch
76-
- apiGroups:
77-
- crd.lagoon.sh
78-
resources:
79-
- mongodbproviders/finalizers
80-
verbs:
81-
- update
82-
- apiGroups:
83-
- crd.lagoon.sh
84-
resources:
85-
- mongodbproviders/status
86-
verbs:
87-
- get
88-
- patch
89-
- update
90-
- apiGroups:
91-
- crd.lagoon.sh
92-
resources:
9332
- relationaldatabaseproviders
9433
verbs:
9534
- create
@@ -102,12 +41,16 @@ rules:
10241
- apiGroups:
10342
- crd.lagoon.sh
10443
resources:
44+
- databaserequests/finalizers
45+
- mongodbproviders/finalizers
10546
- relationaldatabaseproviders/finalizers
10647
verbs:
10748
- update
10849
- apiGroups:
10950
- crd.lagoon.sh
11051
resources:
52+
- databaserequests/status
53+
- mongodbproviders/status
11154
- relationaldatabaseproviders/status
11255
verbs:
11356
- get
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
kind: Cluster
2+
apiVersion: kind.x-k8s.io/v1alpha4

0 commit comments

Comments
 (0)