Skip to content

Commit c5031ef

Browse files
Merge pull request #47 from uselagoon/database-test-e2e
test: add database tests with metrics checks
2 parents b4932a2 + 4ddc28f commit c5031ef

File tree

4 files changed

+137
-15
lines changed

4 files changed

+137
-15
lines changed

.github/workflows/storage-calculator.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ jobs:
4242
with:
4343
go-version: '1.23'
4444

45+
- name: Add dependency chart repos
46+
run: |
47+
helm repo add amazeeio https://amazeeio.github.io/charts/
48+
4549
- name: Create kind cluster
4650
uses: helm/kind-action@v1.12.0
4751
with:
@@ -54,6 +58,6 @@ jobs:
5458
- name: Set up Docker Buildx
5559
uses: docker/setup-buildx-action@v3
5660

57-
- name: Run test-e2e
61+
- name: Run github/test-e2e
5862
run: |
59-
make test-e2e KIND_NETWORK=kind
63+
make github/test-e2e KIND_NETWORK=kind

Makefile

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ endif
2020
KIND_CLUSTER ?= storage-calculator
2121
KIND_NETWORK ?= storage-controller
2222

23+
TIMEOUT = 30m
24+
2325
KIND_VERSION = v0.25.0
2426
KUBECTL_VERSION := v1.31.0
2527
HELM_VERSION := v3.16.1
@@ -244,7 +246,7 @@ regenerate-broker-certs:
244246

245247
# Create a kind cluster locally and run the test e2e test suite against it
246248
.PHONY: kind/test-e2e # Run the e2e tests against a Kind k8s instance that is spun up locally
247-
kind/test-e2e: create-kind-cluster kind/re-test-e2e
249+
kind/test-e2e: create-kind-cluster install-dbaas-operator kind/re-test-e2e
248250

249251
.PHONY: local-kind/test-e2e # Run the e2e tests against a Kind k8s instance that is spun up locally
250252
kind/re-test-e2e:
@@ -260,12 +262,15 @@ kind/clean:
260262

261263
# Utilize Kind or modify the e2e tests to load the image locally, enabling compatibility with other vendors.
262264
.PHONY: test-e2e # Run the e2e tests against a Kind k8s instance that is spun up inside github action.
263-
test-e2e: local-dev/tools generate-broker-certs
265+
test-e2e: generate-broker-certs
264266
($(KUBECTL) create namespace storage-calculator-system || echo "namespace exists") && \
265267
($(KUBECTL) -n storage-calculator-system delete secret lagoon-broker-tls || echo "lagoon-broker-tls doesn't exist, ignoring") && \
266268
$(KUBECTL) -n storage-calculator-system create secret generic lagoon-broker-tls --from-file=tls.crt=local-dev/certificates/clienttls.crt --from-file=tls.key=local-dev/certificates/clienttls.key --from-file=ca.crt=local-dev/certificates/ca.crt && \
267269
go test ./test/e2e/ -v -ginkgo.v
268270

271+
.PHONY: github/test-e2e
272+
github/test-e2e: local-dev/tools install-dbaas-operator test-e2e
273+
269274
.PHONY: kind/set-kubeconfig
270275
kind/set-kubeconfig:
271276
export KIND_CLUSTER=$(KIND_CLUSTER) && \
@@ -301,3 +306,56 @@ CONTROLLER_GEN=$(GOBIN)/controller-gen
301306
else
302307
CONTROLLER_GEN=$(shell which controller-gen)
303308
endif
309+
310+
.PHONY: install-mariadb
311+
install-mariadb:
312+
$(HELM) upgrade \
313+
--install \
314+
--create-namespace \
315+
--namespace mariadb \
316+
--wait \
317+
--timeout $(TIMEOUT) \
318+
$$($(KUBECTL) get ns mariadb > /dev/null 2>&1 && echo --set auth.rootPassword=$$($(KUBECTL) get secret --namespace mariadb mariadb -o json | $(JQ) -r '.data."mariadb-root-password" | @base64d')) \
319+
--version=0.2.1 \
320+
mariadb \
321+
oci://registry-1.docker.io/cloudpirates/mariadb
322+
323+
.PHONY: install-postgresql
324+
install-postgresql:
325+
# root password is required on upgrade if the chart is already installed
326+
$(HELM) upgrade \
327+
--install \
328+
--create-namespace \
329+
--namespace postgresql \
330+
--wait \
331+
--timeout $(TIMEOUT) \
332+
$$($(KUBECTL) get ns postgresql > /dev/null 2>&1 && echo --set auth.postgresPassword=$$($(KUBECTL) get secret --namespace postgresql postgresql -o json | $(JQ) -r '.data."postgres-password" | @base64d')) \
333+
--version=0.2.2 \
334+
postgresql \
335+
oci://registry-1.docker.io/cloudpirates/postgres
336+
337+
.PHONY: install-dbaas-operator
338+
install-dbaas-operator: install-mariadb install-postgresql
339+
$(HELM) upgrade \
340+
--install \
341+
--create-namespace \
342+
--namespace dbaas-operator \
343+
--wait \
344+
--timeout $(TIMEOUT) \
345+
--set enableMariaDBProviders=true \
346+
--set enableMongoDBProviders=true \
347+
--set enablePostreSQLProviders=true \
348+
--set mariadbProviders.development.environment=development \
349+
--set mariadbProviders.development.hostname=mariadb.mariadb.svc.cluster.local \
350+
--set mariadbProviders.development.readReplicaHostnames[0]=mariadb.mariadb.svc.cluster.local \
351+
--set mariadbProviders.development.password=$$($(KUBECTL) get secret --namespace mariadb mariadb -o json | $(JQ) -r '.data."mariadb-root-password" | @base64d') \
352+
--set mariadbProviders.development.port=3306 \
353+
--set mariadbProviders.development.user=root \
354+
--set postgresqlProviders.development.environment=development \
355+
--set postgresqlProviders.development.hostname=postgresql.postgresql.svc.cluster.local \
356+
--set postgresqlProviders.development.password=$$($(KUBECTL) get secret --namespace postgresql postgresql -o json | $(JQ) -r '.data."postgres-password" | @base64d') \
357+
--set postgresqlProviders.development.port=5432 \
358+
--set postgresqlProviders.development.user=postgres \
359+
--version=0.4.0 \
360+
dbaas-operator \
361+
amazeeio/dbaas-operator

