fix(k8s): handle existing workspace on pod restart
Some checks failed
Build and Deploy / build (push) Has been cancelled

The clone init container was failing with 'destination path already exists'
when the pod restarted. EmptyDir volumes persist across container restarts
but init containers run again.

Now checks if workspace exists:
- If .git directory exists: fetch and reset to latest master
- If not: clean and clone fresh

This fixes the CrashLoopBackOff caused by failed clone attempts.
This commit is contained in:
Unchained
2026-04-05 05:17:30 +02:00
parent 6caefb420a
commit a636d29f0b

View File

@@ -22,10 +22,20 @@ spec:
- |
set -e
apk add --no-cache git
git clone --depth 1 --branch master \
http://gitea.gitea.svc.cluster.local:3000/unchained/manoon-headless.git \
/workspace
echo "Clone complete."
# Clean workspace if it exists (handles pod restarts)
if [ -d /workspace/.git ]; then
echo "Workspace exists, pulling latest changes..."
cd /workspace
git fetch origin master
git reset --hard origin/master
else
echo "Cloning fresh repository..."
rm -rf /workspace/*
git clone --depth 1 --branch master \
http://gitea.gitea.svc.cluster.local:3000/unchained/manoon-headless.git \
/workspace
fi
echo "Clone/update complete."
volumeMounts:
- name: workspace
mountPath: /workspace