Skip to content

Commit 85172af

Browse files
committed
Add replay-mounter daemonset
1 parent d6f57b2 commit 85172af

7 files changed

Lines changed: 118 additions & 2 deletions

File tree

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ spicy-secrets/**
1111

1212
tilt_config.json
1313
.local-data/
14-
.helm-cache/
14+
.helm-cache/
15+
16+
# Script related stuff
17+
**/.gradle

cluster/namespaces.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,10 @@ metadata:
1919
apiVersion: v1
2020
kind: Namespace
2121
metadata:
22-
name: traefik
22+
name: traefik
23+
24+
---
25+
apiVersion: v1
26+
kind: Namespace
27+
metadata:
28+
name: replay-mounter

cluster/replay-mounter/Chart.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: v2
2+
name: replay-mounter
3+
version: 1.0.0
4+
description: CIFS/SMB mount watchdog for the faf-replays hostPath PV
5+
6+
dependencies:
7+
- name: infisical-secret
8+
version: 1.0.0
9+
repository: file://../../common/infisical-secret
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{{- if .Values.cifsMount.enabled }}
2+
apiVersion: apps/v1
3+
kind: DaemonSet
4+
metadata:
5+
name: replay-mounter
6+
namespace: replay-mounter
7+
spec:
8+
selector:
9+
matchLabels:
10+
app: replay-mounter
11+
template:
12+
metadata:
13+
labels:
14+
app: replay-mounter
15+
spec:
16+
hostPID: true
17+
nodeSelector:
18+
openebs.io/nodeid: {{ .Values.zfs.nodeId }}
19+
terminationGracePeriodSeconds: 30
20+
containers:
21+
- name: replay-mounter
22+
image: {{ .Values.cifsMount.image }}
23+
securityContext:
24+
privileged: true
25+
env:
26+
- name: CIFS_SERVER
27+
valueFrom:
28+
secretKeyRef:
29+
name: {{ .Values.cifsMount.credentialsSecret }}
30+
key: CIFS_SERVER
31+
- name: CIFS_USERNAME
32+
valueFrom:
33+
secretKeyRef:
34+
name: {{ .Values.cifsMount.credentialsSecret }}
35+
key: CIFS_USERNAME
36+
- name: CIFS_PASSWORD
37+
valueFrom:
38+
secretKeyRef:
39+
name: {{ .Values.cifsMount.credentialsSecret }}
40+
key: CIFS_PASSWORD
41+
- name: MOUNT_TARGET
42+
value: "{{ .Values.dataPath }}/{{ .Values.targetFolder }}/{{ .Values.cifsMount.subfolder }}"
43+
command:
44+
- /bin/sh
45+
- -c
46+
- |
47+
apk add --no-cache cifs-utils
48+
49+
cleanup() {
50+
nsenter --mount=/proc/1/ns/mnt -- umount "$MOUNT_TARGET" 2>/dev/null || \
51+
nsenter --mount=/proc/1/ns/mnt -- umount -l "$MOUNT_TARGET" 2>/dev/null || true
52+
exit 0
53+
}
54+
trap cleanup TERM INT
55+
56+
mount_cifs() {
57+
nsenter --mount=/proc/1/ns/mnt -- mkdir -p "$MOUNT_TARGET"
58+
nsenter --mount=/proc/1/ns/mnt -- \
59+
mount -t cifs "$CIFS_SERVER" "$MOUNT_TARGET" \
60+
-o "username=$CIFS_USERNAME,password=$CIFS_PASSWORD,{{ .Values.cifsMount.mountOptions }}"
61+
}
62+
63+
# Skip if already mounted (handles pod restarts without unmounting first)
64+
if ! nsenter --mount=/proc/1/ns/mnt -- mountpoint -q "$MOUNT_TARGET"; then
65+
until mount_cifs; do echo "Mount failed, retrying in 10s..."; sleep 10; done
66+
fi
67+
68+
# Watchdog
69+
while true; do
70+
sleep 30 &
71+
wait $!
72+
if ! nsenter --mount=/proc/1/ns/mnt -- mountpoint -q "$MOUNT_TARGET"; then
73+
echo "Mount lost, remounting..."
74+
nsenter --mount=/proc/1/ns/mnt -- umount -f "$MOUNT_TARGET" 2>/dev/null || true
75+
mount_cifs || true
76+
fi
77+
done
78+
{{- end }}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cifsMount:
2+
enabled: true
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cifsMount:
2+
enabled: true

cluster/replay-mounter/values.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
cifsMount:
2+
enabled: false
3+
subfolder: "replay-old" # dir created under /opt/faf/data/replays/
4+
credentialsSecret: "cifs-credentials"
5+
mountOptions: "ro,vers=3.0,uid=1000,gid=1000,file_mode=0644,dir_mode=0755"
6+
image: "alpine:3.21"
7+
8+
dataPath: "/opt/faf/data"
9+
targetFolder: "replays"
10+
11+
# zfs.nodeId injected from config/prod.yaml
12+
# infisical-secret.enabled injected from config/prod.yaml
13+
infisical-secret:
14+
name: cifs-credentials
15+
secretNamespace: replay-mounter # namespace where infisical-machine-identity lives
16+
overrideSecretPath: "/replay-mounter"

0 commit comments

Comments
 (0)