Skip to content

Allow annotations to control naming behavior #195

Allow annotations to control naming behavior

Allow annotations to control naming behavior #195

Workflow file for this run

name: End to end tests
on:
push:
pull_request:
jobs:
integration-tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
test_configuration:
- default
- single_namespace_rbac
kind_image:
- kindest/node:v1.25.3@sha256:f52781bc0d7a19fb6c405c2af83abfeb311f130707a0e219175677e366cc45d1
- kindest/node:v1.24.7@sha256:577c630ce8e509131eab1aea12c022190978dd2f745aac5eb1fe65c0807eb315
- kindest/node:v1.23.13@sha256:ef453bb7c79f0e3caba88d2067d4196f427794086a7d0df8df4f019d5e336b61
- kindest/node:v1.22.15@sha256:7d9708c4b0873f0fe2e171e2b1b7f45ae89482617778c1c875f1053d4cef2e41
- kindest/node:v1.21.14@sha256:9d9eb5fb26b4fbc0c6d95fa8c790414f9750dd583f5d7cee45d92e8c26670aa1
- kindest/node:v1.20.15@sha256:a32bf55309294120616886b5338f95dd98a2f7231519c7dedcec32ba29699394
- kindest/node:v1.19.16@sha256:476cb3269232888437b61deca013832fee41f9f074f9bed79f57e4280f7c48b7
# Kind v0.17.0 no longer building images for Kubernetes below 1.19
# - kindest/node:v1.18.20@sha256:e3dca5e16116d11363e31639640042a9b1bd2c90f85717a7fc66be34089a8169
# - kindest/node:v1.17.17@sha256:66f1d0d91a88b8a001811e2f1054af60eef3b669a9a74f9b6db871f2f1eeed00
# - kindest/node:v1.16.15@sha256:83067ed51bf2a3395b24687094e283a7c7c865ccc12a8b1d7aa673ba0c5e8861
# - kindest/node:v1.15.12@sha256:b920920e1eda689d9936dfcf7332701e80be12566999152626b2c9d730397a95
steps:
- name: Generate unique random tag for run
id: generate_random_id
run: echo "::set-output name=random_id::run-$(date +%s)-$RANDOM"
- uses: actions/[email protected]
- name: Set up Helm
uses: azure/setup-helm@v1
with:
version: v3.7.2
# Needed because default version is too old
- uses: azure/setup-kubectl@v3
- uses: actions/setup-python@v2
with:
python-version: 3.9
cache: 'pip'
# See: https://github.com/helm/chart-testing-action
# - name: Set up chart-testing
# uses: helm/[email protected]
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Create Kind cluster
uses: helm/[email protected]
with:
node_image: ${{ matrix.kind_image }}
version: v0.17.0
# We need to have the names in Cronitor be separate, so if we use separate namespaces,
# we can kind of "cheat" a bit and get unique monitor names
# This is _not_ needed for separation, since every Github Actions job in the matrix will
# run in its own separate environment and Kind cluster.
- name: Create namespace
run: |
kubectl create ns "${{ steps.generate_random_id.outputs.random_id }}"
kubectl create ns "extra-namespace-${{ steps.generate_random_id.outputs.random_id }}"
kubectl config set-context --current --namespace="${{ steps.generate_random_id.outputs.random_id }}"
- name: Add API key
run: >
kubectl create secret generic cronitor-secret --from-literal=CRONITOR_API_KEY=${{ secrets.CRONITOR_API_KEY }}
# Since k8s versions 1.25+ don't support the batch/v1beta1 apiVersion anymore,
# we need to special case the resources for older versions of k8s using kustomize until they
# are all deprecated.
- name: Apply test YAML
env:
EXTRA_NAMESPACE: "extra-namespace-${{ steps.generate_random_id.outputs.random_id }}"
RANDOM_ID: "${{ steps.generate_random_id.outputs.random_id }}"
run: |
envsubst < e2e-test/kustomize/base/kustomization-sub.yaml > e2e-test/kustomize/base/kustomization.yaml
cd e2e-test/
if echo "${{ matrix.kind_image }}" | grep -q -e v1.15 -e v1.16 -e v1.17 -e v1.18 -e v1.19 -e v1.20 -e v1.21 -e v1.22 -e v1.23 ; then
kubectl apply -k kustomize/pre-batchv1/
else
kubectl apply -k kustomize/current/
fi
- name: Build docker container
uses: docker/build-push-action@v2
with:
context: .
push: false
tags: "local-docker-build:${{ steps.generate_random_id.outputs.random_id }}"
load: true
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Load docker image to Kind
run: |
kind load docker-image "local-docker-build:${{ steps.generate_random_id.outputs.random_id }}" --name chart-testing
# We've already used a lot of time building the docker container
# and loading the image to kind
- name: Sleep for 1 minute to let events populate
run: sleep $((60 * 1))
shell: bash
- name: Install Cronitor Kubernetes agent
run: |
helm upgrade --install cronitor-kubernetes ./charts/cronitor-kubernetes/ \
--namespace "${{ steps.generate_random_id.outputs.random_id }}" \
--set credentials.secretName=cronitor-secret \
--set credentials.secretKey=CRONITOR_API_KEY \
--set config.defaultEnvironment=CI \
--set config.tags='ci:${{ steps.generate_random_id.outputs.random_id }}' \
-f ./e2e-test/values/${{ matrix.test_configuration }}.yaml \
--set image="local-docker-build:${{ steps.generate_random_id.outputs.random_id }}" \
--set imagePullPolicy=Never \
--wait
- name: Sleep for 3 more minutes to let the agent run
run: sleep $((60 * 3))
shell: bash
- name: Print logs always
if: always()
run: |
echo "::group::Kubernetes agent logs"
kubectl logs $(kubectl get po -l app.kubernetes.io/name=cronitor-kubernetes -o name)
echo "::endgroup::"
- run: pip install -r requirements.txt
if: always()
working-directory: ./e2e-test/api/
# TODO: Ensure agent is actually running / hasn't crashed
- name: Run tests
working-directory: ./e2e-test/api/
env:
CRONITOR_API_KEY: ${{ secrets.CRONITOR_API_KEY }}
CI_TAG: "ci:${{ steps.generate_random_id.outputs.random_id }}"
KUBERNETES_NAMESPACE: "${{ steps.generate_random_id.outputs.random_id }}"
KUBERNETES_EXTRA_NAMESPACE: "extra-namespace-${{ steps.generate_random_id.outputs.random_id }}"
TEST_CONFIGURATION: ${{ matrix.test_configuration }}
RANDOM_ID: "${{ steps.generate_random_id.outputs.random_id }}"
run: pytest
- name: Delete created monitors
# Always need to clean up the leftover monitors, even with test failures
if: always()
working-directory: ./e2e-test/api/
env:
CRONITOR_API_KEY: ${{ secrets.CRONITOR_API_KEY }}
run: |
python main.py --ci-tag 'ci:${{ steps.generate_random_id.outputs.random_id }}'