Skip to content

Set us basic e2e tests #170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: E2E Test

on:
pull_request:
branches:
- master
push:
branches:
- master

jobs:
e2e:
runs-on: ubuntu-latest
name: End-to-End Test
timeout-minutes: 30 # Add timeout to prevent hanging jobs
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build Docker image
uses: docker/build-push-action@v4
with:
context: .
file: ./build/Dockerfile.dist
push: false
load: true
tags: |
postgres-operator:build
- name: Install kubectl & krew
uses: marcofranssen/[email protected]
with:
enablePlugins: true
- name: Install KUTTL
run: kubectl krew install kuttl
- name: Run tests
run: kubectl kuttl test --config ./tests/kuttl-test-self-hosted-postgres.yaml
- name: Upload test artifacts
if: always() # Run even if tests fail
uses: actions/upload-artifact@v4
with:
name: test-results
path: tests/kind-logs-*/
retention-days: 7
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,6 @@ tags
deploy/secret.yaml
# build artifact
operator
# kuttl/kind
tests/kind-logs-*/
kubeconfig
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: gen build
.PHONY: gen build e2e e2e-build

gen:
operator-sdk generate k8s
Expand All @@ -17,3 +17,7 @@ linux-build:
@GOBIN=/work/bin GO111MODULE=on GOOS=linux GOARC=x86_64 go build --mod=vendor -o operator github.com/movetokube/postgres-operator/cmd/manager
docker-build:
docker run -ti -v $(PWD):/work -w /work golang:1.13.15-stretch make linux-build
e2e-build:
docker buildx build -t postgres-operator:build -f ./build/Dockerfile.dist .
e2e: e2e-build
kubectl kuttl test --config ./tests/kuttl-test-self-hosted-postgres.yaml
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ You can contribute to this project by opening a PR to merge to `master`, or one

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

#### e2e-tests

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.

### Compatibility

Postgres operator uses Operator SDK, which uses kubernetes client. Kubernetes client compatibility with Kubernetes cluster
Expand All @@ -225,4 +229,3 @@ Postgres operator compatibility with Operator SDK version is in the table below
| `postgres-operator 0.4.x` | v0.17 | v1beta1 |
| `postgres-operator 1.x.x` | v0.18 | v1 |
| `HEAD` | v0.18 | v1 |

20 changes: 20 additions & 0 deletions tests/e2e/basic-operations/01-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
collectors:
- type: pod
selector: app.kubernetes.io/name=ext-postgres-operator
tail: 100
---
apiVersion: db.movetokube.com/v1alpha1
kind: Postgres
metadata:
name: my-db
status:
roles:
owner: test-db-group
reader: test-db-reader
writer: test-db-writer
schemas:
- stores
- customers
succeeded: true
11 changes: 11 additions & 0 deletions tests/e2e/basic-operations/01-postgres.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: db.movetokube.com/v1alpha1
kind: Postgres
metadata:
name: my-db
spec:
database: test-db
dropOnDelete: true
masterRole: test-db-group
schemas:
- stores
- customers
15 changes: 15 additions & 0 deletions tests/e2e/basic-operations/02-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
collectors:
- type: pod
selector: app.kubernetes.io/name=ext-postgres-operator
tail: 100
---
apiVersion: db.movetokube.com/v1alpha1
kind: PostgresUser
metadata:
name: my-db-user
status:
databaseName: test-db
postgresGroup: test-db-group
succeeded: true
9 changes: 9 additions & 0 deletions tests/e2e/basic-operations/02-postgresuser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: db.movetokube.com/v1alpha1
kind: PostgresUser
metadata:
name: my-db-user
spec:
role: username
database: my-db
secretName: my-secret
privileges: OWNER
8 changes: 8 additions & 0 deletions tests/e2e/basic-operations/03-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
collectors:
- type: pod
selector: app.kubernetes.io/name=ext-postgres-operator
tail: 100
commands:
- command: bash -c "! kubectl get postgresuser my-db-user -n $NAMESPACE"
6 changes: 6 additions & 0 deletions tests/e2e/basic-operations/03-delete-postgresuser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
delete:
- apiVersion: db.movetokube.com/v1alpha1
kind: PostgresUser
name: my-db-user
8 changes: 8 additions & 0 deletions tests/e2e/basic-operations/04-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
collectors:
- type: pod
selector: app.kubernetes.io/name=ext-postgres-operator
tail: 100
commands:
- command: bash -c "! kubectl get postgres my-db -n $NAMESPACE"
6 changes: 6 additions & 0 deletions tests/e2e/basic-operations/04-delete-postgres.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
delete:
- apiVersion: db.movetokube.com/v1alpha1
kind: Postgres
name: my-db
28 changes: 28 additions & 0 deletions tests/kuttl-test-self-hosted-postgres.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: kuttl.dev/v1beta1
kind: TestSuite
testDirs:
- ./tests/e2e/
crdDir: ./deploy/crds/
startKIND: true
kindContext: self-hosted-postgres
kindContainers:
- postgres-operator:build
artifactsDir: ./tests/
commands:
- command: helm repo add ext-postgres-operator https://movetokube.github.io/postgres-operator/
- command: >-
helm install -n $NAMESPACE postgresql oci://registry-1.docker.io/bitnamicharts/postgresql
--version 16.6.0
--set global.postgresql.auth.password=postgres
--set global.postgresql.auth.username=postgres
--wait
timeout: 120
- command: >-
helm install -n $NAMESPACE ext-postgres-operator ext-postgres-operator/ext-postgres-operator
--set image.repository=postgres-operator
--set image.tag=build
--set postgres.host=postgresql
--set postgres.user=postgres
--set postgres.password=postgres
--set postgres.uri_args="sslmode=disable"
--wait