Skip to content

Commit 8c7fda0

Browse files
fix: add HA redis templates (#1284)
* fix: add HA templates and modify the code * fix: namespace problems in UI * doc: update documentation with storage considerations * test: adjust free disk space on ui tests * fix: run make render * fix: liveness probe, blank lines in templates * fix: run make render * fix: add redis env variables to redis * fix: set default resources to {} and add documentation * fix: check both databases on redis ha * fix: docs
1 parent f67038e commit 8c7fda0

File tree

143 files changed

+4498
-499
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+4498
-499
lines changed

.github/workflows/ci-ui-tests.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ jobs:
4848

4949

5050
steps:
51+
- name: Free Disk Space
52+
uses: jlumbroso/free-disk-space@main
53+
with:
54+
android: true
55+
dotnet: true
56+
haskell: true
57+
large-packages: false
58+
docker-images: false
59+
swap-storage: false
60+
5161
- name: Checkout Project
5262
uses: actions/checkout@v4
5363

Dockerfile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ FROM base AS final
2424

2525
RUN mkdir /.pysnmp && chown 10001:10001 /.pysnmp
2626
RUN chown 10001:10001 /tmp
27-
USER 10001:10001
2827
COPY --from=builder /app/.venv /app/.venv
29-
COPY entrypoint.sh ./
30-
ENTRYPOINT ["./entrypoint.sh"]
28+
COPY entrypoint.sh /app/entrypoint.sh
29+
COPY construct-redis-url.sh /app/construct-redis-url.sh
30+
RUN chmod +x /app/construct-redis-url.sh /app/entrypoint.sh
31+
USER 10001:10001
32+
ENTRYPOINT ["/app/entrypoint.sh"]

charts/splunk-connect-for-snmp/templates/_helpers.tpl

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,63 @@ Whether enable polling
9494
{{- else }}
9595
{{- printf "false" }}
9696
{{- end -}}
97-
{{- end }}
97+
{{- end }}
98+
99+
{{- /*
100+
Generate Redis environment variables for application pods
101+
*/ -}}
102+
{{- define "splunk-connect-for-snmp.redis-env" -}}
103+
{{- if eq .Values.redis.architecture "replication" -}}
104+
- name: REDIS_MODE
105+
value: "replication"
106+
- name: REDIS_SENTINEL_SERVICE
107+
value: {{ .Release.Name }}-redis-sentinel
108+
- name: REDIS_HEADLESS_SERVICE
109+
value: {{ .Release.Name }}-redis-headless
110+
- name: NAMESPACE
111+
value: {{ .Release.Namespace }}
112+
- name: REDIS_SENTINEL_REPLICAS
113+
value: {{ .Values.redis.sentinel.replicas | quote }}
114+
- name: REDIS_SENTINEL_PORT
115+
value: "26379"
116+
- name: REDIS_MASTER_NAME
117+
value: mymaster
118+
{{- else -}}
119+
- name: REDIS_MODE
120+
value: "standalone"
121+
- name: REDIS_HOST
122+
value: {{ .Release.Name }}-redis
123+
- name: REDIS_PORT
124+
value: "6379"
125+
{{- end }}
126+
- name: REDIS_DB
127+
value: "1"
128+
- name: CELERY_DB
129+
value: "0"
130+
{{- if .Values.redis.auth.enabled }}
131+
- name: REDIS_PASSWORD
132+
valueFrom:
133+
secretKeyRef:
134+
{{- if .Values.redis.auth.existingSecret }}
135+
name: {{ .Values.redis.auth.existingSecret }}
136+
key: {{ .Values.redis.auth.existingSecretPasswordKey | default "password" }}
137+
{{- else }}
138+
name: {{ .Release.Name }}-redis-secret
139+
key: password
140+
{{- end }}
141+
{{- end -}}
142+
{{- end -}}
143+
144+
{{- /*
145+
Generate Redis environment variables for application pods
146+
*/ -}}
147+
{{- define "splunk-connect-for-snmp.redis-annotations" -}}
148+
{{- if eq .Values.redis.architecture "replication" -}}
149+
checksum/redis-config: {{ include (print $.Template.BasePath "/redis/redis-ha-config.yaml") . | sha256sum }}
150+
{{- else -}}
151+
checksum/redis-config: {{ include (print $.Template.BasePath "/redis/redis-config.yaml") . | sha256sum }}
152+
{{- end -}}
153+
{{- if .Values.redis.auth.enabled }}
154+
checksum/redis-secret: {{ include (print $.Template.BasePath "/redis/redis-secret.yaml") . | sha256sum }}
155+
{{- end -}}
156+
{{- end -}}

charts/splunk-connect-for-snmp/templates/inventory/job.yaml

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ spec:
99
ttlSecondsAfterFinished: 300
1010
template:
1111
metadata:
12-
{{- with .Values.inventory.podAnnotations }}
13-
annotations:
14-
{{- toYaml . | nindent 8 }}
15-
{{- end }}
16-
12+
annotations:
13+
{{- include "splunk-connect-for-snmp.redis-annotations" . | nindent 8 }}
14+
{{- with .Values.inventory.podAnnotations }}
15+
{{- toYaml . | nindent 8 }}
16+
{{- end }}
1717
labels:
1818
{{- include "splunk-connect-for-snmp.inventory.selectorLabels" . | nindent 8 }}
1919
spec:
@@ -30,26 +30,7 @@ spec:
3030
env:
3131
- name: CONFIG_PATH
3232
value: /app/config/config.yaml
33-
{{- if .Values.redis.auth.enabled }}
34-
- name: REDIS_PASSWORD
35-
valueFrom:
36-
secretKeyRef:
37-
{{- if .Values.redis.auth.existingSecret }}
38-
name: {{ .Values.redis.auth.existingSecret }}
39-
key: {{ .Values.redis.auth.existingSecretPasswordKey | default "password" }}
40-
{{- else }}
41-
name: {{ .Release.Name }}-redis-secret
42-
key: password
43-
{{- end }}
44-
{{- end }}
45-
- name: REDIS_HOST
46-
value: {{ .Release.Name }}-redis
47-
- name: REDIS_PORT
48-
value: "6379"
49-
- name: REDIS_DB
50-
value: "1"
51-
- name: CELERY_DB
52-
value: "0"
33+
{{- include "splunk-connect-for-snmp.redis-env" . | nindent 10 }}
5334
- name: INVENTORY_PATH
5435
value: /app/inventory/inventory.csv
5536
- name: MONGO_URI
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{{- if eq .Values.redis.architecture "replication" }}
2+
apiVersion: v1
3+
kind: ConfigMap
4+
metadata:
5+
name: {{ .Release.Name }}-redis-config
6+
namespace: {{ .Release.Namespace }}
7+
labels:
8+
app: {{ .Release.Name }}-redis
9+
data:
10+
redis.conf: |
11+
dir /data
12+
13+
# Persistence
14+
save 900 1
15+
save 300 10
16+
save 60 10000
17+
18+
{{- if .Values.redis.persistence.aof.enabled }}
19+
appendonly yes
20+
appendfsync {{ .Values.redis.persistence.aof.fsync | default "everysec" }}
21+
{{- end }}
22+
23+
# Replication
24+
min-replicas-to-write 1
25+
min-replicas-max-lag 10
26+
27+
loglevel notice
28+
maxmemory-policy noeviction
29+
bind 0.0.0.0
30+
protected-mode no
31+
port 6379
32+
{{- end }}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{{- if eq .Values.redis.architecture "replication" }}
2+
apiVersion: v1
3+
kind: Service
4+
metadata:
5+
name: {{ .Release.Name }}-redis
6+
namespace: {{ .Release.Namespace }}
7+
labels:
8+
app: {{ .Release.Name }}-redis
9+
spec:
10+
type: ClusterIP
11+
ports:
12+
- port: 6379
13+
targetPort: 6379
14+
name: redis
15+
selector:
16+
app: {{ .Release.Name }}-redis
17+
---
18+
apiVersion: v1
19+
kind: Service
20+
metadata:
21+
name: {{ .Release.Name }}-redis-headless
22+
namespace: {{ .Release.Namespace }}
23+
labels:
24+
app: {{ .Release.Name }}-redis
25+
spec:
26+
clusterIP: None
27+
ports:
28+
- port: 6379
29+
name: redis
30+
selector:
31+
app: {{ .Release.Name }}-redis
32+
{{- end }}
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
{{- if eq .Values.redis.architecture "replication" }}
2+
apiVersion: apps/v1
3+
kind: StatefulSet
4+
metadata:
5+
name: {{ .Release.Name }}-redis-ha
6+
namespace: {{ .Release.Namespace }}
7+
labels:
8+
app: {{ .Release.Name }}-redis
9+
app.kubernetes.io/name: redis
10+
app.kubernetes.io/instance: {{ .Release.Name }}
11+
app.kubernetes.io/component: database
12+
spec:
13+
serviceName: {{ .Release.Name }}-redis-headless
14+
replicas: {{ .Values.redis.replicas | default 3 }}
15+
podManagementPolicy: Parallel
16+
selector:
17+
matchLabels:
18+
app: {{ .Release.Name }}-redis
19+
template:
20+
metadata:
21+
labels:
22+
app: {{ .Release.Name }}-redis
23+
annotations:
24+
{{- include "splunk-connect-for-snmp.redis-annotations" . | nindent 8 }}
25+
spec:
26+
{{- with .Values.redis.podSecurityContext }}
27+
securityContext:
28+
runAsUser: {{ .runAsUser }}
29+
fsGroup: {{ .fsGroup }}
30+
{{- end }}
31+
{{- if .Values.redis.storage.enabled }}
32+
initContainers:
33+
- name: fix-permissions
34+
image: {{ .Values.redis.image.repository }}:{{ .Values.redis.image.tag }}
35+
imagePullPolicy: {{ .Values.redis.image.pullPolicy }}
36+
command:
37+
- sh
38+
- -c
39+
- |
40+
echo "Fixing permissions on /data..."
41+
chown -R {{ .Values.redis.podSecurityContext.runAsUser }}:{{ .Values.redis.podSecurityContext.fsGroup }} /data
42+
chmod -R 755 /data
43+
ls -ln /data
44+
volumeMounts:
45+
- name: redis-data
46+
mountPath: /data
47+
securityContext:
48+
runAsUser: 0
49+
{{- end }}
50+
containers:
51+
- name: redis
52+
image: {{ .Values.redis.image.repository }}:{{ .Values.redis.image.tag }}
53+
imagePullPolicy: {{ .Values.redis.image.pullPolicy }}
54+
ports:
55+
- containerPort: 6379
56+
name: redis
57+
env:
58+
- name: POD_IP
59+
valueFrom:
60+
fieldRef:
61+
fieldPath: status.podIP
62+
{{- if .Values.redis.auth.enabled }}
63+
- name: REDIS_PASSWORD
64+
valueFrom:
65+
secretKeyRef:
66+
{{- if .Values.redis.auth.existingSecret }}
67+
name: {{ .Values.redis.auth.existingSecret }}
68+
key: {{ .Values.redis.auth.existingSecretPasswordKey | default "password" }}
69+
{{- else }}
70+
name: {{ .Release.Name }}-redis-secret
71+
key: password
72+
{{- end }}
73+
{{- end }}
74+
command:
75+
- sh
76+
- -c
77+
args:
78+
- |
79+
cp /etc/redis/redis.conf /tmp/redis.conf
80+
81+
{{- if .Values.redis.auth.enabled }}
82+
echo "requirepass $REDIS_PASSWORD" >> /tmp/redis.conf
83+
echo "masterauth $REDIS_PASSWORD" >> /tmp/redis.conf
84+
{{- end }}
85+
86+
# Announce pod IP for Sentinel
87+
echo "replica-announce-ip $POD_IP" >> /tmp/redis.conf
88+
echo "replica-announce-port 6379" >> /tmp/redis.conf
89+
90+
# Start Redis
91+
# Sentinel will handle promotion - all start as replicas initially
92+
HOSTNAME=$(hostname)
93+
MASTER_NAME="{{ .Release.Name }}-redis-ha-0"
94+
MASTER_HOST="$MASTER_NAME.{{ .Release.Name }}-redis-headless"
95+
96+
if [ "$HOSTNAME" = "$MASTER_NAME" ]; then
97+
echo "Starting as master"
98+
else
99+
echo "replicaof $MASTER_HOST 6379" >> /tmp/redis.conf
100+
echo "Starting as replica of $MASTER_HOST"
101+
fi
102+
103+
exec redis-server /tmp/redis.conf
104+
volumeMounts:
105+
{{- if .Values.redis.storage.enabled }}
106+
- name: redis-data
107+
mountPath: /data
108+
{{- end }}
109+
- name: redis-config
110+
mountPath: /etc/redis
111+
resources:
112+
{{- toYaml .Values.redis.resources | nindent 10 }}
113+
{{- if .Values.redis.livenessProbe.enabled | default true }}
114+
livenessProbe:
115+
exec:
116+
command:
117+
- sh
118+
- -c
119+
- |
120+
{{- if .Values.redis.auth.enabled }}
121+
redis-cli -a "$REDIS_PASSWORD" ping
122+
{{- else }}
123+
redis-cli ping
124+
{{- end }}
125+
initialDelaySeconds: {{ .Values.redis.livenessProbe.initialDelaySeconds | default 30 }}
126+
periodSeconds: {{ .Values.redis.livenessProbe.periodSeconds | default 10 }}
127+
timeoutSeconds: {{ .Values.redis.livenessProbe.timeoutSeconds | default 5 }}
128+
failureThreshold: {{ .Values.redis.livenessProbe.failureThreshold | default 3 }}
129+
{{- end }}
130+
{{- if .Values.redis.readinessProbe.enabled | default true }}
131+
readinessProbe:
132+
exec:
133+
command:
134+
- sh
135+
- -c
136+
- |
137+
{{- if .Values.redis.auth.enabled }}
138+
redis-cli -a "$REDIS_PASSWORD" ping
139+
{{- else }}
140+
redis-cli ping
141+
{{- end }}
142+
initialDelaySeconds: {{ .Values.redis.readinessProbe.initialDelaySeconds | default 5 }}
143+
periodSeconds: {{ .Values.redis.readinessProbe.periodSeconds | default 5 }}
144+
timeoutSeconds: {{ .Values.redis.readinessProbe.timeoutSeconds | default 3 }}
145+
failureThreshold: {{ .Values.redis.readinessProbe.failureThreshold | default 3 }}
146+
{{- end }}
147+
volumes:
148+
- name: redis-config
149+
configMap:
150+
name: {{ .Release.Name }}-redis-config
151+
{{- if not .Values.redis.storage.enabled }}
152+
- name: redis-data
153+
emptyDir: {}
154+
{{- end }}
155+
{{- if .Values.redis.storage.enabled }}
156+
volumeClaimTemplates:
157+
- metadata:
158+
name: redis-data
159+
spec:
160+
accessModes: {{ toYaml .Values.redis.storage.accessModes | nindent 8 }}
161+
{{- if .Values.redis.storage.storageClassName }}
162+
storageClassName: {{ .Values.redis.storage.storageClassName }}
163+
{{- end }}
164+
resources:
165+
requests:
166+
storage: {{ .Values.redis.storage.size }}
167+
{{- end }}
168+
{{- end }}

0 commit comments

Comments
 (0)