File tree Expand file tree Collapse file tree 8 files changed +114
-0
lines changed Expand file tree Collapse file tree 8 files changed +114
-0
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,7 @@ GO ?= go
6262GO_BUILD = $(GO_CMD ) build -trimpath
6363GO_CMD = $(GO_ENV ) $(GO )
6464GO_TEST ?= $(GO ) test
65+ KUTTL_TEST ?= kuttl test
6566
6667# Disable optimizations if creating a debug build
6768ifeq ("$(DEBUG_BUILD ) ", "true")
@@ -202,6 +203,11 @@ check-envtest-existing:
202203 USE_EXISTING_CLUSTER=true $(GO_TEST ) -count=1 -cover -p=1 -tags=envtest ./...
203204 ${PGO_KUBE_CLIENT} delete -k ./config/dev
204205
206+ # Expects operator to be running
207+ .PHONY : check-kuttl
208+ check-kuttl :
209+ ${PGO_KUBE_CLIENT} ${KUTTL_TEST} \
210+ --config testing/kuttl/kuttl-test.yaml
205211
206212.PHONY : check-generate
207213check-generate : generate-crd generate-deepcopy generate-rbac
Original file line number Diff line number Diff line change 1+ # Kuttl
2+
3+ ## Installing
4+ Docs for install: https://kuttl.dev/docs/cli.html#setup-the-kuttl-kubectl-plugin
5+
6+ Options:
7+ - Download and install the binary
8+ - Install the ` kubectl krew ` [ plugin manager] ( https://github.com/kubernetes-sigs/krew )
9+ and ` kubectl krew install kuttl `
10+ ## Cheat sheet
11+
12+ ### Run test suite
13+
14+ Make sure that the operator is running in your kubernetes environment and that your ` kubeconfig ` is
15+ set up. Then run the make target:
16+
17+ ```
18+ make check-kuttl
19+ ```
20+
21+ ### Running a single test
22+ A single test is considered to be one directory under ` kuttl/e2e ` , for example
23+ ` kuttl/e2e/restore ` would run the ` restore ` test.
24+
25+ There are two ways to run a single test in isolation:
26+ - using an env var with the make target: ` KUTTL_TEST='kuttl test --test <test-name>' make check-kuttl `
27+ - using ` kubectl kuttl --test ` flag: ` kubectl kuttl test testing/kuttl/e2e --test <test-name> `
Original file line number Diff line number Diff line change 1+ apiVersion : postgres-operator.crunchydata.com/v1beta1
2+ kind : PostgresCluster
3+ metadata :
4+ name : cluster-start
5+ status :
6+ instances :
7+ - name : instance1
8+ readyReplicas : 1
9+ replicas : 1
10+ updatedReplicas : 1
11+ ---
12+ apiVersion : batch/v1
13+ kind : Job
14+ metadata :
15+ labels :
16+ postgres-operator.crunchydata.com/cluster : cluster-start
17+ postgres-operator.crunchydata.com/pgbackrest-backup : replica-create
18+ status :
19+ succeeded : 1
Original file line number Diff line number Diff line change 1+ apiVersion : postgres-operator.crunchydata.com/v1beta1
2+ kind : PostgresCluster
3+ metadata :
4+ name : cluster-start
5+ spec :
6+ image : registry.developers.crunchydata.com/crunchydata/crunchy-postgres:centos8-13.4-1
7+ postgresVersion : 13
8+ instances :
9+ - name : instance1
10+ dataVolumeClaimSpec :
11+ accessModes :
12+ - " ReadWriteOnce"
13+ resources :
14+ requests :
15+ storage : 1Gi
16+ backups :
17+ pgbackrest :
18+ image : registry.developers.crunchydata.com/crunchydata/crunchy-pgbackrest:centos8-2.35-0
19+ repos :
20+ - name : repo1
21+ volume :
22+ volumeClaimSpec :
23+ accessModes :
24+ - " ReadWriteOnce"
25+ resources :
26+ requests :
27+ storage : 1Gi
Original file line number Diff line number Diff line change 1+ apiVersion : kuttl.dev/v1beta1
2+ kind : TestStep
3+ commands :
4+ - script : CLUSTER=cluster-start $HOME/postgres-operator/testing/kuttl/script/port-forward.sh
5+ background : true
6+ # this sleep is needed when running in cloud environments to ensure connection-psql.sh
7+ # will not fail when attempting the port-forward and has suffient time to connect, may
8+ # not be needed when running locally
9+ - script : sleep 10
10+ - script : CLUSTER=cluster-start $HOME/postgres-operator/testing/kuttl/script/connect-psql.sh
Original file line number Diff line number Diff line change 1+ apiVersion : kuttl.dev/v1beta1
2+ kind : TestSuite
3+ testDirs :
4+ - testing/kuttl/e2e/
5+ timeout : 120
6+ parallel : 2
7+ # by default kuttl will run in a generated namespace to override
8+ # that functionality simply uncomment the line below and replace
9+ # postgres-operator with the desired namespace to run in.
10+ # namespace: postgres-operator
11+ suppress :
12+ - events
13+
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+ CLUSTER=${CLUSTER:- default}
3+ PG_CLUSTER_USER_SECRET_NAME=${PG_CLUSTER_USER_SECRET_NAME:- $CLUSTER -pguser-$CLUSTER }
4+
5+ PGPASSWORD=$( kubectl get secrets -n $NAMESPACE " ${PG_CLUSTER_USER_SECRET_NAME} " -o go-template=' {{.data.password | base64decode}}' ) \
6+ PGUSER=$( kubectl get secrets -n $NAMESPACE " ${PG_CLUSTER_USER_SECRET_NAME} " -o go-template=' {{.data.user | base64decode}}' ) \
7+ PGDATABASE=$( kubectl get secrets -n $NAMESPACE " ${PG_CLUSTER_USER_SECRET_NAME} " -o go-template=' {{.data.dbname | base64decode}}' ) \
8+ psql -h localhost -c " select version();"
Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+ CLUSTER=${CLUSTER:- default}
3+ export PG_CLUSTER_PRIMARY_POD=$( kubectl get pod -n $NAMESPACE -o name -l postgres-operator.crunchydata.com/cluster=$CLUSTER ,postgres-operator.crunchydata.com/role=master)
4+ kubectl -n $NAMESPACE port-forward " ${PG_CLUSTER_PRIMARY_POD} " 5432:5432
You can’t perform that action at this time.
0 commit comments