Skip to content

Commit 975e2aa

Browse files
committed
Set us basic e2e tests
1 parent 035c13a commit 975e2aa

13 files changed

+151
-2
lines changed

.github/workflows/e2e-test.yml

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: E2E Test
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
push:
8+
branches:
9+
- master
10+
11+
jobs:
12+
e2e:
13+
runs-on: ubuntu-latest
14+
name: End-to-End Test
15+
timeout-minutes: 30 # Add timeout to prevent hanging jobs
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
- name: Set up Docker Buildx
20+
uses: docker/setup-buildx-action@v2
21+
- name: Build Docker image
22+
uses: docker/build-push-action@v4
23+
with:
24+
context: .
25+
file: ./build/Dockerfile.dist
26+
push: false
27+
tags: |
28+
postgres-operator:build
29+
- name: Install kubectl & krew
30+
uses: marcofranssen/setup-kubectl@v1.3.0
31+
with:
32+
enablePlugins: true
33+
- name: Install KUTTL
34+
run: kubectl krew install kuttl
35+
- name: Run tests
36+
working-directory: tests
37+
run: kubectl kuttl test
38+
- name: Upload test artifacts
39+
if: always() # Run even if tests fail
40+
uses: actions/upload-artifact@v4
41+
with:
42+
name: test-results
43+
path: tests/kind-logs-*/
44+
retention-days: 7

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,6 @@ tags
8383
deploy/secret.yaml
8484
# build artifact
8585
operator
86+
# kuttl/kind
87+
tests/kind-logs-*/
88+
tests/kubeconfig

Makefile

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: gen build
1+
.PHONY: gen build e2e e2e-build
22

33
gen:
44
operator-sdk generate k8s
@@ -17,3 +17,7 @@ linux-build:
1717
@GOBIN=/work/bin GO111MODULE=on GOOS=linux GOARC=x86_64 go build --mod=vendor -o operator github.com/movetokube/postgres-operator/cmd/manager
1818
docker-build:
1919
docker run -ti -v $(PWD):/work -w /work golang:1.13.15-stretch make linux-build
20+
e2e-build:
21+
docker buildx build -t postgres-operator:build -f ./build/Dockerfile.dist .
22+
e2e: e2e-build
23+
cd tests && kubectl kuttl test

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ You can contribute to this project by opening a PR to merge to `master`, or one
213213

214214
Please write tests and fix any broken tests before you open a PR. Tests should cover at least 80% of your code.
215215

216+
#### e2e-tests
217+
218+
End-to-end tests are implemented using [kuttl](https://kuttl.dev/), a Kubernetes test framework. To execute these tests locally, first install kuttl on your system, then run the command `make e2e` from the project root directory.
219+
216220
### Compatibility
217221

218222
Postgres operator uses Operator SDK, which uses kubernetes client. Kubernetes client compatibility with Kubernetes cluster
@@ -225,4 +229,3 @@ Postgres operator compatibility with Operator SDK version is in the table below
225229
| `postgres-operator 0.4.x` | v0.17 | v1beta1 |
226230
| `postgres-operator 1.x.x` | v0.18 | v1 |
227231
| `HEAD` | v0.18 | v1 |
228-
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# In your test case directory, create a file named 00-helm-install.yaml
2+
apiVersion: kuttl.dev/v1beta1
3+
kind: TestStep
4+
commands:
5+
- command: >-
6+
helm install -n $NAMESPACE postgresql oci://registry-1.docker.io/bitnamicharts/postgresql
7+
--version 16.6.0
8+
--set global.postgresql.auth.password=postgres
9+
--set global.postgresql.auth.username=postgres
10+
--wait
11+
timeout: 120
12+
- command: >-
13+
helm install -n $NAMESPACE ext-postgres-operator-$NAMESPACE ext-postgres-operator/ext-postgres-operator
14+
--set image.repository=postgres-operator
15+
--set image.tag=build
16+
--set postgres.host=postgresql
17+
--set postgres.user=postgres
18+
--set postgres.password=postgres
19+
--set postgres.uri_args="sslmode=disable"
20+
--set watchNamespace=$NAMESPACE
21+
--wait
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestAssert
3+
collectors:
4+
- type: pod
5+
selector: app.kubernetes.io/name=ext-postgres-operator
6+
tail: 100
7+
---
8+
apiVersion: db.movetokube.com/v1alpha1
9+
kind: Postgres
10+
metadata:
11+
name: my-db
12+
status:
13+
roles:
14+
owner: test-db-group
15+
reader: test-db-reader
16+
writer: test-db-writer
17+
schemas:
18+
- stores
19+
- customers
20+
succeeded: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: db.movetokube.com/v1alpha1
2+
kind: Postgres
3+
metadata:
4+
name: my-db
5+
spec:
6+
database: test-db
7+
dropOnDelete: true
8+
masterRole: test-db-group
9+
schemas:
10+
- stores
11+
- customers
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestAssert
3+
collectors:
4+
- type: pod
5+
selector: app.kubernetes.io/name=ext-postgres-operator
6+
tail: 100
7+
---
8+
apiVersion: db.movetokube.com/v1alpha1
9+
kind: PostgresUser
10+
metadata:
11+
name: my-db-user
12+
status:
13+
databaseName: test-db
14+
postgresGroup: test-db-group
15+
succeeded: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: db.movetokube.com/v1alpha1
2+
kind: PostgresUser
3+
metadata:
4+
name: my-db-user
5+
spec:
6+
role: username
7+
database: my-db
8+
secretName: my-secret
9+
privileges: OWNER
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestStep
3+
delete:
4+
- apiVersion: db.movetokube.com/v1alpha1
5+
kind: PostgresUser
6+
name: my-db-user
7+
- apiVersion: db.movetokube.com/v1alpha1
8+
kind: Postgres
9+
name: my-db

tests/kuttl-test.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: kuttl.dev/v1beta1
2+
kind: TestSuite
3+
testDirs: # Directories containing test cases to run.
4+
- ./e2e/
5+
crdDir: ../deploy/crds/
6+
startKIND: true
7+
kindContainers:
8+
- postgres-operator:build
9+
commands:
10+
- command: helm repo add ext-postgres-operator https://movetokube.github.io/postgres-operator/

0 commit comments

Comments
 (0)