diff --git a/e2e/.chainsaw.yaml b/e2e/.chainsaw.yaml new file mode 100755 index 000000000..e3644593c --- /dev/null +++ b/e2e/.chainsaw.yaml @@ -0,0 +1,12 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/configuration-chainsaw-v1alpha1.json +apiVersion: chainsaw.kyverno.io/v1alpha1 +kind: Configuration +metadata: + name: configuration +spec: + timeouts: + assert: 5m0s + cleanup: 5m0s + delete: 5m0s + error: 5m0s + exec: 5m0s diff --git a/e2e/Makefile b/e2e/Makefile index 40bc73aa1..a9b44c848 100644 --- a/e2e/Makefile +++ b/e2e/Makefile @@ -12,10 +12,10 @@ _runThisTest: cp $(ROOT_DIR)/e2e/Makefile $$D ;\ mkdir $$D/suit ;\ cp -r $(PWD) $$D/suit ;\ - ROOT_DIR=$(ROOT_DIR) KUBECONFIG="$(ROOT_DIR)/kubeconfig" kubectl-kuttl test --timeout 300 --skip-delete "$$D/suit" + ROOT_DIR=$(ROOT_DIR) KUBECONFIG="$(ROOT_DIR)/kubeconfig" chainsaw test --skip-delete "$$D/suit" runTestSuit: - @T="$$(KUBECONFIG="$$ROOT_DIR/kubeconfig" kubectl-kuttl test --timeout 300 --skip-delete --namespace "$$NAMESPACE" "$$TS" 2>&1)" ;\ + @T="$$(KUBECONFIG="$$ROOT_DIR/kubeconfig" chainsaw test --skip-delete --namespace "$$NAMESPACE" "$$TS" 2>&1)" ;\ echo "$$T" |\ grep -v harness.go |\ grep -v ^=== |\ diff --git a/e2e/README.MD b/e2e/README.MD deleted file mode 100644 index e86283df6..000000000 --- a/e2e/README.MD +++ /dev/null @@ -1,89 +0,0 @@ -# E2E Framework - -The E2E framework uses Kuttl under the hood. Kuttl is a simple and most importantly static tool. -That means there is no way to dynamically generate manifests. -The solution is KIK (Kuttl-In-Kuttl)! - -## Kuttl-In-Kuttl - -## How does it work - - - Instead of creating a static Kuttl manifest, you can create template. Template extension must be `.yml` otherwise Kuttl starts executing it. - - Template is rendered via `envsubst`, so you can use Bash variables for dynamic data injection. - - Variables always present - - `${KUBECONFIG}` - - `${NAMESPACE}` - - `${ROOT_DIR}` - - Example template -```yaml -apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 -kind: LinodeMachine -metadata: - ownerReferences: - - apiVersion: cluster.x-k8s.io/v1beta1 - kind: Machine - name: machine-sample - uid: ${MACHINE_UID} - name: linodemachine-sample -spec: - region: us-sea - type: g5-nanode-1 -``` - - - Helper tools are available, please create a Makefile in your test folder. In this way you can use built in helpers without including any script in the test, plus this file is a good place for test specific helpers. - - Example Makefile -```makefile -include ../../Makefile -``` - - - Template is nothing without a runner, please use helpers provided in Makefile to render and run template. - - Example template runner -```yaml -apiVersion: kuttl.dev/v1beta1 -kind: TestStep -commands: - - script: |- - MACHINE_UID="$(OBJ=machines/machine-sample make getKubeUid)" \ - TS="$(TPL="$PWD/02-create-linodemachine.tpl.yml" make renderTestCase)" make runTestSuit -``` - - - You can run testsuits (which can contain template rendering). - - Example testsuit runner: -```yaml -apiVersion: kuttl.dev/v1beta1 -kind: TestStep -commands: - - script: TS="$PWD/testsuit" make runTestSuit -``` - - - Test execution order is not guaranteed. If a test depends on another resource it is strongly suggested to create `assert` files to wait for an event. Almost every test depends on CAPI providers, so there is a good chance, you have to create a `00-assert.yaml` in your test folder. - - Example `00-assert.yaml`: -```yaml -apiVersion: apps/v1 -kind: Deployment -metadata: - name: capi-controller-manager - namespace: capi-system -status: - availableReplicas: 1 ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: cluster-api-provider-linode-controller-manager - namespace: cluster-api-provider-linode-system -status: - availableReplicas: 1 -``` - -## Executing individual test suit - -```bash -make _e2etest-infra # Only once per cluster! -(cd e2e/linodemachine-controller/minimal ; make runThisTest) -``` diff --git a/e2e/kuttl-config.yaml b/e2e/kuttl-config.yaml deleted file mode 100644 index a9abaa602..000000000 --- a/e2e/kuttl-config.yaml +++ /dev/null @@ -1,7 +0,0 @@ -apiVersion: kuttl.dev/v1beta1 -kind: TestSuite -testDirs: -- e2e/linodecluster-controller -- e2e/linodemachine-controller -- e2e/linodevpc-controller -timeout: 300 diff --git a/e2e/linodecluster-controller/minimal/02-create-linodecluster.tpl.yml b/e2e/linodecluster-controller/minimal/02-create-linodecluster.tpl.yml deleted file mode 100644 index 81aa7c0ba..000000000 --- a/e2e/linodecluster-controller/minimal/02-create-linodecluster.tpl.yml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 -kind: LinodeCluster -metadata: - name: linodecluster-sample - ownerReferences: - - apiVersion: cluster.x-k8s.io/v1beta1 - kind: Cluster - name: cluster-sample - uid: ${CLUSTER_UID} -spec: - region: us-sea diff --git a/e2e/linodecluster-controller/minimal/02-create-linodecluster.yaml b/e2e/linodecluster-controller/minimal/02-create-linodecluster.yaml index 231b7ef0a..957c36513 100644 --- a/e2e/linodecluster-controller/minimal/02-create-linodecluster.yaml +++ b/e2e/linodecluster-controller/minimal/02-create-linodecluster.yaml @@ -1,6 +1,11 @@ -apiVersion: kuttl.dev/v1beta1 -kind: TestStep -commands: - - script: |- - CLUSTER_UID="$(OBJ=clusters/cluster-sample make getKubeUid)" \ - TS="$(TPL="$PWD/02-create-linodecluster.tpl.yml" make renderTestCase)" make runTestSuit +apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 +kind: LinodeCluster +metadata: + name: linodecluster-sample + ownerReferences: + - apiVersion: cluster.x-k8s.io/v1beta1 + kind: Cluster + name: cluster-sample + uid: (x_k8s_get($client, 'cluster.x-k8s.io/v1beta1', 'Cluster', $namespace, 'cluster-sample').metadata.uid) +spec: + region: us-sea diff --git a/e2e/linodecluster-controller/minimal/03-verify-nodebalancer.yaml b/e2e/linodecluster-controller/minimal/03-verify-nodebalancer.yaml deleted file mode 100644 index bd5d4cea2..000000000 --- a/e2e/linodecluster-controller/minimal/03-verify-nodebalancer.yaml +++ /dev/null @@ -1,5 +0,0 @@ -apiVersion: kuttl.dev/v1beta1 -kind: TestStep -commands: - - script: |- - URI="nodebalancers" FILTER="{\"tags\":\"$(OBJ=linodeclusters/linodecluster-sample make getKubeUid)\"}" make callLinodeApiGet | grep 'results": 1' diff --git a/e2e/linodecluster-controller/minimal/04-delete-linodecluster.yaml b/e2e/linodecluster-controller/minimal/04-delete-linodecluster.yaml deleted file mode 100644 index b8f205339..000000000 --- a/e2e/linodecluster-controller/minimal/04-delete-linodecluster.yaml +++ /dev/null @@ -1,6 +0,0 @@ -apiVersion: kuttl.dev/v1beta1 -kind: TestStep -delete: -- apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 - kind: LinodeCluster - name: linodecluster-sample diff --git a/e2e/linodecluster-controller/minimal/05-verify-nodebalancer-destroyed.yaml b/e2e/linodecluster-controller/minimal/05-verify-nodebalancer-destroyed.yaml deleted file mode 100644 index 6eb1db621..000000000 --- a/e2e/linodecluster-controller/minimal/05-verify-nodebalancer-destroyed.yaml +++ /dev/null @@ -1,5 +0,0 @@ -apiVersion: kuttl.dev/v1beta1 -kind: TestStep -commands: - - script: |- - URI="nodebalancers" FILTER="{\"tags\":\"$(OBJ=linodeclusters/linodecluster-sample make getKubeUid)\"}" make callLinodeApiGet | grep 'results": 0' diff --git a/e2e/linodecluster-controller/minimal/06-cleanup-cluster.yaml b/e2e/linodecluster-controller/minimal/06-cleanup-cluster.yaml deleted file mode 100644 index c0eb3fb3f..000000000 --- a/e2e/linodecluster-controller/minimal/06-cleanup-cluster.yaml +++ /dev/null @@ -1,5 +0,0 @@ -apiVersion: cluster.x-k8s.io/v1beta1 -kind: Cluster -metadata: - name: cluster-sample -spec: diff --git a/e2e/linodecluster-controller/minimal/chainsaw-test.yaml b/e2e/linodecluster-controller/minimal/chainsaw-test.yaml new file mode 100755 index 000000000..2e3823605 --- /dev/null +++ b/e2e/linodecluster-controller/minimal/chainsaw-test.yaml @@ -0,0 +1,41 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json +apiVersion: chainsaw.kyverno.io/v1alpha1 +kind: Test +metadata: + creationTimestamp: null + name: minimal +spec: + steps: + - name: step-00 + try: + - assert: + file: 00-assert.yaml + - name: step-01 + try: + - apply: + file: 01-create-cluster.yaml + - name: step-02 + try: + - apply: + file: 02-create-linodecluster.yaml + - assert: + file: 02-assert.yaml + - name: step-03 + try: + - script: + content: 'URI="nodebalancers" FILTER="{\"tags\":\"$(OBJ=linodeclusters/linodecluster-sample + make getKubeUid)\"}" make callLinodeApiGet | grep ''results": 1''' + - name: step-04 + try: + - delete: + ref: + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + kind: LinodeCluster + name: linodecluster-sample + - error: + file: 04-error.yaml + - name: step-05 + try: + - script: + content: 'URI="nodebalancers" FILTER="{\"tags\":\"$(OBJ=linodeclusters/linodecluster-sample + make getKubeUid)\"}" make callLinodeApiGet | grep ''results": 0''' diff --git a/e2e/linodemachine-controller/byovpc/01-create-cluster.yaml b/e2e/linodemachine-controller/byovpc/01-create-cluster.yaml deleted file mode 100644 index dc2cf4ccc..000000000 --- a/e2e/linodemachine-controller/byovpc/01-create-cluster.yaml +++ /dev/null @@ -1,11 +0,0 @@ -apiVersion: kuttl.dev/v1beta1 -kind: TestStep -commands: - - command: make createVPC - - script: |- - VPC_ID=$(make fetchVPCID) \ - TS="$(TPL="$PWD/01-create-vpc.tpl.yml" make renderTestCase)" make runTestSuit - - command: make enableVPC - - script: |- - VPC_UID="$(OBJ=linodevpcs/linodevpc-sample make getKubeUid)" \ - TS="$(TPL="$PWD/01-create-cluster.tpl.yml" make renderTestCase)" make runTestSuit diff --git a/e2e/linodemachine-controller/byovpc/02-create-linodemachine.yaml b/e2e/linodemachine-controller/byovpc/02-create-linodemachine.yaml deleted file mode 100644 index ad15f30bb..000000000 --- a/e2e/linodemachine-controller/byovpc/02-create-linodemachine.yaml +++ /dev/null @@ -1,6 +0,0 @@ -apiVersion: kuttl.dev/v1beta1 -kind: TestStep -commands: - - script: |- - MACHINE_UID="$(OBJ=machines/machine-sample make getKubeUid)" \ - TS="$(TPL="$PWD/02-create-linodemachine.tpl.yml" make renderTestCase)" make runTestSuit diff --git a/e2e/linodemachine-controller/byovpc/03-delete-linodemachine.yaml b/e2e/linodemachine-controller/byovpc/03-delete-linodemachine.yaml deleted file mode 100644 index 3bf5e64ad..000000000 --- a/e2e/linodemachine-controller/byovpc/03-delete-linodemachine.yaml +++ /dev/null @@ -1,6 +0,0 @@ -apiVersion: kuttl.dev/v1beta1 -kind: TestStep -delete: -- apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 - kind: LinodeMachine - name: linodemachine-sample diff --git a/e2e/linodemachine-controller/byovpc/04-verify-linode-instance.yaml b/e2e/linodemachine-controller/byovpc/04-verify-linode-instance.yaml deleted file mode 100644 index 4515f8566..000000000 --- a/e2e/linodemachine-controller/byovpc/04-verify-linode-instance.yaml +++ /dev/null @@ -1,5 +0,0 @@ -apiVersion: kuttl.dev/v1beta1 -kind: TestStep -commands: - - script: |- - URI="linode/instances" FILTER="{\"tags\":\"$(OBJ=linodemachines/linodemachine-sample make getKubeUid)\"}" make callLinodeApiGet | grep 'results": 0' diff --git a/e2e/linodemachine-controller/byovpc/chainsaw-test.yaml b/e2e/linodemachine-controller/byovpc/chainsaw-test.yaml new file mode 100755 index 000000000..03195bea2 --- /dev/null +++ b/e2e/linodemachine-controller/byovpc/chainsaw-test.yaml @@ -0,0 +1,60 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json +apiVersion: chainsaw.kyverno.io/v1alpha1 +kind: Test +metadata: + creationTimestamp: null + name: byovpc +spec: + steps: + - name: step-00 + try: + - assert: + file: 00-assert.yaml + - name: step-01 + try: + - command: + args: + - createVPC + entrypoint: make + - script: + content: |- + VPC_ID=$(make fetchVPCID) \ + TS="$(TPL="$PWD/01-create-vpc.tpl.yml" make renderTestCase)" make runTestSuit + - command: + args: + - enableVPC + entrypoint: make + - script: + content: |- + VPC_UID="$(OBJ=linodevpcs/linodevpc-sample make getKubeUid)" \ + TS="$(TPL="$PWD/01-create-cluster.tpl.yml" make renderTestCase)" make runTestSuit + - apply: + file: 01-create-cluster.tpl.yml + - apply: + file: 01-create-vpc.tpl.yml + - assert: + file: 01-assert.yaml + - name: step-02 + try: + - script: + content: |- + MACHINE_UID="$(OBJ=machines/machine-sample make getKubeUid)" \ + TS="$(TPL="$PWD/02-create-linodemachine.tpl.yml" make renderTestCase)" make runTestSuit + - apply: + file: 02-create-linodemachine.tpl.yml + - assert: + file: 02-assert.yaml + - name: step-03 + try: + - delete: + ref: + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + kind: LinodeMachine + name: linodemachine-sample + - error: + file: 03-error.yaml + - name: step-04 + try: + - script: + content: 'URI="linode/instances" FILTER="{\"tags\":\"$(OBJ=linodemachines/linodemachine-sample + make getKubeUid)\"}" make callLinodeApiGet | grep ''results": 0''' diff --git a/e2e/linodemachine-controller/minimal/02-create-linodemachine.tpl.yml b/e2e/linodemachine-controller/minimal/02-create-linodemachine.tpl.yml deleted file mode 100644 index 0a4b23b4e..000000000 --- a/e2e/linodemachine-controller/minimal/02-create-linodemachine.tpl.yml +++ /dev/null @@ -1,12 +0,0 @@ -apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 -kind: LinodeMachine -metadata: - ownerReferences: - - apiVersion: cluster.x-k8s.io/v1beta1 - kind: Machine - name: machine-sample - uid: ${MACHINE_UID} - name: linodemachine-sample -spec: - region: us-sea - type: g5-nanode-1 diff --git a/e2e/linodemachine-controller/minimal/02-create-linodemachine.yaml b/e2e/linodemachine-controller/minimal/02-create-linodemachine.yaml index ad15f30bb..b7ff6920b 100644 --- a/e2e/linodemachine-controller/minimal/02-create-linodemachine.yaml +++ b/e2e/linodemachine-controller/minimal/02-create-linodemachine.yaml @@ -1,6 +1,12 @@ -apiVersion: kuttl.dev/v1beta1 -kind: TestStep -commands: - - script: |- - MACHINE_UID="$(OBJ=machines/machine-sample make getKubeUid)" \ - TS="$(TPL="$PWD/02-create-linodemachine.tpl.yml" make renderTestCase)" make runTestSuit +apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 +kind: LinodeMachine +metadata: + ownerReferences: + - apiVersion: cluster.x-k8s.io/v1beta1 + kind: Machine + name: machine-sample + uid: (x_k8s_get($client, 'cluster.x-k8s.io/v1beta1', 'Machine', $namespace, 'machine-sample').metadata.uid) + name: linodemachine-sample +spec: + region: us-sea + type: g5-nanode-1 diff --git a/e2e/linodemachine-controller/minimal/03-delete-linodemachine.yaml b/e2e/linodemachine-controller/minimal/03-delete-linodemachine.yaml deleted file mode 100644 index 3bf5e64ad..000000000 --- a/e2e/linodemachine-controller/minimal/03-delete-linodemachine.yaml +++ /dev/null @@ -1,6 +0,0 @@ -apiVersion: kuttl.dev/v1beta1 -kind: TestStep -delete: -- apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 - kind: LinodeMachine - name: linodemachine-sample diff --git a/e2e/linodemachine-controller/minimal/04-verify-linode-instance.yaml b/e2e/linodemachine-controller/minimal/04-verify-linode-instance.yaml deleted file mode 100644 index 4515f8566..000000000 --- a/e2e/linodemachine-controller/minimal/04-verify-linode-instance.yaml +++ /dev/null @@ -1,5 +0,0 @@ -apiVersion: kuttl.dev/v1beta1 -kind: TestStep -commands: - - script: |- - URI="linode/instances" FILTER="{\"tags\":\"$(OBJ=linodemachines/linodemachine-sample make getKubeUid)\"}" make callLinodeApiGet | grep 'results": 0' diff --git a/e2e/linodemachine-controller/minimal/chainsaw-test.yaml b/e2e/linodemachine-controller/minimal/chainsaw-test.yaml new file mode 100755 index 000000000..b8601f848 --- /dev/null +++ b/e2e/linodemachine-controller/minimal/chainsaw-test.yaml @@ -0,0 +1,36 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json +apiVersion: chainsaw.kyverno.io/v1alpha1 +kind: Test +metadata: + creationTimestamp: null + name: minimal +spec: + steps: + - name: step-00 + try: + - assert: + file: 00-assert.yaml + - name: step-01 + try: + - apply: + file: 01-create-cluster.yaml + - name: step-02 + try: + - apply: + file: 02-create-linodemachine.tpl.yml + - assert: + file: 02-assert.yaml + - name: step-03 + try: + - delete: + ref: + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + kind: LinodeMachine + name: linodemachine-sample + - error: + file: 03-error.yaml + - name: step-04 + try: + - script: + content: 'URI="linode/instances" FILTER="{\"tags\":\"$(OBJ=linodemachines/linodemachine-sample + make getKubeUid)\"}" make callLinodeApiGet | grep ''results": 0''' diff --git a/e2e/linodevpc-controller/minimal/02-delete-vpc.yaml b/e2e/linodevpc-controller/minimal/02-delete-vpc.yaml deleted file mode 100644 index 193c292fd..000000000 --- a/e2e/linodevpc-controller/minimal/02-delete-vpc.yaml +++ /dev/null @@ -1,6 +0,0 @@ -apiVersion: kuttl.dev/v1beta1 -kind: TestStep -delete: -- apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 - kind: LinodeVPC - name: linodevpc-sample diff --git a/e2e/linodevpc-controller/minimal/03-verify-vpc.yaml b/e2e/linodevpc-controller/minimal/03-verify-vpc.yaml deleted file mode 100644 index 9d882abd6..000000000 --- a/e2e/linodevpc-controller/minimal/03-verify-vpc.yaml +++ /dev/null @@ -1,5 +0,0 @@ -apiVersion: kuttl.dev/v1beta1 -kind: TestStep -commands: - - script: |- - URI="vpcs" FILTER="{\"label\":\"CLi-$(OBJ=linodevpcs/linodevpc-sample make getKubeUid | sed 's/-//g')\"}" make callLinodeApiGet | grep 'results": 0' diff --git a/e2e/linodevpc-controller/minimal/chainsaw-test.yaml b/e2e/linodevpc-controller/minimal/chainsaw-test.yaml new file mode 100755 index 000000000..734a9f400 --- /dev/null +++ b/e2e/linodevpc-controller/minimal/chainsaw-test.yaml @@ -0,0 +1,33 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json +apiVersion: chainsaw.kyverno.io/v1alpha1 +kind: Test +metadata: + creationTimestamp: null + name: minimal +spec: + steps: + - name: step-00 + try: + - assert: + file: 00-assert.yaml + - name: step-01 + try: + - apply: + file: 01-create-vpc.yaml + - assert: + file: 01-assert.yaml + - name: step-02 + try: + - delete: + ref: + apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1 + kind: LinodeVPC + name: linodevpc-sample + - error: + file: 02-error.yaml + - name: step-03 + try: + - script: + content: 'URI="vpcs" FILTER="{\"label\":\"CLi-$(OBJ=linodevpcs/linodevpc-sample + make getKubeUid | sed ''s/-//g'')\"}" make callLinodeApiGet | grep ''results": + 0'''