Skip to content

Commit 397e34a

Browse files
committed
chore: migrate from kuttl to chainsaw
Signed-off-by: Charles-Edouard Brétéché <[email protected]>
1 parent 4bd23cb commit 397e34a

File tree

134 files changed

+1818
-893
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+1818
-893
lines changed

.chainsaw.yaml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/configuration-chainsaw-v1alpha1.json
2+
apiVersion: chainsaw.kyverno.io/v1alpha1
3+
kind: Configuration
4+
metadata:
5+
creationTimestamp: null
6+
name: configuration
7+
spec:
8+
parallel: 1
9+
reportFormat: JSON
10+
reportName: e2e
11+
timeouts:
12+
apply: 5m0s
13+
assert: 5m0s
14+
cleanup: 5m0s
15+
delete: 5m0s
16+
error: 5m0s
17+
exec: 5m0s

.github/workflows/ci-build.yaml

+2-14
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,8 @@ jobs:
4949
k3s-version: [ v1.27.1 ]
5050
# k3s-version: [v1.20.2, v1.19.2, v1.18.9, v1.17.11, v1.16.15]
5151
steps:
52-
- name: Download kuttl plugin
53-
env:
54-
KUTTL_VERSION: '0.10.0'
55-
KUTTL_PLUGIN_SUM: 'ad21c0d2be495a8f6cfc0821e592ae61afd191ebd453156d9b204e2524fceaf2'
56-
KUTTL_PLUGIN_FILENAME: 'kubectl-kuttl_0.10.0_linux_x86_64'
57-
run: |
58-
set -x
59-
echo ${KUTTL_PLUGIN_FILENAME}
60-
curl -OL https://github.com/kudobuilder/kuttl/releases/download/v${KUTTL_VERSION}/${KUTTL_PLUGIN_FILENAME}
61-
echo "${KUTTL_PLUGIN_SUM} ${KUTTL_PLUGIN_FILENAME}" | sha256sum -c -
62-
sudo mv ${KUTTL_PLUGIN_FILENAME} /usr/local/bin/kubectl-kuttl
63-
sudo chmod +x /usr/local/bin/kubectl-kuttl
64-
kubectl-kuttl version
52+
- name: Install chainsaw
53+
uses: kyverno/[email protected]
6554
- name: Install K3D
6655
run: |
6756
set -x
@@ -100,7 +89,6 @@ jobs:
10089
REDIS_CONFIG_PATH="build/redis" go run ./main.go 2>&1 | tee /tmp/e2e-operator-run.log &
10190
- name: Run tests
10291
run: |
103-
set -o pipefail
10492
bash hack/test.sh 2>&1 | tee /tmp/e2e-test.log
10593
- name: Upload operator logs
10694
uses: actions/upload-artifact@v2

.gitignore

-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ vendor/
2929
# transient build artifacts
3030
build/_output
3131

32-
kubeconfig
33-
kuttl-test.json
3432
e2e.json
3533

3634
# Desktop Services Store in macOS system

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/confi
125125
##@ E2E
126126

127127
e2e: ## Run operator e2e tests
128-
kubectl kuttl test ./tests/k8s --config ./tests/kuttl-tests.yaml
128+
chainsaw test ./tests/k8s
129129

130130
all: test install run e2e ## UnitTest, Run the operator locally and execute e2e tests.
131131

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ See the [documentation][docs] for installation and usage of the operator.
1313

1414
## E2E testing
1515

