fix(kubernetes): make retained PVC preparation robust (#3697)

This commit is contained in:
José Almeida
2026-09-15 16:16:08 +02:00
committed by GitHub
parent 6c5ab15980
commit d986a14326
7 changed files with 233 additions and 7 deletions
+10 -3
View File
@@ -28,6 +28,13 @@ repository_url={{repository.clone_url}}
repository_branch={{repository.branch}}
clone_tmp=/opt/kandev/.workspace-clone
normalize_repository_origin() {
printf '%s\n' "$1" | sed \
-e 's|^https://[^/@]*@github.com/|https://github.com/|' \
-e 's|^git@github.com:|https://github.com/|' \
-e 's|^ssh://git@github.com/|https://github.com/|'
}
# ---- Git identity and HTTPS authentication ----
{{git.identity_setup}}
git config --global --add safe.directory '*'
@@ -44,8 +51,8 @@ if [ -n "$repository_url" ]; then
exit 1
fi
workspace_origin=$(git -C "$workspace" remote get-url origin 2>/dev/null || true)
expected_origin=$(printf '%s\n' "$repository_url" | sed 's|^https://[^/@]*@github.com/|https://github.com/|')
retained_origin=$(printf '%s\n' "$workspace_origin" | sed 's|^https://[^/@]*@github.com/|https://github.com/|')
expected_origin=$(normalize_repository_origin "$repository_url")
retained_origin=$(normalize_repository_origin "$workspace_origin")
if [ -z "$workspace_origin" ] || [ "$retained_origin" != "$expected_origin" ]; then
echo 'kandev: retained workspace repository origin does not match the configured repository' >&2
exit 1
@@ -60,7 +67,7 @@ if [ -n "$repository_url" ]; then
rm -rf "$clone_tmp"
trap 'rm -rf "$clone_tmp"' 0 1 2 15
git clone --depth=1 --branch "$repository_branch" "$repository_url" "$clone_tmp"
cp -a "$clone_tmp"/. "$workspace"/
cp -R "$clone_tmp"/. "$workspace"/
rm -rf "$clone_tmp"
trap - 0 1 2 15
fi