Skip to content

Commit 553f85d

Browse files
committed
Allow external redis and and mysql
1 parent 9ae7b43 commit 553f85d

File tree

8 files changed

+128
-16
lines changed

8 files changed

+128
-16
lines changed

charts/librenms/templates/_helpers.tpl

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,70 @@ Create the name of the secret to use
7474
{{- else -}}
7575
{{- .Release.Name -}}
7676
{{- end -}}
77-
{{- end -}}
77+
{{- end -}}
78+
79+
{{/*
80+
Get the MySQL host
81+
*/}}
82+
{{- define "librenms.mysqlHost" -}}
83+
{{- if .Values.mysql.enabled -}}
84+
{{ .Release.Name }}-mysql
85+
{{- else -}}
86+
{{ .Values.mysql.external.host }}
87+
{{- end -}}
88+
{{- end -}}
89+
90+
{{/*
91+
Get the MySQL secret
92+
*/}}
93+
{{- define "librenms.mysqlSecret" -}}
94+
{{- if .Values.mysql.enabled -}}
95+
{{ .Release.Name }}-mysql
96+
{{- else -}}
97+
{{ .Values.mysql.external.existingSecret }}
98+
{{- end -}}
99+
{{- end -}}
100+
101+
{{/*
102+
Get the MySQL secret key
103+
*/}}
104+
{{- define "librenms.mysqlSecretKey" -}}
105+
{{- if .Values.mysql.enabled -}}
106+
mysql-password
107+
{{- else -}}
108+
{{ .Values.mysql.external.existingSecretKey }}
109+
{{- end -}}
110+
{{- end -}}
111+
112+
{{/*
113+
Get the MySQL port
114+
*/}}
115+
{{- define "librenms.mysqlPort" -}}
116+
{{- if .Values.mysql.enabled -}}
117+
3306
118+
{{- else -}}
119+
{{ .Values.mysql.external.port }}
120+
{{- end -}}
121+
{{- end -}}
122+
123+
{{/*
124+
Get the Redis host
125+
*/}}
126+
{{- define "librenms.redisHost" -}}
127+
{{- if .Values.redis.enabled -}}
128+
{{ .Release.Name }}-redis-master
129+
{{- else -}}
130+
{{ .Values.redis.external.host }}
131+
{{- end -}}
132+
{{- end -}}
133+
134+
{{/*
135+
Get the Redis port
136+
*/}}
137+
{{- define "librenms.redisPort" -}}
138+
{{- if .Values.redis.enabled -}}
139+
6379
140+
{{- else -}}
141+
{{ .Values.redis.external.port }}
142+
{{- end -}}
143+
{{- end -}}

charts/librenms/templates/librenms-configmap.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ metadata:
66
data:
77
TZ: {{ .Values.librenms.timezone}}
88
DB_TIMEOUT: "60"
9-
REDIS_HOST: {{ .Release.Name }}-redis-master
10-
REDIS_PORT: "6379"
9+
REDIS_HOST: "{{ include "librenms.redisHost" . }}"
10+
REDIS_PORT: "{{ include "librenms.redisPort" . }}"
1111
REDIS_DB: "0"
1212
RRDCACHED_SERVER: "{{ .Release.Name }}-rrdcached:42217"
1313
CACHE_DRIVER: redis
1414
SESSION_DRIVER: redis
15-
DB_HOST: {{ .Release.Name }}-mysql
15+
DB_HOST: "{{ include "librenms.mysqlHost" . }}"
16+
DB_PORT: "{{ include "librenms.mysqlPort" . }}"
1617
DB_USERNAME: {{.Values.mysql.auth.username}}
1718
DB_DATABASE: {{.Values.mysql.auth.database}}
1819
---
@@ -24,4 +25,4 @@ data:
2425
custom.php: |-
2526
{{ tpl (.Files.Get "files/custom.php") . | indent 4 }}
2627
init.sh: |-
27-
{{ .Files.Get "files/init.sh" | indent 4 }}
28+
{{ .Files.Get "files/init.sh" | indent 4 }}

charts/librenms/templates/librenms-cron.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ spec:
2727
- name: DB_PASSWORD
2828
valueFrom:
2929
secretKeyRef:
30-
name: {{ .Release.Name }}-mysql
31-
key: mysql-password
30+
name: {{ include "librenms.mysqlSecret" . }}
31+
key: {{ include "librenms.mysqlSecretKey" . }}
3232
{{- with .Values.librenms.extraEnvs }}
3333
{{- toYaml . | nindent 8 }}
3434
{{- end }}
@@ -48,4 +48,4 @@ spec:
4848
{{- toYaml . | nindent 8 }}
4949
{{- end }}
5050
restartPolicy: OnFailure
51-
{{ end }}
51+
{{ end }}

