Skip to content

Commit

Permalink
Add e2e test in build workflows (#429)
Browse files Browse the repository at this point in the history
Co-authored-by: Tom Kerkhove <kerkhove.tom@gmail.com>
  • Loading branch information
JorTurFer and tomkerkhove authored Jun 29, 2022
1 parent 4c118bd commit 3ed9b3d
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/build_canary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,21 @@ jobs:
file: scaler/Dockerfile
context: .
push: true

e2e_tests:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3

- name: Helm install
uses: Azure/setup-helm@v1

- name: Create k8s v1.23 Kind Cluster
uses: helm/kind-action@main
with:
node_image: kindest/node:v1.23.0@sha256:49824ab1727c04e56a21a5d8372a402fcd32ea51ac96a2706a12af38934f81ac
cluster_name: http-add-on-smoke-tests-cluster

- name: Run e2e test
run: |
./tests/e2e-test.sh
20 changes: 20 additions & 0 deletions .github/workflows/build_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,23 @@ jobs:
file: scaler/Dockerfile
context: .
push: true

e2e_tests:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3

- name: Helm install
uses: Azure/setup-helm@v1

- name: Create k8s v1.23 Kind Cluster
uses: helm/kind-action@main
with:
node_image: kindest/node:v1.23.0@sha256:49824ab1727c04e56a21a5d8372a402fcd32ea51ac96a2706a12af38934f81ac
cluster_name: http-add-on-smoke-tests-cluster

- name: Run e2e test
run: |
./tests/e2e-test.sh
env:
TAG: ${{ steps.get_version.outputs.VERSION }}
104 changes: 104 additions & 0 deletions tests/e2e-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/bin/bash

TAG=${TAG:-canary}

# Install KEDA
helm repo add kedacore https://kedacore.github.io/charts
helm repo update
helm upgrade --install keda kedacore/keda --namespace keda --create-namespace --wait

# Show Kubernetes resources in keda namespace
kubectl get all --namespace keda

# Install Http-add-on
helm upgrade --install http-add-on kedacore/keda-add-ons-http --set images.tag=$TAG --namespace keda --create-namespace --wait

# Show Kubernetes resources in http-add-on namespace
kubectl get all --namespace http-add-on

# Create resources
kubectl create ns app
helm upgrade --install xkcd ./examples/xkcd -n app --wait

# Show Kubernetes resources in app namespace
kubectl get all --namespace app

# Check http-add-on generated ScaledObject
n=0
max=5
until [ "$n" -ge "$max" ]
do
ready=$(kubectl get so xkcd-app -n app -o jsonpath="{.status.conditions[0].status}")
echo "ready: $ready"
if [ $ready == "True" ]; then
break
fi
n=$((n+1))
sleep 15
done
if [ $n -eq $max ]; then
echo "The ScaledObject is not working correctly"
exit 1
fi
echo "The ScaledObject is working correctly"

# Check that deployment has 0 instances
n=0
max=5
until [ "$n" -ge "$max" ]
do
replicas=$(kubectl get deploy xkcd -n app -o jsonpath="{.spec.replicas}")
echo "replicas: $replicas"
if [ $replicas == "0" ]; then
break
fi
n=$((n+1))
sleep 15
done
if [ $n -eq $max ]; then
echo "Current replica count is not 0"
exit 1
fi
echo "The workflow is scaled to zero"

# Generate one request
cat <<EOF | kubectl apply -f -
apiVersion: batch/v1
kind: Job
metadata:
name: generate-request
namespace: app
spec:
template:
spec:
containers:
- name: curl-client
image: curlimages/curl
imagePullPolicy: Always
command: ["curl", "-H", "Host: myhost.com", "keda-add-ons-http-interceptor-proxy.keda:8080"]
restartPolicy: Never
activeDeadlineSeconds: 600
backoffLimit: 5
EOF

# Check that deployment has 1 instances
n=0
max=5
until [ "$n" -ge "$max" ]
do
replicas=$(kubectl get deploy xkcd -n app -o jsonpath="{.spec.replicas}")
echo "replicas: $replicas"
if [ $replicas == "1" ]; then
break
fi
n=$((n+1))
sleep 15
done
if [ $n -eq $max ]; then
echo "Current replica count is not 1"
exit 1
fi

echo "The workflow is scaled to one"

echo "SUCCESS"

0 comments on commit 3ed9b3d

Please sign in to comment.