-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> Co-authored-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
- Loading branch information
1 parent
50e5a45
commit 77ae277
Showing
9 changed files
with
168 additions
and
164 deletions.
There are no files selected for viewing
This file contains 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,120 @@ | ||
# Leverage assertions trees | ||
|
||
Whether verifying the scaling behavior of a database cluster or ensuring data consistency across instances, Chainsaw's assertion model provides the precision and flexibility needed for comprehensive validation. | ||
|
||
Chainsaw allows declaring complex assertions with a simple and no-code approach, allowing assertions based on comparisons beyond simple equality, working with arrays, and other scenarios that could not be achieved before. | ||
|
||
!!! tip | ||
Under the hood, Chainsaw uses [kyverno-json assertion trees](https://kyverno.github.io/kyverno-json/latest/intro/). Refer to the assertion trees documentation for more details on the supported syntax. | ||
|
||
## Comparisons beyond simple equality | ||
|
||
The assertion below will check that the number of replicas for a deployment is **greater than 3**. | ||
|
||
Chainsaw doesn't need to know the exact expected number of replicas. | ||
The `(replicas > 3)` expression will be evaluated until the assertion passes or the operation timeout expires (making the assertion fail). | ||
|
||
```yaml | ||
apiVersion: chainsaw.kyverno.io/v1alpha1 | ||
kind: Test | ||
metadata: | ||
name: example | ||
spec: | ||
steps: | ||
- try: | ||
# ... | ||
- assert: | ||
resource: | ||
apiVersion: v1 | ||
kind: Deployment | ||
metadata: | ||
name: foo | ||
spec: | ||
(replicas > 3): true | ||
# ... | ||
``` | ||
|
||
## Working with arrays | ||
|
||
Chainsaw query language makes it easy to assert on arrays. | ||
You can filter and transform arrays to select what you want to assert. | ||
|
||
### Filtering | ||
|
||
In the example below we are creating a resource, then we assert that a condition with `type == 'Ready'` exists and has a field matching `status: 'True'`: | ||
|
||
```yaml | ||
apiVersion: chainsaw.kyverno.io/v1alpha1 | ||
kind: Test | ||
metadata: | ||
name: example | ||
spec: | ||
steps: | ||
- try: | ||
- apply: | ||
resource: | ||
apiVersion: tempo.grafana.com/v1alpha1 | ||
kind: TempoStack | ||
metadata: | ||
name: simplest | ||
spec: | ||
storage: | ||
secret: | ||
name: minio | ||
type: s3 | ||
# ... | ||
- assert: | ||
resource: | ||
apiVersion: tempo.grafana.com/v1alpha1 | ||
kind: TempoStack | ||
metadata: | ||
name: simplest | ||
status: | ||
# filter conditions array to keep elements where `type == 'Ready'` | ||
# and assert there's a single element matching the filter | ||
# and that this element status is `True` | ||
(conditions[?type == 'Ready']): | ||
- status: 'True' | ||
``` | ||
## Comprehensive reporting | ||
Chainsaw offers detailed resource diffs upon assertion failures. In the example below, the assertion failure message `metadata.annotations.foo: Invalid value: "null": Expected value: "bar"` is augmented with a resource diff. | ||
|
||
It provides a clear view of discrepancies between expected and actual resources and gives more context around the specific failure (we can easily identify the owner of the offending pod for example). | ||
|
||
``` | ||
| 09:55:50 | deployment | step-1 | ASSERT | RUN | v1/Pod @ chainsaw-rare-liger/* | ||
| 09:56:20 | deployment | step-1 | ASSERT | ERROR | v1/Pod @ chainsaw-rare-liger/* | ||
=== ERROR | ||
--------------------------------------------------- | ||
v1/Pod/chainsaw-rare-liger/example-5477b4ff8c-tnhd9 | ||
--------------------------------------------------- | ||
* metadata.annotations.foo: Invalid value: "null": Expected value: "bar" | ||
|
||
--- expected | ||
+++ actual | ||
@@ -1,10 +1,16 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
- annotations: | ||
- foo: bar | ||
labels: | ||
app: nginx | ||
+ name: example-5477b4ff8c-tnhd9 | ||
namespace: chainsaw-rare-liger | ||
+ ownerReferences: | ||
+ - apiVersion: apps/v1 | ||
+ blockOwnerDeletion: true | ||
+ controller: true | ||
+ kind: ReplicaSet | ||
+ name: example-5477b4ff8c | ||
+ uid: 118abe16-ec42-4894-83db-64479c4aac6f | ||
spec: {} | ||
| 09:56:20 | deployment | step-1 | TRY | DONE | | ||
``` | ||
## Next step | ||
To continue our exploration of the main Chainsaw features, let's look at [bindings and resource templating](./resource-templating.md). |
This file contains 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
This file contains 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,3 @@ | ||
# Multi-cluster setup | ||
|
||
TODO |
This file contains 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,29 @@ | ||
# Next steps | ||
|
||
We covered the main features of Chainsaw in this **Getting started** sections. | ||
|
||
While this should help you understand Chainsaw better, there are a lot of other things Chainsaw can do for you. | ||
|
||
!!! tip | ||
If there's anything you would like to be improved, please [reach out](./community.md), we will be happy to discuss and improve as much as we can. | ||
|
||
To continue exploring the capabilities of Chainsaw: | ||
|
||
- Browse advanced use case discovery guides | ||
- Look at the Chainsaw configuration options | ||
- Consult the reference documentation for details about something specific | ||
- Familiarize with examples | ||
- Engage with our community and start contributing | ||
|
||
--- | ||
|
||
## Additional resources | ||
|
||
Resources, blog posts and videos talking about Chainsaw: | ||
|
||
- [Kyverno Chainsaw - The ultimate end-to-end testing tool!](https://kyverno.io/blog/2023/12/12/kyverno-chainsaw-the-ultimate-end-to-end-testing-tool/) | ||
- [Kyverno Chainsaw - Exploring the Power of Assertion Trees!](https://kyverno.io/blog/2023/12/13/kyverno-chainsaw-exploring-the-power-of-assertion-trees/) | ||
- [Nirmata Office Hours for Kyverno- Episode 9- Demonstrate Kyverno Chainsaw](https://www.youtube.com/watch?v=IrIteTTjlbU) | ||
- [Kubebuilder Community Meeting - February 1, 2024](https://www.youtube.com/watch?v=Ejof-wtAdQM) | ||
- [Kyverno Chainsaw 0.1.4 - Awesome new features!](https://kyverno.io/blog/2024/02/15/kyverno-chainsaw-0.1.4-awesome-new-features/) | ||
- [Mastering Kubernetes Testing with Kyverno Chainsaw!](https://youtu.be/hQJWGzogIiI) |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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