adomenech73 / testkube-flux

Devops guide and assets to use Testkube with Flux

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Testing cloud native applications with Flux and Testkube

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.

Manual Flux configuration

1. Fork this repository and clone it locally

git clone https://github.com/$GITHUB_USER/testkube-flux.git

2. Start a Kubernetes cluster

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

3. Create a Github Classic Token:

Must be of type Classic (i.e. starts with ghp_)

GITHUB_TOKEN=<ghp_>
GITHUB_USER=<username>

And export the environment variables in your terminal.

4. Install Flux in the cluster and connect it to the repository

Install the Flux CLI and run:

flux bootstrap github \
  --owner=$GITHUB_USER \
  --repository=testkube-flux \
  --path=cluster \
  --personal

5. Create a Flux Source and a Kusktomize Controller

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

6. Install Testkube in the cluster

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 

7. Create a Test CRD with testkube CLI

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

8. Add the generated test to the Kustomize file:

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

9. Push all the changes to your repository:

git pull origin main
git add -A && git commit -m "Configure Testkube tests"
git push

10. Your tests should be applied in the cluster:

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 |

About

Devops guide and assets to use Testkube with Flux

License:MIT License


Languages

Language:JavaScript 70.1%Language:Dockerfile 29.9%