-
Notifications
You must be signed in to change notification settings - Fork 8
161 lines (137 loc) · 6.74 KB
/
kubernetes.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
name: End to end tests
on:
push: {}
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 }}'