Skip to content

Commit a9519ae

Browse files
committed
[HELM] Add cronjob for automatically updating server list.
1 parent 8a1a112 commit a9519ae

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

helm-charts/nts-pool/templates/cron-config-updater.yaml

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
11

2+
---
3+
apiVersion: v1
4+
kind: ConfigMap
5+
metadata:
6+
name: {{ include "nts-pool.fullname" . }}-config-updater
7+
namespace: {{ default .Release.Namespace .Values.namespaceOverride }}
8+
labels:
9+
{{- include "nts-pool.labels" . | nindent 4 }}
10+
data:
11+
config-updater.sh: |
12+
#!/bin/sh
13+
curl --fail -H "Authentication: Bearer ${AUTHTOKEN}" "${CONFIGURL}" |
14+
jq '{"op": "replace", "path": "/data/servers.json", "value": "\(.)"}' |
15+
curl --fail --cacert "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt" \
16+
--binary-data @- -X PATCH -H "Content-Type: application/json-patch+json" \
17+
-H "Authentication: Bearer $(cat /var/run/secrets/kubernets.io/serviceaccount/token)" \
18+
"https://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_SERVICE_PORT_HTTPS}/api/v1/namespaces/${NAMESPACE}/configmaps/${CONFIGMAP}"
219
---
320
apiVersion: batch/v1
421
kind: CronJob
522
metadata:
6-
name: {{ include "nts-pool.fullname" . }}-ke-config-updater
23+
name: {{ include "nts-pool.fullname" . }}-ke-server-list-updater
724
namespace: {{ default .Release.Namespace .Values.namespaceOverride }}
825
labels:
926
{{- include "nts-pool.labels" . | nindent 4 }}
@@ -15,6 +32,14 @@ spec:
1532
spec:
1633
serviceAccountName: {{ include "nts-pool.fullname" . }}-ke-config-updater
1734
restartPolicy: Never
35+
volumes:
36+
- name: config-updater-script
37+
configMap:
38+
name: {{ include "nts-pool.fullname" . }}-config-updater
39+
items:
40+
- key: "config-updater.sh"
41+
path: "config-updater.sh"
42+
mode: 0755
1843
containers:
1944
- name: ke-config-updater
2045
imagePullPolicy: "{{ default .Values.image.pullPolicy .Values.ke.image.pullPolicy }}"
@@ -23,7 +48,20 @@ spec:
2348
{{- toYaml . | nindent 16 }}
2449
{{- end }}
2550
image: "{{ default .Values.image.repository .Values.ke.image.repository }}:{{ default .Values.image.tag .Values.ke.image.tag }}"
51+
volumeMounts:
52+
- name: config-updater-script
53+
mountPath: "/opt/scripts/"
54+
readonly: true
2655
command:
27-
- /bin/sh
28-
- -c
29-
- echo 'Hello from Kubernetes CronJob!'
56+
- /opt/scripts/config-updater.sh
57+
env:
58+
- name: AUTHTOKEN
59+
valueFrom:
60+
secretKeyRef:
61+
{{- toYaml .Values.management.configUpdaterSecretRef | nindent 22 }}
62+
- name: CONFIGURL
63+
value: "http://{{ include "nts-pool.fullname" . }}-management.{{ default .Release.Namespace .Values.namespaceOverride }}.svc.{{ .Values.clusterDomain }}:3000/poolke_servers"
64+
- name: NAMESPACE
65+
value: "{{ default .Release.Namespace .Values.namespaceOverride }}"
66+
- name: CONFIGMAP
67+
value: "{{ include "nts-pool.fullname" . }}-servers-config"

helm-charts/nts-pool/values.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ geolocation:
137137
maxmindDatabaseUrl: null
138138

139139
configUpdater:
140-
# When to run the config updater job
141-
schedule: "0 * * * *"
140+
# When to run the config updater jobs
141+
schedule: "* * * * *"
142142
# Override global image settings for the config updater
143143
image:
144144
pullSecrets: null

0 commit comments

Comments
 (0)