-
Notifications
You must be signed in to change notification settings - Fork 216
docs( cluster ): Kyverno Chainsaw testing documentation #759
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
Open
itay-grudev
wants to merge
6
commits into
main
Choose a base branch
from
docs/cluster-testing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bb507ba
docs( cluster ): Kyverno Chainsaw testing documentation
itay-grudev ebb18a8
Fixed errata kind create cluster
itay-grudev c19c2ba
Update TESTING.md
itay-grudev 08de604
Merge branch 'main' into docs/cluster-testing
itay-grudev 7b797a2
Merge branch 'main' into docs/cluster-testing
itay-grudev 607a5cf
Merge branch 'main' into docs/cluster-testing
itay-grudev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| # Testing | ||
|
|
||
| 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. | ||
|
|
||
| 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. | ||
|
|
||
| ## Procedure | ||
|
|
||
| 1. Create a kind cluster. | ||
|
|
||
| ```bash | ||
| kind create cluster | ||
| ``` | ||
|
|
||
| 2. Install the CloudNativePG operator | ||
|
|
||
| ```bash | ||
| helm dependency update charts/cloudnative-pg | ||
| helm upgrade \ | ||
| --install \ | ||
| --namespace $NAMESPACE \ | ||
| --create-namespace \ | ||
| --set config.clusterWide=$CLUSTER_WIDE \ | ||
| --wait \ | ||
| cnpg charts/cloudnative-pg | ||
| ``` | ||
|
|
||
| 3. Install the Prometheus CRDs (optional, but required for monitoring tests) | ||
|
|
||
| ```bash | ||
| helm repo add prometheus-community https://prometheus-community.github.io/helm-charts | ||
| helm install prometheus-crds prometheus-community/prometheus-operator-crds | ||
| ``` | ||
|
|
||
| 4. Install MinIO (optional, but required for backup/recovery tests). | ||
|
|
||
| ```bash | ||
| helm repo add minio-operator https://operator.min.io | ||
| helm upgrade \ | ||
| --install \ | ||
| --namespace minio-system \ | ||
| --create-namespace \ | ||
| --wait \ | ||
| operator minio-operator/operator | ||
|
|
||
| helm upgrade \ | ||
| --install \ | ||
| --namespace minio \ | ||
| --create-namespace \ | ||
| --wait \ | ||
| --values ./.github/minio.yaml \ | ||
| tenant minio-operator/tenant | ||
| ``` | ||
|
|
||
| 5. Install Kyverno Chainsaw | ||
|
|
||
| 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. | ||
|
|
||
| You can also install Kyverno Chainsaw from source if you have _Go_ installed: | ||
|
|
||
| ```bash | ||
| go install github.com/kyverno/chainsaw@latest | ||
| ``` | ||
|
|
||
| 6. Run the tests | ||
|
|
||
| To run the whole test suite: | ||
|
|
||
| ```bash | ||
| chainsaw test charts/cluster | ||
| ``` | ||
|
|
||
| To run a specific test, specify its directory path. Example: | ||
|
|
||
| ```bash | ||
| chainsaw test charts/cluster/test/postgresql-cluster-configuration | ||
| ``` | ||
|
|
||
| ## Test structure | ||
|
|
||
| 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. | ||
| 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. | ||
|
|
||
| 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: | ||
|
|
||
| * 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. | ||
| * Always manually uninstall Helm chart resources to speed up cleanup. | ||
| * Where applicable, and for steps likely to fail, add `catch` statements. For example: | ||
|
|
||
| ```yaml | ||
| catch: | ||
| - describe: | ||
| apiVersion: batch/v1 | ||
| kind: Job | ||
| - describe: | ||
| apiVersion: postgresql.cnpg.io/v1 | ||
| kind: Cluster | ||
| - podLogs: | ||
| selector: batch.kubernetes.io/job-name=your-job-name | ||
| ``` | ||
|
|
||
| This will substantially help with debugging later. | ||
| * Provide useful step descriptions to aid in understanding test failures. | ||
| * Use reasonable test timeouts so tests fail if something isn't finished after 5–10 minutes. Aim for tests to complete within 10 minutes. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.