test/e2e/e2e_suite.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ var (
3737
duration = 600 * time.Second
3838
interval = 1 * time.Second
3939

40-
metricLabels = []string{
41-
"lagoon_storage_calculator_kilobytes",
40+
metricClaims = []string{
41+
`lagoon_storage_calculator_kilobytes{claimenv="123",claimpvc="basic-data",environment="develop",lagoon_namespace="example-project-develop",project="example-project"}`,
42+
`lagoon_storage_calculator_kilobytes{claimenv="123",claimpvc="basic-data",environment="main",lagoon_namespace="example-project-main",project="example-project"}`,
43+
`lagoon_storage_calculator_kilobytes{claimenv="123",claimpvc="mariadb",environment="develop",lagoon_namespace="example-project-develop",project="example-project"}`,
44+
`lagoon_storage_calculator_kilobytes{claimenv="123",claimpvc="postgres",environment="develop",lagoon_namespace="example-project-develop",project="example-project"}`,
4245
}
4346
)
4447

@@ -212,6 +215,21 @@ var _ = Describe("controller", Ordered, func() {
212215
return nil
213216
}
214217
EventuallyWithOffset(1, verifyStorageCalculatorRuns, duration, interval).Should(Succeed())
218+
verifyStorageCalculatorRuns2 := func() error {
219+
cmd = exec.Command(utils.Kubectl(), "logs",
220+
controllerPodName, "-c", "manager",
221+
"-n", namespace,
222+
)
223+
podlogs, err := utils.Run(cmd)
224+
ExpectWithOffset(2, err).NotTo(HaveOccurred())
225+
if !strings.Contains(string(podlogs), "storage in example-project-develop") {
226+
return fmt.Errorf("storage-calculator-pod not created")
227+
}
228+
return nil
229+
}
230+
EventuallyWithOffset(1, verifyStorageCalculatorRuns2, duration, interval).Should(Succeed())
231+
232+
time.Sleep(10 * time.Second)
215233

216234
By("validating that unauthenticated metrics requests fail")
217235
runCmd := `curl -s -k https://storage-calculator-controller-manager-metrics-service.storage-calculator-system.svc.cluster.local:8443/metrics | grep -v "#" | grep "lagoon_"`
@@ -223,7 +241,7 @@ var _ = Describe("controller", Ordered, func() {
223241
output, err := utils.RunCommonsCommand(namespace, runCmd)
224242
ExpectWithOffset(2, err).NotTo(HaveOccurred())
225243
fmt.Printf("metrics: %s", string(output))
226-
err = utils.CheckStringContainsStrings(string(output), metricLabels)
244+
err = utils.CheckStringContainsStrings(string(output), metricClaims)
227245
ExpectWithOffset(2, err).NotTo(HaveOccurred())
228246
// End tests
229247
})

test/e2e/testdata/example-env-2.yaml

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ kind: Namespace
33
metadata:
44
name: example-project-develop
55
labels:
6-
lagoon.sh/environmentType: production
6+
lagoon.sh/environmentType: development
77
lagoon.sh/storageCalculatorEnabled: 'true'
88
lagoon.sh/environmentId: '123'
99
lagoon.sh/environment: 'develop'
@@ -22,7 +22,7 @@ metadata:
2222
app.kubernetes.io/name: basic-persistent
2323
lagoon.sh/buildType: branch
2424
lagoon.sh/environment: develop
25-
lagoon.sh/environmentType: production
25+
lagoon.sh/environmentType: development
2626
lagoon.sh/project: example-project
2727
lagoon.sh/service: basic
2828
lagoon.sh/service-type: basic-persistent
@@ -50,7 +50,7 @@ metadata:
5050
app.kubernetes.io/name: basic-persistent
5151
lagoon.sh/buildType: branch
5252
lagoon.sh/environment: develop
53-
lagoon.sh/environmentType: production
53+
lagoon.sh/environmentType: development
5454
lagoon.sh/project: example-project
5555
lagoon.sh/service: basic
5656
lagoon.sh/service-type: basic-persistent
@@ -77,7 +77,7 @@ spec:
7777
app.kubernetes.io/name: basic-persistent
7878
lagoon.sh/buildType: branch
7979
lagoon.sh/environment: develop
80-
lagoon.sh/environmentType: production
80+
lagoon.sh/environmentType: development
8181
lagoon.sh/project: example-project
8282
lagoon.sh/service: basic
8383
lagoon.sh/service-type: basic-persistent
@@ -135,7 +135,7 @@ metadata:
135135
app.kubernetes.io/name: basic-persistent
136136
lagoon.sh/buildType: branch
137137
lagoon.sh/environment: develop
138-
lagoon.sh/environmentType: production
138+
lagoon.sh/environmentType: development
139139
lagoon.sh/project: example-project
140140
lagoon.sh/service: basic
141141
lagoon.sh/service-type: basic-persistent
@@ -166,7 +166,7 @@ metadata:
166166
app.kubernetes.io/name: lagoon-env
167167
lagoon.sh/buildType: branch
168168
lagoon.sh/environment: name
169-
lagoon.sh/environmentType: production
169+
lagoon.sh/environmentType: development
170170
lagoon.sh/project: example-project
171171
lagoon.sh/template: lagoon-env-0.1.0
172172
name: lagoon-platform-env
@@ -186,12 +186,54 @@ metadata:
186186
app.kubernetes.io/name: lagoon-env
187187
lagoon.sh/buildType: branch
188188
lagoon.sh/environment: name
189-
lagoon.sh/environmentType: production
189+
lagoon.sh/environmentType: development
190190
lagoon.sh/project: example-project
191191
lagoon.sh/template: lagoon-env-0.1.0
192192
name: lagoon-env
193193
namespace: example-project-develop
194194
stringData:
195195
MY_SPECIAL_VARIABLE: myspecialvariable
196196
MY_SPECIAL_VARIABLE1: myspecialvariable1
197-
MY_SPECIAL_VARIABLE2: myspecialvariable2
197+
MY_SPECIAL_VARIABLE2: myspecialvariable2
198+
---
199+
apiVersion: mariadb.amazee.io/v1
200+
kind: MariaDBConsumer
201+
metadata:
202+
annotations:
203+
lagoon.sh/branch: environment-name
204+
creationTimestamp: null
205+
labels:
206+
app.kubernetes.io/instance: mariadb
207+
app.kubernetes.io/managed-by: build-deploy-tool
208+
app.kubernetes.io/name: mariadb
209+
lagoon.sh/buildType: branch
210+
lagoon.sh/environment: name
211+
lagoon.sh/environmentType: development
212+
lagoon.sh/project: example-project
213+
lagoon.sh/service-type: mariadb-dbaas
214+
lagoon.sh/template: mariadb-dbaas-0.1.0
215+
name: mariadb
216+
namespace: example-project-develop
217+
spec:
218+
environment: development
219+
---
220+
apiVersion: postgres.amazee.io/v1
221+
kind: PostgreSQLConsumer
222+
metadata:
223+
annotations:
224+
lagoon.sh/branch: environment-name
225+
creationTimestamp: null
226+
labels:
227+
app.kubernetes.io/instance: postgres
228+
app.kubernetes.io/managed-by: build-deploy-tool
229+
app.kubernetes.io/name: postgres
230+
lagoon.sh/buildType: branch
231+
lagoon.sh/environment: name
232+
lagoon.sh/environmentType: development
233+
lagoon.sh/project: example-project
234+
lagoon.sh/service-type: postgres-dbaas
235+
lagoon.sh/template: postgres-dbaas-0.1.0
236+
name: postgres
237+
namespace: example-project-develop
238+
spec:
239+
environment: development

0 commit comments

Comments
 (0)