diff --git a/integration/README.md b/integration/README.md new file mode 100644 index 0000000..880c86d --- /dev/null +++ b/integration/README.md @@ -0,0 +1,32 @@ +## Integration tests + +### Prerequisites + +The integration/e2e tests have the following prerequisites: + + * an environment variable `CLUSTER_MANIFEST_FILE` pointing to the cluster manifest. Cluster manifests can be produced with the help of the templates found under `templates`. For example: + ``` + export AWS_REGION=us-east-1 + export AWS_SSH_KEY_NAME=capi + export CONTROL_PLANE_MACHINE_COUNT=3 + export WORKER_MACHINE_COUNT=3 + export AWS_CREATE_BASTION=false + export AWS_PUBLIC_IP=false + export AWS_CONTROL_PLANE_MACHINE_FLAVOR=t3.large + export AWS_NODE_MACHINE_FLAVOR=t3.large + clusterctl generate cluster test-ci-cluster --from "bootstrap/templates/cluster-template-aws.yaml" --kubernetes-version 1.25.0 > cluster.yaml + export CLUSTER_MANIFEST_FILE=$PWD/cluster.yaml + ``` + + * `clusterctl` available in the PATH + + * `kubectl` available in the PATH + + * a management cluster initialised via `clusterctl` with the infrastructure targeted as well as the version of the MicroK8s providers we want to be tested + + * the `kubeconfig` of the management cluster in the default location `$HOME/.kube/config` + + +### Running the tests + +Just execute the `test.sh`. diff --git a/integration/test.sh b/integration/test.sh index b0c89cc..25dea22 100644 --- a/integration/test.sh +++ b/integration/test.sh @@ -2,8 +2,11 @@ set -ex -_DIR="${BASH_SOURCE%/*}" -if [[ ! -d "$_DIR" ]]; then _DIR="$PWD"; fi +if [[ -z "${CLUSTER_MANIFEST_FILE}" ]]; then + echo "Environemnt variable CLUSTER_MANIFEST_FILE is not set." + echo "CLUSTER_MANIFEST_FILE is expected to hold the PATH to a cluster manifest." + exit 1 +fi while ! kubectl wait --for=condition=available deploy/capi-microk8s-bootstrap-controller-manager -n capi-microk8s-bootstrap-system; do echo "Waiting for bootstrap controller to come up" @@ -16,28 +19,14 @@ done echo "Deploy a test cluster" -# generate cluster -export AWS_REGION=us-east-1 -export AWS_SSH_KEY_NAME=capi -export CONTROL_PLANE_MACHINE_COUNT=3 -export WORKER_MACHINE_COUNT=3 -export AWS_CREATE_BASTION=false -export AWS_PUBLIC_IP=false -export AWS_CONTROL_PLANE_MACHINE_FLAVOR=t3.large -export AWS_NODE_MACHINE_FLAVOR=t3.large -clusterctl generate cluster test-ci-cluster --from "${_DIR}/../templates/cluster-template-aws.yaml" --kubernetes-version 1.25.0 > cluster.yaml - function cleanup() { set +e kubectl delete cluster test-ci-cluster } trap cleanup EXIT -# have AWS infrastructure provider logs running -kubectl logs -n capa-system deploy/capa-controller-manager -f & - # deploy cluster -kubectl apply -f cluster.yaml +kubectl apply -f ${CLUSTER_MANIFEST_FILE} # get cluster kubeconfig while ! clusterctl get kubeconfig test-ci-cluster > ./kubeconfig; do @@ -52,7 +41,7 @@ cat ./kubeconfig # wait for nodes to come up while ! kubectl --kubeconfig=./kubeconfig get node | grep "Ready" | wc -l | grep 6; do - kubectl get cluster,machines,awscluster,awsmachines || true + kubectl get cluster,machines || true kubectl --kubeconfig=./kubeconfig get node,pod -A || true echo waiting for 6 nodes to become ready