charts/librenms/templates/librenms-deployment.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ spec:
3232
name: {{ .Release.Name }}-files
3333
- name: mysql
3434
secret:
35-
secretName: {{ .Release.Name }}-mysql
35+
secretName: {{ include "librenms.mysqlSecret" . }}
3636
optional: false
3737
initContainers:
3838
- name: init
@@ -60,8 +60,15 @@ spec:
6060
- name: DB_PASSWORD
6161
valueFrom:
6262
secretKeyRef:
63-
name: {{ .Release.Name }}-mysql
64-
key: mysql-password
63+
name: {{ include "librenms.mysqlSecret" . }}
64+
key: {{ include "librenms.mysqlSecretKey" . }}
65+
{{ if not .Values.redis.enabled }}
66+
- name: REDIS_PASSWORD
67+
valueFrom:
68+
secretKeyRef:
69+
name: {{ .Values.redis.external.existingSecret }}
70+
key: {{ .Values.redis.external.existingSecretKey }}
71+
{{- end }}
6572
{{- with .Values.librenms.extraEnvs }}
6673
{{- toYaml . | nindent 8 }}
6774
{{- end }}

charts/librenms/templates/librenms-poller-ss.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ spec:
3333
name: {{ .Release.Name }}-files
3434
- name: mysql
3535
secret:
36-
secretName: {{ .Release.Name }}-mysql
36+
secretName: {{ include "librenms.mysqlSecret" . }}
3737
initContainers:
3838
- name: init
3939
image: busybox:1.28
@@ -59,8 +59,15 @@ spec:
5959
- name: DB_PASSWORD
6060
valueFrom:
6161
secretKeyRef:
62-
name: {{ .Release.Name }}-mysql
63-
key: mysql-password
62+
name: {{ include "librenms.mysqlSecret" . }}
63+
key: {{ include "librenms.mysqlSecretKey" . }}
64+
{{ if not .Values.redis.enabled }}
65+
- name: REDIS_PASSWORD
66+
valueFrom:
67+
secretKeyRef:
68+
name: {{ .Values.redis.external.existingSecret }}
69+
key: {{ .Values.redis.external.existingSecretKey }}
70+
{{- end }}
6471
{{- with .Values.librenms.poller.extraEnvs }}
6572
{{- toYaml . | nindent 8 }}
6673
{{- end }}
@@ -83,7 +90,7 @@ spec:
8390
{{- end }}
8491
readinessProbe:
8592
exec:
86-
command: ["nc", "-z", "-v", "-w1", "{{ .Release.Name }}-mysql", "3306"]
93+
command: ["nc", "-z", "-v", "-w1", "{{ include "librenms.mysqlHost" . }}", "3306"]
8794
initialDelaySeconds: 0
8895
periodSeconds: 1
8996
failureThreshold: 3

charts/librenms/templates/librenms-secret.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ metadata:
77
type: Opaque
88
data:
99
appkey: {{ .Values.librenms.appkey | b64enc | quote }}
10-
{{- end }}
10+
{{- end }}

charts/librenms/templates/rrdcached-deployment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,4 @@ spec:
5656
{{- if .Values.librenms.rrdcached.resources }}
5757
resources: {{ toYaml .Values.librenms.rrdcached.resources | nindent 10 }}
5858
{{- end }}
59+

charts/librenms/values.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,23 @@ mysql:
168168
username: librenms
169169
database: librenms
170170

171+
# -- External MySQL configuration
172+
# -- Only used when mysql.enabled is set to false
173+
# -- Configure these settings to connect to an existing MySQL instance
174+
external:
175+
# -- External MySQL host address
176+
host: your-mysql-host
177+
# -- External MySQL port
178+
port: 3306
179+
# -- External MySQL username for LibreNMS
180+
username: librenms
181+
# -- External MySQL database name
182+
database: librenms
183+
# -- Name of existing Kubernetes secret containing the MySQL password
184+
existingSecret: mysql-credentials-secret
185+
# -- Key in the existing secret that contains the MySQL password
186+
existingSecretKey: mysql-password
187+
171188
# -- Configuration for redis dependency chart by Bitnami. See their chart for
172189
# more information: https://github.com/bitnami/charts/tree/master/bitnami/redis
173190
redis:
@@ -183,3 +200,16 @@ redis:
183200
disableCommands: []
184201

185202
architecture: standalone
203+
204+
# -- External Redis configuration
205+
# -- Only used when redis.enabled is set to false
206+
# -- Configure these settings to connect to an existing Redis instance
207+
external:
208+
# -- External Redis host address
209+
host: your-redis-host
210+
# -- External Redis port
211+
port: 6379
212+
# -- Name of existing Kubernetes secret containing the Redis password
213+
existingSecret: redis-credentials-secret
214+
# -- Key in the existing secret that contains the Redis password
215+
existingSecretKey: REDIS_PASSWORD

0 commit comments

Comments
 (0)