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 29, 2024
1 parent e633152 commit c7b85bf
Show file tree
Hide file tree
Showing 60 changed files with 278 additions and 292 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ test: manifests generate fmt vet envtest ## Run tests.
e2etest:
make --no-print-directory _e2etest # Workaround to force the flag on Github Action

_e2etest-infra: kind ctlptl tilt kuttl kustomize clusterctl
local-deploy: kind ctlptl tilt kuttl kustomize clusterctl
@echo -n "LINODE_TOKEN=$(LINODE_TOKEN)" > config/default/.env.linode
$(CTLPTL) apply -f .tilt/ctlptl-config.yaml
$(TILT) ci --timeout 240s -f Tiltfile

_e2etest: manifests generate _e2etest-infra
_e2etest: manifests generate local-deploy
ROOT_DIR="$(PWD)" $(KUTTL) test --config e2e/kuttl-config.yaml

## --------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion docs/src/developers/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ go get <repository>@<version>
### Using tilt
To build a kind cluster and start Tilt, simply run:
```sh
make tilt-cluster
make local-deploy
```
Once your kind management cluster is up and running, you can
Expand Down
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
22 changes: 4 additions & 18 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-test-api-server\"}" make callLinodeApiGet | grep 'results": 1'
```
## Test Execution
Expand Down Expand Up @@ -54,6 +40,6 @@ status:
## Executing individual tests

```bash
make _e2etest-infra # Only once per cluster!
(cd e2e/linodemachine-controller/minimal ; make runThisTest)
make local-deploy # Only once per cluster!
(cd e2e/linodemachine-controller/minimal-linodemachine ; make runThisTest)
```
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
apiVersion: cluster.x-k8s.io/v1beta1
kind: Cluster
metadata:
name: cluster-sample
name: cluster-test
spec:
infrastructureRef:
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
kind: LinodeCluster
name: linodecluster-sample
name: linodecluster-test
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
kind: LinodeCluster
metadata:
name: linodecluster-sample
name: linodecluster-test
finalizers:
- infrastructure.cluster.x-k8s.io/v1alpha1
spec:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
kind: LinodeCluster
metadata:
name: linodecluster-sample
name: linodecluster-test
spec:
region: us-sea
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\":\"linodecluster-test-api-server\"}" 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-test
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
kind: LinodeCluster
metadata:
name: linodecluster-sample
name: linodecluster-test
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\":\"linodecluster-test-api-server\"}" make callLinodeApiGet | grep 'results": 0'
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: cluster.x-k8s.io/v1beta1
kind: Cluster
metadata:
name: cluster-sample
name: cluster-test
spec:

This file was deleted.

This file was deleted.

This file was deleted.

8 changes: 0 additions & 8 deletions e2e/linodemachine-controller/byovpc/01-assert.yaml

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.

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

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-test
spec:
controlPlaneRef:
apiVersion: controlplane.cluster.x-k8s.io/v1beta1
kind: KubeadmControlPlane
name: linodecluster-test-control-plane
infrastructureRef:
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
kind: LinodeCluster
name: linodemachine-test
---
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
kind: LinodeCluster
metadata:
name: linodemachine-test
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-test
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-test
spec:
clusterName: linodemachine-cluster-test
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-test-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-test
replicas: 1
version: 1.29.1
---
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha1
kind: LinodeMachineTemplate
metadata:
name: linodemachine-test
spec:
template:
spec:
region: us-sea
type: g5-nanode-1

Loading

0 comments on commit c7b85bf

Please sign in to comment.