This repository sets up Flux to use Testkube to generate testing resource manifests that Flux will then apply to a Kubernetes cluster. This repository covers the steps to do that.
1. Fork this repository and clone it locally
git clone https://github.com/$GITHUB_USER/testkube-flux.git
You can use Minikube, Kind or any managed cluster with a cloud provider (EKS, GKE, etc). In this example we're using Kind.
kind create cluster
Must be of type Classic (i.e. starts with ghp_
)
GITHUB_TOKEN=<ghp_>
GITHUB_USER=<username>
And export the environment variables in your terminal.
Install the Flux CLI and run:
flux bootstrap github \
--owner=$GITHUB_USER \
--repository=testkube-flux \
--path=cluster \
--personal
The following command will create Flux source to tell Flux to apply changes that are created in your repository:
flux create source git testkube-tests \
--url=https://github.com/$GITHUB_USER/testkube-flux \
--branch=main \
--interval=30s \
--export > ./cluster/flux-system/sources/testkube-tests/test-source.yaml
And now create a Flux Kustomize Controller to apply the Testkube Test CRDs in the cluser using Kustomize:
flux create kustomization testkube-test \
--target-namespace=testkube \
--source=testkube-tests \
--path="cluster/testkube" \
--prune=true \
--interval=30s \
--export > ./cluster/flux-system/sources/testkube-tests/testkube-kustomization.yaml
Install the Testkube CLI from https://kubeshop.github.io/testkube/installing
And run the following command to install Testkube and its components in the cluster:
testkube install
In this example the test being used is a Postman test, which you can find in /img/server/tests/postman-collection.json
.
To create a Kubernetes CRD for the test, run:
testkube generate tests-crds img/server/tests/postman-collection.json > cluster/testkube/server-postman-test.yaml
The name of the test file created in the previous step is server-postman-test.yaml
, add that to the Kustomize file located in cluster/testkube/kustomization.yaml
:
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
+ - server-postman-test.yaml
git pull origin main
git add -A && git commit -m "Configure Testkube tests"
git push
To see if Flux detected your changes run:
flux get kustomizations --watch
And to ensure that the test has been created run:
testkube get test
NAME | TYPE | CREATED | LABELS |
--------------------------+--------------------+-------------------------------+---------------------------------------------------+
postman-collection-test | postman/collection | 2023-01-30 18:04:13 +0000 UTC | kustomize.toolkit.fluxcd.io/name=testkube-test, |
| | | kustomize.toolkit.fluxcd.io/namespace=flux-system |