Charmed PostgreSQL K8s
- By Canonical Data Platform
- Databases
Channel | Revision | Published | Runs on |
---|---|---|---|
latest/stable | 20 | 20 Sep 2022 | |
14/stable | 193 | 13 Mar 2024 | |
14/candidate | 248 | Yesterday | |
14/beta | 248 | 03 May 2024 | |
14/edge | 248 | 03 May 2024 |
juju deploy postgresql-k8s --channel 14/edge
Deploy Kubernetes operators easily with Juju, the Universal Operator Lifecycle Manager. Need a Kubernetes cluster? Install MicroK8s to create a full CNCF-certified Kubernetes system in under 60 seconds.
Platform:
Charm Testing
There are many types of software tests available, most of which are applicable for Charmed PostgreSQL K8s.
This reference addresses the following types:
- Smoke test
- Unit tests
- Integration tests
- System test
- Performance test
Note: All commands are written for juju >= v.3.0
If you are using an earlier version, be aware that:
juju run
replacesjuju run-action --wait
injuju v.2.9
juju integrate
replacesjuju relate
andjuju add-relation
injuju v.2.9
For more information, check the Juju 3.0 Release Notes.
Smoke test
This type of test ensures that basic functionality works over a short amount of time.
Steps
- Set up a
juju v.3.x
environment - Deploy database with test application
- Start “continuous write” test
juju add-model smoke-test
juju deploy postgresql-k8s --trust --channel 14/edge
juju scale-application postgresql-k8s 3 # (optional)
juju deploy postgresql-test-app
juju integrate postgresql-test-app:first-database postgresql-k8s
# Start "continuous write" test:
juju run postgresql-test-app/leader start-continuous-writes
export user=operator
export pass=$(juju run postgresql-k8s/leader get-password username=${user} | yq '.. | select(. | has("password")).password')
export relname=first-database
export ip=$(juju show-unit postgresql-k8s/0 --endpoint database | yq '.. | select(. | has("public-address")).public-address')
export db=$(juju show-unit postgresql-k8s/0 --endpoint database | yq '.. | select(. | has("database")).database')
export relid=$(juju show-unit postgresql-k8s/0 --endpoint database | yq '.. | select(. | has("relation-id")).relation-id')
export query="select count(*) from continuous_writes"
watch -n1 -x juju run postgresql-test-app/leader run-sql dbname=${db} query="${query}" relation-id=${relid} relation-name=${relname}
# OR
watch -n1 -x juju ssh --container postgresql postgresql-k8s/leader "psql postgresql://${user}:${pass}@${ip}:5432/${db} -c \"${query}\""
# Watch that the counter is growing!
Expected results
postgresql-test-app
continuously inserts records into the database received through the integration (the tablecontinuous_writes
).- The counters (amount of records in table) are growing on all cluster members
Tips
To stop the “continuous write” test, run
juju run postgresql-test-app/leader stop-continuous-writes
To truncate the “continuous write” table (i.e. delete all records from database), run
juju run postgresql-test-app/leader clear-continuous-writes
Unit tests
Check the “Contributing” guide and follow tox run -e unit
examples there.
Integration tests
Check the “Contributing” guide and follow tox run -e integration
examples there.
System test
Check/deploy the charm postgresql-k8s-bundle
(charmhub | git).
It deploys and tests all the necessary parts at once.
Performance test
Refer to the sysbench documentation.