Skip to content

Commit 3c0aecc

Browse files
committed
[HELM] implemented basic geolocation downloading.
1 parent 40e341a commit 3c0aecc

File tree

4 files changed

+86
-8
lines changed

4 files changed

+86
-8
lines changed

Dockerfile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ FROM debian:bookworm-slim AS runner
3434
# Install CA certificates for the runner
3535
RUN apt update \
3636
&& apt install -y --no-install-recommends \
37-
ca-certificates \
37+
ca-certificates curl \
3838
&& rm -rf /var/lib/apt/lists/* /tmp/*
3939

4040
# Copy compiled binaries from the builder stage
@@ -43,9 +43,6 @@ COPY --from=builder /build/artifacts/nts-pool-management /usr/local/bin/nts-pool
4343
COPY --from=builder /build/artifacts/nts-pool-monitor /usr/local/bin/nts-pool-monitor
4444
COPY --from=builder /build/nts-pool-management/assets /opt/nts-pool-management/assets
4545

46-
# Temporarily copy test geodb, until we actually implement proper loading of the geolocation database.
47-
COPY --from=builder /build/nts-pool-ke/testdata/GeoLite2-Country-Test.mmdb /opt/nts-pool-management/GeoLite2-Country-Test.mmdb
48-
4946
# Set a default assets directory
5047
ENV NTSPOOL_ASSETS_DIR=/opt/nts-pool-management/assets
5148

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
apiVersion: v1
3+
kind: ConfigMap
4+
metadata:
5+
name: {{ include "nts-pool.fullname" . }}-geolocation-loader
6+
namespace: {{ default .Release.Namespace .Values.namespaceOverride }}
7+
labels:
8+
{{- include "nts-pool.labels" . | nindent 4 }}
9+
data:
10+
geolocation-loader.sh: |
11+
#!/bin/sh
12+
while true; do
13+
curl --fail -o geolite2.tar.gz -z "${TARGET}" -u "${USERID}:${LICENSE_KEY}" -L "${URL}"
14+
if [ $? -eq 0 ] && [ -f geolite2.tar.gz ]; then
15+
tar -xf geolite2.tar.gz --wildcards --strip-components 1 \*/GeoLite2-Country.mmdb
16+
mv GeoLite2-Country.mmdb "${TARGET}"
17+
touch "${TARGET}"
18+
fi
19+
rm -f geolite2.tar.gz
20+
sleep "$PERIOD"
21+
done

helm-charts/nts-pool/templates/management.yaml

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,59 @@ spec:
3131
app.kubernetes.io/component: management
3232
{{- include "nts-pool.selectorLabels" . | nindent 8 }}
3333
spec:
34-
{{- if .Values.management.databaseCertificate.cert }}
3534
volumes:
35+
- name: geolocation-script
36+
configMap:
37+
name: {{ include "nts-pool.fullname" . }}-geolocation-loader
38+
items:
39+
- key: "geolocation-loader.sh"
40+
path: "geolocation-loader.sh"
41+
mode: 0755
42+
- name: geolocation
43+
emptyDir: {}
44+
{{- if .Values.management.databaseCertificate.cert }}
3645
- name: db-cert-volume
3746
configMap:
3847
name: {{ include "nts-pool.fullname" . }}-management-db-cert
39-
{{- end }}
48+
{{- end }}
49+
initContainers:
50+
- name: geolocation
51+
imagePullPolicy: "{{ default .Values.image.pullPolicy .Values.management.image.pullPolicy }}"
52+
{{- with default .Values.image.pullSecrets .Values.management.image.pullSecrets }}
53+
imagePullSecrets:
54+
{{- toYaml . | nindent 10 }}
55+
{{- end }}
56+
image: "{{ default .Values.image.repository .Values.management.image.repository }}:{{ default .Values.image.tag .Values.management.image.tag }}"
57+
command: ["/opt/geodb/geolocation-loader.sh"]
58+
workingDir: "/opt/geodb/"
59+
volumeMounts:
60+
- name: geolocation
61+
mountPath: "/opt/geodb"
62+
- name: geolocation-script
63+
mountPath: "/opt/geodb/scripts/"
64+
readonly: true
65+
restartPolicy: always
66+
startupProbe:
67+
exec:
68+
command:
69+
- sh
70+
- -c
71+
- test -e /opt/geodb/geodb.mmdb
72+
env:
73+
- name: USERID
74+
valueFrom:
75+
secretKeyRef:
76+
{{- toYaml .Values.geolocation.maxmindUserIdSecretRef | nindent 16 }}
77+
- name: LICENSE_KEY
78+
valueFrom:
79+
secretKeyRef:
80+
{{- toYaml .Values.geolocation.maxmindLicenseKeySecretRef | nindent 16 }}
81+
- name: URL
82+
value: {{ .Values.geolocation.maxmindDatabaseUrl }}
83+
- name: TARGET
84+
value: "/opt/geodb/geodb.mmdb"
85+
- name: PERIOD
86+
value: "24h"
4087
containers:
4188
- name: management
4289
imagePullPolicy: "{{ default .Values.image.pullPolicy .Values.management.image.pullPolicy }}"
@@ -47,8 +94,10 @@ spec:
4794
image: "{{ default .Values.image.repository .Values.management.image.repository }}:{{ default .Values.image.tag .Values.management.image.tag }}"
4895
command: ["/usr/local/bin/nts-pool-management"]
4996
workingDir: "/opt/nts-pool-management"
50-
{{- if .Values.management.databaseCertificate.cert }}
5197
volumeMounts:
98+
- name: geolocation
99+
mountPath: "/opt/geodb"
100+
{{- if .Values.management.databaseCertificate.cert }}
52101
- name: db-cert-volume
53102
mountPath: {{ .Values.management.databaseCertificate.mountPath }}
54103
subPath: db.pem
@@ -102,4 +151,4 @@ spec:
102151
- name: RESTART_BUMP
103152
value: "{{ default 1 .Values.management.restartBump}}"
104153
- name: NTSPOOL_GEOLOCATION_DB
105-
value: "/opt/nts-pool-management/GeoLite2-Country-Test.mmdb" # Temporary, until proper loading of geolocation database is implemented
154+
value: "/opt/geodb/geodb.mmdb"

helm-charts/nts-pool/values.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,17 @@ monitor:
115115
# Timeout for ntp exchanges with timesources.
116116
ntpTimeout: 1000
117117

118+
# Configuration for geolocation data loading. The software is designed to use the MaxMind GeoLite2 Country database
119+
# NOTE: These values MUST be provided
120+
geolocation:
121+
maxmindUserIdSecretRef:
122+
name: nts-pool-maxmind
123+
key: user-id
124+
maxmindLicenseKeySecretRef:
125+
name: nts-pool-maxmind
126+
key: license-key
127+
maxmindDatabaseUrl: null
128+
118129
configUpdater:
119130
# When to run the config updater job
120131
schedule: "0 * * * *"

0 commit comments

Comments
 (0)