-
Notifications
You must be signed in to change notification settings - Fork 4
243 lines (207 loc) · 7.84 KB
/
buildAndTestHelm.yml
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
name: Build and Test Helm
on:
pull_request:
paths-ignore:
- docs/**
- README.md
- deploy/helm/*.md
- build/**
- src/**
branches:
- master
- release/**
jobs:
helm_verify:
name: Helm Lint and Unit tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Helm
uses: azure/setup-helm@v3
with:
version: v3.9.0
- name: Add dependency chart repos
run: |
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo add open-telemetry https://open-telemetry.github.io/opentelemetry-helm-charts
helm repo add jetstack https://charts.jetstack.io
- name: Download chart dependencies before linting
run: helm dependency build deploy/helm
- name: Lint helm
run: helm lint deploy/helm --with-subcharts
- name: Lint template
run: helm template deploy/helm --include-crds --no-hooks
- name: Install Unit test plugin
run: helm plugin install https://github.com/helm-unittest/helm-unittest.git
- name: Run unit tests
run: helm unittest deploy/helm
# Verify whether Helm chart works with image published in DockerHub
helm_e2e:
runs-on: ubuntu-latest
needs: helm_verify
name: Helm e2e tests
outputs:
image_tag: ${{ steps.generate-tag.outputs.value }}
strategy:
matrix:
# Kubernetes versions to test on
kubernetes_version:
- v1.25.16
- v1.26.15
- v1.27.16
- v1.28.13
- v1.29.8
- v1.30.4
- v1.31.0
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Deploy skaffold
uses: ./.github/actions/deploy-skaffold
- name: Create k8s Kind Cluster
uses: helm/[email protected]
with:
version: v0.24.0
kubectl_version: ${{ matrix.kubernetes_version }}
node_image: kindest/node:${{ matrix.kubernetes_version }}
cluster_name: kind
- name: Add dependency chart repos
run: |
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo add open-telemetry https://open-telemetry.github.io/opentelemetry-helm-charts
helm repo add jetstack https://charts.jetstack.io
- name: Build
run: skaffold build -p=ci-helm-e2e --file-output=/tmp/tags.json
- name: Copy image to Kind cluster
run: |
kind load docker-image $(jq -r '.builds[] | select(.imageName=="integration-test") | .tag' /tmp/tags.json)
- name: Setup kubetail
run: |
curl -Lo kubetail https://raw.githubusercontent.com/johanhaleby/kubetail/master/kubetail && sudo install kubetail /usr/local/bin/
shell: bash
- name: Deploy services using Skaffold
run: |
skaffold deploy -p=ci-helm-e2e \
--build-artifacts=/tmp/tags.json \
--kube-context kind-kind
- name: Show all resources
run: |
kubectl get all -n test-namespace
- name: Run integration tests
uses: ./.github/actions/run-integration-tests
helm_test_auto_update_against_last_published:
runs-on: ubuntu-latest
name: Helm auto update test
needs: helm_verify
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Deploy Kubernetes
uses: ./.github/actions/deploy-kubernetes
- name: Add dependency chart repos
run: |
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo add open-telemetry https://open-telemetry.github.io/opentelemetry-helm-charts
helm repo add jetstack https://charts.jetstack.io
helm repo add solarwinds https://helm.solarwinds.com
helm repo update
- name: Deploy mocks.yaml
run: kubectl apply -f tests/deploy/base/mocks.yaml
- name: Create Dockerfile with Helm repository
run: |
cat <<EOF > Dockerfile
FROM python:3.12-alpine3.19
WORKDIR /app
COPY . .
EXPOSE 5000
CMD ["python", "-m", "http.server", "5000"]
EOF
- name: Package and build Helm repository image
run: |
helm dependency build deploy/helm
helm package deploy/helm
helm repo index .
docker build -t helm-repo:latest .
- name: Deploy Helm repository in Kubernetes cluster
run: |
cat <<EOF | kubectl apply -f -
apiVersion: apps/v1
kind: Deployment
metadata:
name: helm-repo
spec:
selector:
matchLabels:
app: helm-repo
replicas: 1
template:
metadata:
labels:
app: helm-repo
spec:
containers:
- name: helm-repo
image: helm-repo:latest
imagePullPolicy: Never
ports:
- containerPort: 5000
---
apiVersion: v1
kind: Service
metadata:
name: helm-repo
spec:
selector:
app: helm-repo
ports:
- protocol: TCP
port: 5000
targetPort: 5000
type: ClusterIP
EOF
- name: Deploy swo-k8s-collector Helm chart
run: |
helm install swo-k8s-collector solarwinds/swo-k8s-collector \
--create-namespace \
--namespace swo-k8s-collector \
--set cluster.name=test-cluster \
--set otel.endpoint=timeseries-mock-service:9082 \
--set otel.api_token=not_set \
--set autoupdate.enabled=true \
--set autoupdate.devel=true \
--set otel.metrics.swi_endpoint_check=false \
--set otel.metrics.prometheus_check=false \
--set otel.metrics.resources.requests.memory=100Mi \
--set otel.events.resources.requests.memory=100Mi \
--set otel.logs.resources.requests.memory=100Mi \
--atomic
- name: Update AutoUpdate ConfigMap to use local Helm repository
run: |
kubectl get configmap swo-k8s-collector-autoupdate-script -n swo-k8s-collector -o yaml > autoupdate-script.yaml
sed -i 's|https://helm.solarwinds.com|http://helm-repo.default.svc.cluster.local:5000|' autoupdate-script.yaml
kubectl apply -f autoupdate-script.yaml
cat autoupdate-script.yaml
- name: Trigger helm-autoupdate CronJob and verify
run: |
# Trigger the CronJob
kubectl create job --from=cronjob/helm-autoupdate helm-autoupdate-manual-trigger -n swo-k8s-collector
# Wait for the job to complete
kubectl wait --for=condition=complete --timeout=300s job/helm-autoupdate-manual-trigger -n swo-k8s-collector
# Get the job's success and failure status
JOB_SUCCEEDED=$(kubectl get job helm-autoupdate-manual-trigger -n swo-k8s-collector -o=jsonpath='{.status.succeeded}')
JOB_FAILED=$(kubectl get job helm-autoupdate-manual-trigger -n swo-k8s-collector -o=jsonpath='{.status.failed}')
# Check if the job succeeded or failed
if [ "$JOB_SUCCEEDED" == "1" ]; then
echo "Job completed successfully."
elif [ "$JOB_FAILED" != "" ]; then
echo "Job failed."
exit 1
else
echo "Job did not complete successfully. Status is ambiguous."
exit 1
fi
- name: Trigger helm-autoupdate CronJob logs
if: ${{ always() }}
run: |
kubectl logs jobs/helm-autoupdate-manual-trigger -n swo-k8s-collector --all-containers=true