Skip to content

Commit bb507ba

Browse files
committed
docs( cluster ): Kyverno Chainsaw testing documentation
Signed-off-by: Itay Grudev <itay@verito.digital>
1 parent 8298eb9 commit bb507ba

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed

charts/cluster/TESTING.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Testing
2+
3+
This chart uses Kyverno Chainsaw and implements end-to-end (E2E) tests for common features. Not everything is tested because of inadequate tooling — for example, local simulation of Azure and Google Cloud Storage. We do test S3 via MinIO. Our aim is that every critical feature that is technically feasible to test is covered.
4+
5+
We use a local kind cluster (minikube also works) and provision prerequisites such as the CloudNativePG operator, Prometheus CRDs, and MinIO. Then we run the `chainsaw` utility, which executes the individual tests. It can run tests in parallel, which is essential because some tests take over five minutes to complete.
6+
7+
## Procedure
8+
9+
1. Create a kind cluster.
10+
11+
```bash
12+
kind delete cluster kind
13+
```
14+
15+
2. Install the CloudNativePG operator
16+
17+
```bash
18+
helm dependency update charts/cloudnative-pg
19+
helm upgrade \
20+
--install \
21+
--namespace $NAMESPACE \
22+
--create-namespace \
23+
--set config.clusterWide=$CLUSTER_WIDE \
24+
--wait \
25+
cnpg charts/cloudnative-pg
26+
```
27+
28+
3. Install the Prometheus CRDs (optional, but required for monitoring tests)
29+
30+
```bash
31+
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
32+
helm install prometheus-crds prometheus-community/prometheus-operator-crds
33+
```
34+
35+
4. Install MinIO (optional, but required for backup/recovery tests).
36+
37+
```bash
38+
helm repo add minio-operator https://operator.min.io
39+
helm upgrade \
40+
--install \
41+
--namespace minio-system \
42+
--create-namespace \
43+
--wait \
44+
operator minio-operator/operator
45+
46+
helm upgrade \
47+
--install \
48+
--namespace minio \
49+
--create-namespace \
50+
--wait \
51+
--values ./.github/minio.yaml \
52+
tenant minio-operator/tenant
53+
```
54+
55+
5. Install Kyverno Chainsaw
56+
57+
Refer to the [Kyverno Chainsaw Installation](https://kyverno.io/blog/2023/12/12/kyverno-chainsaw-the-ultimate-end-to-end-testing-tool/#install-chainsaw) documentation for platform specific instructions.
58+
59+
You can also install Kyverno Chainsaw from source if you have _Go_ installed:
60+
61+
```bash
62+
go install github.com/kyverno/chainsaw@latest
63+
```
64+
65+
6. Run the tests
66+
67+
To run the whole test suite:
68+
69+
```bash
70+
chainsaw test charts/cluster
71+
```
72+
73+
To run a specific test, specify its directory path. Example:
74+
75+
```bash
76+
chainsaw test charts/cluster/test/postgresql-cluster-configuration
77+
```
78+
79+
## Test structure
80+
81+
We are only going to outline the test structure here. Refer to the [Kyverno Chainsaw](https://kyverno.github.io/chainsaw/latest/quick-start/) documentation for full reference and capabilities.
82+
The tests are located in the `test` directory. Each test has its own subdirectory. Because clusters take time to provision, where it makes sense tests should be combined and executed sequentially on the same cluster. One exception is critical functionality such as backup/restore, which should be tested independently.
83+
84+
Inside each test there is a `chainsaw-test.yaml` file that outlines the steps of that particular test. Here are some tips for writing tests for CloudNativePG:
85+
86+
* Whenever you're adding new features, make sure at the very least to update the `postgresql-cluster-configuration` test that verifies that all non-default configuration options are passed and applied correctly. We're unlikely to merge PRs that don't have their own test or update this one.
87+
* Always manually uninstall Helm chart resources to speed up cleanup.
88+
* Where applicable, and for steps likely to fail, add `catch` statements. For example:
89+
90+
```yaml
91+
catch:
92+
- describe:
93+
apiVersion: batch/v1
94+
kind: Job
95+
- describe:
96+
apiVersion: postgresql.cnpg.io/v1
97+
kind: Cluster
98+
- podLogs:
99+
selector: batch.kubernetes.io/job-name=your-job-name
100+
```
101+
102+
This will substantially help with debugging later.
103+
* Provide useful step descriptions to aid in understanding test failures.
104+
* Use reasonable test timeouts so tests fail if something isn't finished after 5–10 minutes. Aim for tests to complete within 10 minutes.

0 commit comments

Comments
 (0)