16-
E2E tests are written using [KUTTL](https://kuttl.dev/docs/#install-kuttl-cli). Please Install [KUTTL](https://kuttl.dev/docs/#install-kuttl-cli) to run the tests.
16+
E2E tests are written using [chainsaw](https://kyverno.github.io/chainsaw). Please Install [chainsaw](https://kyverno.github.io/chainsaw/latest/install/) to run the tests.
1717

1818
Note that the e2e tests for Redis HA mode require a cluster with at least three worker nodes. A local three-worker node
1919
cluster can be created using [k3d](https://k3d.io/)

docs/e2e-test-guide.md

+49-55
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Argo CD Operator E2E Test Guide
22

3-
E2E tests are written using [KUTTL](https://kuttl.dev/docs/#install-kuttl-cli).
3+
E2E tests are written using [chainsaw](https://kyverno.github.io/chainsaw/latest/install/).
44

55
## Requirements
66

77
This test suite assumes that an Argo CD Operator is installed on the cluster or running locally using `ARGOCD_CLUSTER_CONFIG_NAMESPACES=argocd-e2e-cluster-config make install run`.
88

99
The system executing the tests must have following tools installed:
1010

11-
* `kuttl` kubectl plugin (>= v0.11.1)
11+
* `chainsaw`
1212
* `oc` and `kubectl` client
1313
* `jq` for parsing JSON data
1414
* `curl`
@@ -47,28 +47,28 @@ make e2e
4747
make all
4848
```
4949

50-
### Running manual with kuttl
50+
### Running manual with chainsaw
5151

5252
```sh
53-
kubectl kuttl test ./tests/k8s --config ./tests/kuttl-tests.yaml
53+
chainsaw test ./tests/k8s
5454
```
5555

5656
### Running single tests
5757

5858
Sometimes (e.g. when initially writing a test or troubleshooting an existing
5959
one), you may want to run single test cases isolated. To do so, you can pass
60-
the name of the test using `--test` to `kuttl`, i.e.
60+
the test folder to chainsaw, i.e.
6161

6262
```sh
63-
kubectl kuttl test ./tests/k8s --config ./tests/kuttl-tests.yaml --test 1-004_validate_namespace_scoped_install
63+
chainsaw test ./tests/k8s/1-004_validate_namespace_scoped_install
6464
```
6565

6666
The name of the test is the name of the directory containing its steps and
6767
assertions.
6868

69-
If you are troubleshooting, you may want to prevent `kuttl` from deleting the
70-
test's namespace afterwards. In order to do so, just pass the additional flag
71-
`--skip-delete` to above command.
69+
If you are troubleshooting, you may want to prevent `chainsaw` from deleting the
70+
test's namespace afterward. To do so, just pass the additional flag
71+
`--skip-delete` to the above command.
7272

7373
## Writing new tests
7474

@@ -84,22 +84,8 @@ The `<test ID>` is the serial number of the test as defined in the Test Plan
8484
document. The `<short description>` is exactly that, a short description of
8585
what happens in the test.
8686

87-
### Name of the test steps
88-
89-
Each test step is a unique YAML file within the test's directory. The name of
90-
the step is defined by its file name.
91-
92-
The test steps must be named `XX-<name>.yaml`. This is a `kuttl` convention
93-
and cannot be overriden. `XX` is a number (prefixed with `0`, so step `1` must
94-
be `01`), and `<name>` is a free form value for the test step.
95-
96-
There are two reserved words you cannot use for `<name>`:
97-
98-
* `assert` contains positive assertions (i.e. resources that must exist) and
99-
* `errors` contains negative assertions (i.e. resources that must not exist)
100-
10187
Refer to the
102-
[kuttl documentation](https://kuttl.dev/docs)
88+
[chainsaw documentation](https://kyverno.github.io/chainsaw/latest/writing-tests/)
10389
for more information.
10490

10591
### Documentation
@@ -112,45 +98,49 @@ will help others in troubleshooting failing tests.
11298

11399
### Recipes
114100

115-
`kuttl` unfortunately neither encourages or supports re-use of your test steps
116-
and assertions yet.
117-
118101
Generally, you should try to use `assert` and `errors` declaration whenever
119102
possible and viable. For some cases, you may need to use custom scripts to
120103
get the results you are looking for.
121104

122105
#### Scripts general
123106

124-
Scripts can be executed in a `kuttl.dev/TestStep` resources from a usual test
125-
step declaration.
107+
Scripts can be executed in a `Test` resource.
126108

127109
Your script probably will retrieve some information, and asserts it state. If
128110
the assertion fails, the script should exit with a code > 0, and also print
129111
some information why it failed, e.g.
130112

131113
```yaml
132-
apiVersion: kuttl.dev/v1beta1
133-
kind: TestStep
134-
commands:
135-
- script: |
136-
# Get some piece of information...
137-
if test "$result" != "expected"; then
138-
echo "Expectation failed, should 'expected', is '$result'"
139-
exit 1
140-
fi
114+
apiVersion: chainsaw.kyverno.io/v1alpha1
115+
kind: Test
116+
metadata:
117+
name: example
118+
spec:
119+
steps:
120+
- script:
121+
content: |
122+
# Get some piece of information...
123+
if test "$result" != "expected"; then
124+
echo "Expectation failed, should 'expected', is '$result'"
125+
exit 1
126+
fi
141127
```
142128
143129
Also, you may want to use `set -e` and `set -o pipefail` at the top of your
144130
script to catch unexpected errors as test case failures, e.g.
145131

146132
```yaml
147-
apiVersion: kuttl.dev/v1beta1
148-
kind: TestStep
149-
commands:
150-
- script: |
151-
set -e
152-
set -o pipefail
153-
# rest of your script
133+
apiVersion: chainsaw.kyverno.io/v1alpha1
134+
kind: Test
135+
metadata:
136+
name: example
137+
spec:
138+
steps:
139+
- script:
140+
content: |
141+
set -e
142+
set -o pipefail
143+
# rest of your script
154144
```
155145

156146
#### Getting values of a resource's environment variables
@@ -165,14 +155,18 @@ of a variable named `FOO` for the `argocd-server` deployment in the test's
165155
namespace:
166156

167157
```yaml
168-
apiVersion: kuttl.dev/v1beta1
169-
kind: TestStep
170-
commands:
171-
- script: |
172-
val=$(kubectl get -n $NAMESPACE deployments argocd-server -o json \
173-
| jq -r '.spec.templates.spec.containers[0].env[]|select(.name=="FOO").value')
174-
if test "$val" != "bar"; then
175-
echo "Expectation failed for for env FOO in argocd-server: should 'bar', is '$val'"
176-
exit 1
177-
fi
158+
apiVersion: chainsaw.kyverno.io/v1alpha1
159+
kind: Test
160+
metadata:
161+
name: example
162+
spec:
163+
steps:
164+
- script:
165+
content: |
166+
val=$(kubectl get -n $NAMESPACE deployments argocd-server -o json \
167+
| jq -r '.spec.templates.spec.containers[0].env[]|select(.name=="FOO").value')
168+
if test "$val" != "bar"; then
169+
echo "Expectation failed for for env FOO in argocd-server: should 'bar', is '$val'"
170+
exit 1
171+
fi
178172
```

hack/test.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818

1919
set -e
2020

21-
kubectl kuttl test ./tests/k8s ./tests/ha --config ./tests/kuttl-tests.yaml
21+
chainsaw test ./tests/k8s ./tests/ha

tests/ha/1-020_validate_redis_ha_nonha/01-assert.yaml

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
apiVersion: kuttl.dev/v1beta1
2-
kind: TestAssert
3-
timeout: 720
4-
---
51
apiVersion: v1
62
kind: Service
73
metadata:
@@ -20,4 +16,4 @@ kind: Deployment
2016
metadata:
2117
name: example-argocd-redis
2218
status:
23-
readyReplicas: 1
19+
readyReplicas: 1

tests/ha/1-020_validate_redis_ha_nonha/02-assert.yaml

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
apiVersion: kuttl.dev/v1beta1
2-
kind: TestAssert
3-
timeout: 720
4-
---
51
apiVersion: v1
62
kind: Service
73
metadata:
@@ -45,9 +41,9 @@ spec:
4541
affinity:
4642
podAntiAffinity:
4743
requiredDuringSchedulingIgnoredDuringExecution:
48-
- labelSelector:
49-
matchLabels:
50-
app.kubernetes.io/name: example-argocd-redis-ha
44+
- labelSelector:
45+
matchLabels:
46+
app.kubernetes.io/name: example-argocd-redis-ha
5147
status:
5248
readyReplicas: 3
5349
---
@@ -56,4 +52,4 @@ kind: Deployment
5652
metadata:
5753
name: example-argocd-redis-ha-haproxy
5854
status:
59-
readyReplicas: 1
55+
readyReplicas: 1

tests/ha/1-020_validate_redis_ha_nonha/03-assert.yaml

-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
apiVersion: kuttl.dev/v1beta1
2-
kind: TestAssert
3-
timeout: 720
4-
---
51
apiVersion: argoproj.io/v1alpha1
62
kind: ArgoCD
73
metadata:
@@ -73,5 +69,3 @@ spec:
7369
memory: 128Mi
7470
status:
7571
readyReplicas: 3
76-
77-

tests/ha/1-020_validate_redis_ha_nonha/04-assert.yaml

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
apiVersion: kuttl.dev/v1beta1
2-
kind: TestAssert
3-
timeout: 720
4-
---
51
apiVersion: argoproj.io/v1alpha1
62
kind: ArgoCD
73
metadata:
@@ -15,4 +11,4 @@ kind: Deployment
1511
metadata:
1612
name: example-argocd-redis
1713
status:
18-
readyReplicas: 1
14+
readyReplicas: 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json
2+
apiVersion: chainsaw.kyverno.io/v1alpha1
3+
kind: Test
4+
metadata:
5+
creationTimestamp: null
6+
name: 1-020-validate-redis-ha-nonha
7+
spec:
8+
steps:
9+
- name: step-01
10+
try:
11+
- apply:
12+
file: 01-basic.yaml
13+
- assert:
14+
file: 01-assert.yaml
15+
- error:
16+
file: 01-errors.yaml
17+
- name: step-02
18+
try:
19+
- apply:
20+
file: 02-enable-ha.yaml
21+
- assert:
22+
file: 02-assert.yaml
23+
- error:
24+
file: 02-errors.yaml
25+
- name: step-03
26+
try:
27+
- apply:
28+
file: 03-update-ha-resources.yaml
29+
- assert:
30+
file: 03-assert.yaml
31+
- name: step-04
32+
try:
33+
- apply:
34+
file: 04-disable-ha.yaml
35+
- assert:
36+
file: 04-assert.yaml
37+
- error:
38+
file: 04-errors.yaml

tests/k8s/1-0017_validate_cmp/01-assert.yaml

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
# Increase the timeout for the first test because it needs to download
2-
# a number of container images
3-
apiVersion: kuttl.dev/v1beta1
4-
kind: TestAssert
5-
timeout: 720
6-
---
71
apiVersion: argoproj.io/v1alpha1
82
kind: ArgoCD
93
metadata:
@@ -23,9 +17,8 @@ status:
2317
apiVersion: v1
2418
kind: ConfigMap
2519
metadata:
26-
name: guestbook
27-
namespace: test-1-17-custom
2820
annotations:
2921
Bar: baz
3022
Foo: myfoo
31-
23+
name: guestbook
24+
namespace: test-1-17-custom

0 commit comments

Comments
 (0)