Files
vjailbreak/image_builder/configs/daemonset.yaml
T
2026-09-15 22:46:46 +05:30

100 lines
3.3 KiB
YAML

apiVersion: apps/v1
kind: DaemonSet
metadata:
name: sync-daemon
namespace: kube-system
labels:
app: sync-daemon
spec:
selector:
matchLabels:
app: sync-daemon
template:
metadata:
labels:
app: sync-daemon
spec:
hostNetwork: true
initContainers:
- name: fix-perms
image: alpine:latest
securityContext:
privileged: true
runAsUser: 0
command: ["/bin/sh", "-c"]
args:
- |
echo "Fixing permissions on /home/ubuntu/vmware-vix-disklib-distrib..."
chown -R 1000:1000 /home/ubuntu/vmware-vix-disklib-distrib
chmod 755 /home/ubuntu/vmware-vix-disklib-distrib
volumeMounts:
- name: vmwarelib
mountPath: /home/ubuntu/vmware-vix-disklib-distrib
containers:
- name: sync-container
image: alpine:latest
securityContext:
privileged: true
runAsUser: 0
runAsGroup: 0
ports:
- containerPort: 873
volumeMounts:
- name: pf9-env
mountPath: /etc/pf9
readOnly: true
- name: vmwarelib
mountPath: /home/ubuntu/vmware-vix-disklib-distrib
- name: logs
mountPath: /var/log/pf9
command: ["/bin/sh", "-c"]
args:
- |
apk add --no-cache rsync coreutils grep
IS_MASTER=$(grep -E '^export IS_MASTER=' /etc/pf9/k3s.env | cut -d'=' -f2)
MASTER_IP=$(grep -E '^export MASTER_IP=' /etc/pf9/k3s.env | cut -d'=' -f2)
if [ "$IS_MASTER" = "true" ]; then
echo "Master node detected. IP: $MASTER_IP"
echo "Starting rsync daemon..."
rsync --daemon --config=/etc/pf9/rsyncd.conf --no-detach
if ps aux | grep rsync | grep -v grep; then
echo "rsync daemon is running."
else
echo "Failed to start rsync daemon."
exit 1
fi
else
echo "Worker node detected. Syncing from Master..."
while true; do
mkdir -p /home/ubuntu/vmware-vix-disklib-distrib/
echo "Syncing from rsync://${MASTER_IP}"
rsync -avz rsync://${MASTER_IP}/vmwarelib/ /home/ubuntu/vmware-vix-disklib-distrib/
# Sync logs from worker to master
rsync -avz /var/log/pf9 rsync://${MASTER_IP}/worker-logs
# Also Sync logs from master to worker
rsync -avz rsync://${MASTER_IP}/master-logs /var/log/pf9
if [ $? -eq 0 ]; then
echo "Sync completed successfully."
else
echo "Sync failed. Retrying in 60 seconds..."
fi
sleep 20
done
fi
volumes:
- name: pf9-env
hostPath:
path: /etc/pf9
type: DirectoryOrCreate
- name: vmwarelib
hostPath:
path: /home/ubuntu/vmware-vix-disklib-distrib
type: DirectoryOrCreate
- name: logs
hostPath:
type: DirectoryOrCreate
path: /var/log/pf9