diff --git a/charts/json-server/templates/configmap.yaml b/charts/json-server/templates/configmap.yaml index 03c0a6b..2b7747b 100644 --- a/charts/json-server/templates/configmap.yaml +++ b/charts/json-server/templates/configmap.yaml @@ -54,6 +54,43 @@ data: + 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 -}} diff --git a/charts/json-server/templates/deployment.yaml b/charts/json-server/templates/deployment.yaml index 32a9e1e..f90e48d 100644 --- a/charts/json-server/templates/deployment.yaml +++ b/charts/json-server/templates/deployment.yaml @@ -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: diff --git a/charts/json-server/values.yaml b/charts/json-server/values.yaml index 540659c..773541e 100644 --- a/charts/json-server/values.yaml +++ b/charts/json-server/values.yaml @@ -13,6 +13,7 @@ jsonServer: tag: {{ image_tag }} sidecar: + targetUrl: metadata.example.org image: repository: bv11-cr01.bessems.eu/library/json-server pullPolicy: IfNotPresent