feat: Continuous helm polling to update database
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Danny Bessems 2023-07-14 13:39:28 +02:00
parent dcb3decbd3
commit a5e3c79d10
3 changed files with 44 additions and 1 deletions

View File

@ -54,6 +54,43 @@ data:
<script src="script.js"></script>
</body>
</html>
update.sh: |
#!/bin/sh
while getopts u: flag
do
case "${flag}" in
u) URL=${OPTARG};;
esac
done
[ $(curl -kLs -w "%{http_code}" -o /dev/null https://$URL) != 200 ] && {
echo 'Could not connect to' $URL
exit 1
}
echo '['$(date "+%Y-%m-%d %H:%M:%S")'] Started polling helm releases with 60 second interval'
while sleep 60;
do
echo '['$(date "+%Y-%m-%d %H:%M:%S")']' $(curl -ks https://$URL/components | jq length) 'known releases in database'
echo -n $(helm list --all-namespaces --output json | jq -c '.[]') | while IFS= read -r release;
do
APP_NAME=$(echo $release | jq -r '.name')
APP_ID=$(curl -ks https://$URL/components?name=$APP_NAME | jq -r '.[0].id')
# Release is not yet in database
[ "$APP_ID" == null ] && {
curl -ks -X POST https://$URL/components -H 'Content-Type: application/json' --data "$release"
}
# Release is already in database
[ "$APP_ID" != null ] && {
curl -ks -X PATCH https://$URL/components/$APP_ID -H 'Content-Type: application/json' --data "$release"
}
done
done
db.json: |
{{ include "common.tplvalues.render" ( dict "value" .Values.jsonServer.seedData.configInline "context" $) | indent 4 }}
{{- end -}}

View File

@ -62,7 +62,12 @@ spec:
command:
- /bin/sh
- -c
- sleep infinity
- "/opt/update.sh -u {{ .Values.sidecar.targetUrl }}"
volumeMounts:
- name: {{ .Release.Name }}-configmap
mountPath: /opt/update.sh
subPath: update.sh
defaultMode: 0744
volumes:
- name: {{ .Release.Name }}-configmap
configMap:

View File

@ -13,6 +13,7 @@ jsonServer:
tag: {{ image_tag }}
sidecar:
targetUrl: metadata.example.org
image:
repository: bv11-cr01.bessems.eu/library/json-server
pullPolicy: IfNotPresent