Skip to content

Commit

Permalink
refactor kuttl tests to remove kuttl-in-kuttl
Browse files Browse the repository at this point in the history
  • Loading branch information
eljohnson92 committed Feb 28, 2024
1 parent 9b929d4 commit fd20ee5
Show file tree
Hide file tree
Showing 56 changed files with 251 additions and 265 deletions.
18 changes: 3 additions & 15 deletions e2e/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,9 @@ runThisTest:
_runThisTest:
@D="$$(mktemp -d)" ;\
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"

getKubeUid:
@kubectl get -o jsonpath='{.metadata.uid}' -n "$$NAMESPACE" "$$OBJ"

getKubeLabel:
@kubectl get -o jsonpath='{.spec.label}' -n "$$NAMESPACE" "$$OBJ"

patchKubeObj:
@kubectl patch --type=merge -p "$$PATCH" -n "$$NAMESPACE" "$$OBJ"

patchKubeObjStatus:
@kubectl patch --type=merge --subresource status -p "$$PATCH" -n "$$NAMESPACE" "$$OBJ"
mkdir $$D/suite ;\
cp -r $(PWD) $$D/suite ;\
ROOT_DIR=$(ROOT_DIR) KUBECONFIG="$(ROOT_DIR)/kubeconfig" kubectl-kuttl test --timeout 300 --skip-delete "$$D/suite"

callLinodeApiGet:
@curl -s -H "Authorization: Bearer $$LINODE_TOKEN" -H "X-Filter: $$FILTER" -H "Content-Type: application/json" "https://$(TARGET_API)/$(TARGET_API_VERSION)/$$URI"
Expand Down
20 changes: 3 additions & 17 deletions e2e/README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

The E2E framework uses Kuttl under the hood. Kuttl is a simple and most importantly static tool that handles applying manifests for running assertions in a namespace it generates for each test.

In order to dynamically generate manifests, Kuttl supports declaring a `TestStep` manifest which includes an option for running scripts. This allows us apply manifests with dynamic values from stdin.

Additionally, helper functions can be invoked in the scripts by creating a Makefile in each test folder that references `../../Makefile` (i.e. `e2e/Makefile`).
Helper functions can be invoked in the scripts by creating a Makefile in each test folder that references `../../Makefile` (i.e. `e2e/Makefile`) in order to do custom validation.

## Example TestStep

Expand All @@ -13,20 +12,7 @@ apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- script: |-
cat <<EOF | kubectl apply -n $NAMESPACE -f -
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
kind: LinodeMachine
metadata:
ownerReferences:
- apiVersion: cluster.x-k8s.io/v1beta1
kind: Machine
name: machine-sample
uid: $(OBJ=machines/machine-sample make getKubeUid)
name: linodemachine-sample
spec:
region: us-sea
type: g5-nanode-1
EOF
URI="nodebalancers" FILTER="{\"label\":\"cluster-sample-api-server\"}" make callLinodeApiGet | grep 'results": 1'
```
## Test Execution
Expand Down Expand Up @@ -55,5 +41,5 @@ status:

```bash
make _e2etest-infra # Only once per cluster!
(cd e2e/linodemachine-controller/minimal ; make runThisTest)
(cd e2e/linodemachine-controller/minimal-linodemachine ; make runThisTest)
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- script: |-
URI="nodebalancers" FILTER="{\"label\":\"cluster-sample-api-server\"}" make callLinodeApiGet | grep 'results": 1'
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- script: |-
URI="nodebalancers" FILTER="{\"tags\":\"cluster-sample-api-server\"}" make callLinodeApiGet | grep 'results": 0'

This file was deleted.

This file was deleted.

69 changes: 0 additions & 69 deletions e2e/linodemachine-controller/byovpc/01-create-cluster.yaml

This file was deleted.

10 changes: 0 additions & 10 deletions e2e/linodemachine-controller/byovpc/01-vpc-create-options.json

This file was deleted.

18 changes: 0 additions & 18 deletions e2e/linodemachine-controller/byovpc/02-create-linodemachine.yaml

This file was deleted.

This file was deleted.

This file was deleted.

11 changes: 0 additions & 11 deletions e2e/linodemachine-controller/byovpc/Makefile

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
apiVersion: cluster.x-k8s.io/v1beta1
kind: Cluster
metadata:
name: linodemachine-cluster-sample
spec:
controlPlaneRef:
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
kind: KubeadmControlPlane
name: linodecluster-sample-control-plane
infrastructureRef:
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
kind: LinodeCluster
name: linodecluster-sample
---
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
kind: LinodeCluster
metadata:
name: linodecluster-sample
spec:
region: us-sea
23 changes: 23 additions & 0 deletions e2e/linodemachine-controller/minimal-linodemachine/02-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
kind: LinodeMachine
metadata:
labels:
cluster.x-k8s.io/cluster-name: linodemachine-cluster-sample
spec:
region: us-sea
type: g5-nanode-1
status:
ready: true
instanceState: running
---
apiVersion: cluster.x-k8s.io/v1beta1
kind: Machine
metadata:
labels:
cluster.x-k8s.io/cluster-name: linodemachine-cluster-sample
spec:
clusterName: cluster-sample
status:
bootstrapReady: true
infrastructureReady: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
kind: KubeadmControlPlane
metadata:
name: linodecluster-sample-control-plane
spec:
kubeadmConfigSpec:
clusterConfiguration:
apiServer:
extraArgs:
cloud-provider: external
controllerManager:
extraArgs:
cloud-provider: external
machineTemplate:
infrastructureRef:
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
kind: LinodeMachineTemplate
name: linodemachine-sample
replicas: 1
version: 1.29.1
---
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
kind: LinodeMachineTemplate
metadata:
name: linodemachine-sample
spec:
template:
spec:
region: us-sea
type: g5-nanode-1

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- script: |-
URI="linode/instances" FILTER="{\"tags\":\"linodecluster-sample\"}" make callLinodeApiGet | grep 'results": 1'
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
delete:
- apiVersion: cluster.x-k8s.io/v1beta1
kind: Cluster
name: cluster-sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- script: |-
URI="linode/instances" FILTER="{\"tags\":\"linodecluster-sample\"}" make callLinodeApiGet | grep 'results": 0'
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: cluster.x-k8s.io/v1beta1
kind: Cluster
metadata:
name: cluster-sample
spec:
43 changes: 0 additions & 43 deletions e2e/linodemachine-controller/minimal/01-create-cluster.yaml

This file was deleted.

10 changes: 0 additions & 10 deletions e2e/linodemachine-controller/minimal/02-assert.yaml

This file was deleted.

18 changes: 0 additions & 18 deletions e2e/linodemachine-controller/minimal/02-create-linodemachine.yaml

This file was deleted.

This file was deleted.

Loading

0 comments on commit fd20ee5

Please sign in to comment.