90 lines
3.5 KiB
YAML
90 lines
3.5 KiB
YAML
name: Helm End to End Testing
|
|
|
|
on:
|
|
- pull_request
|
|
|
|
jobs:
|
|
create-cluster:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v3
|
|
|
|
- name: Set up Docker Buildx # We need this step for docker caching
|
|
uses: docker/setup-buildx-action@v2
|
|
|
|
- name: Build docker image locally # using github actions docker cache
|
|
uses: docker/build-push-action@v2
|
|
with:
|
|
context: ./engine
|
|
file: ./engine/Dockerfile
|
|
push: false
|
|
load: true
|
|
tags: oncall/engine:latest
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|
|
|
|
- name: Create k8s Kind Cluster
|
|
uses: helm/kind-action@v1.3.0
|
|
with:
|
|
config: ./helm/kind.yml
|
|
|
|
- name: Load image on the nodes of the cluster
|
|
run: kind load docker-image --name=chart-testing oncall/engine:latest
|
|
|
|
- name: Install helm chart
|
|
run: helm install test-release helm/oncall --values helm/simple.yml --values helm/values-local-image.yml
|
|
|
|
- name: Await k8s pods and other resources up
|
|
uses: jupyterhub/action-k8s-await-workloads@v1
|
|
with:
|
|
workloads: "" # all
|
|
namespace: "" # default
|
|
timeout: 300
|
|
max-restarts: 0
|
|
|
|
- name: Bootstrap organization and integration
|
|
run: |
|
|
export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=oncall,app.kubernetes.io/instance=test-release,app.kubernetes.io/component=engine" -o jsonpath="{.items[0].metadata.name}")
|
|
export ONCALL_INTEGRATION_URL=http://localhost:30001$(kubectl exec -it $POD_NAME -- bash -c "python manage.py setup_end_to_end_test --bootstrap_integration")
|
|
echo "ONCALL_INTEGRATION_URL=$ONCALL_INTEGRATION_URL" >> $GITHUB_ENV
|
|
|
|
- name: Send an alert to the integration
|
|
run: |
|
|
echo $ONCALL_INTEGRATION_URL
|
|
export TEST_ID=test-0
|
|
echo "TEST_ID=$TEST_ID" >> $GITHUB_ENV
|
|
curl -X POST "$ONCALL_INTEGRATION_URL" \
|
|
-H 'Content-Type: Application/json' \
|
|
-d '{
|
|
"alert_uid": "08d6891a-835c-e661-39fa-96b6a9e26552",
|
|
"title": "'"$TEST_ID"'",
|
|
"image_url": "https://upload.wikimedia.org/wikipedia/commons/e/ee/Grumpy_Cat_by_Gage_Skidmore.jpg",
|
|
"state": "alerting",
|
|
"link_to_upstream_details": "https://en.wikipedia.org/wiki/Downtime",
|
|
"message": "Smth happened. Oh no!"
|
|
}'
|
|
|
|
# GitHub Action reference: https://github.com/jupyterhub/action-k8s-namespace-report
|
|
- name: Kubernetes namespace report
|
|
uses: jupyterhub/action-k8s-namespace-report@v1
|
|
if: always()
|
|
|
|
- name: Await 1 alert group and 1 alert created during the test (timeout 30 seconds)
|
|
run: |
|
|
export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=oncall,app.kubernetes.io/instance=test-release,app.kubernetes.io/component=engine" -o jsonpath="{.items[0].metadata.name}")
|
|
tries=30
|
|
while [ "$tries" -gt 0 ]; do
|
|
if kubectl exec -it $POD_NAME -c oncall -- bash -c "python manage.py setup_end_to_end_test --return_results_for_test_id $TEST_ID" | grep -q '1, 1'
|
|
then
|
|
break
|
|
fi
|
|
|
|
tries=$(( tries - 1 ))
|
|
sleep 1
|
|
done
|
|
|
|
if [ "$tries" -eq 0 ]; then
|
|
echo 'Expected "1, 1" (alert groups, alerts). They were not created in 30 seconds during this integration test. Something is broken' >&2
|
|
exit 1
|
|
fi
|