fix: cache lag retry, go.work, провайдер rollback, test v4 no -target

This commit is contained in:
Naeel
2026-03-23 10:03:26 +03:00
parent cb77a7f68e
commit 7a168185ea
6 changed files with 155 additions and 24 deletions
+70 -13
View File
@@ -1,12 +1,13 @@
#!/bin/bash
# test_cache_matrix.sh — 2026-03-23 (v3)
# test_cache_matrix.sh — 2026-03-23 (v4)
# Комплексный тест кэша registry:
# Phase 1 — полный деплой всех 24 ресурсов (kaniko builds, т.к. нет образов)
# Phase 2 — destroy sless_* + re-apply (все образы из кэша)
# Phase 3 — одновременно: удаление 2, смена кода 2, смена параметров 2
# ВАЖНО: nubes_postgres.npg и nubes_postgres_database НЕ уничтожаются.
# Причина: пересоздание БД ротирует пароль user0 в k8s secret;
# vault_secrets на это не реагирует сразу → FunctionJob получает старый пароль.
# ВАЖНО: postgres.tf НЕ переименовывается и НЕ трогается никогда.
# Destroy sless-ресурсов делается путём переименования tf-файлов в .tf.bak,
# затем terraform apply (видит что ресурсов нет → удаляет их из state+кластера),
# затем файлы возвращаются обратно. Никаких -target.
set -euo pipefail
DIR="$(cd "$(dirname "$0")" && pwd)"
@@ -38,17 +39,29 @@ timed_op() {
}
destroy_sless_only() {
# Переименовываем tf-файлы с sless-ресурсами в .tf.bak → terraform apply их удалит.
# Никаких -target — чтобы не затрагивать postgres и не получать state drift.
local label="$1"
local targets
targets=$(terraform state list 2>/dev/null | grep -E '^(sless_service|sless_job)' | sed 's/^/-target=/' | tr '
' ' ' || true)
if [[ -z "$targets" ]]; then
local SLESS_FILES=("chaos_marathon.tf" "functions.tf" "stress.tf")
local has_state
has_state=$(terraform state list 2>/dev/null | grep -cE '^(sless_service|sless_job)' || true)
if [[ "$has_state" -eq 0 ]]; then
log " (nothing to destroy for $label — state empty)"
return 0
fi
local n; n=$(terraform state list 2>/dev/null | grep -cE '^(sless_service|sless_job)' || true)
log " Targets: $n resources"
timed_op "$label" terraform destroy $targets -auto-approve
log " Hiding sless tf-files → apply will destroy $has_state resources"
for f in "${SLESS_FILES[@]}"; do
[[ -f "$DIR/$f" ]] && mv "$DIR/$f" "$DIR/$f.bak"
done
timed_op "$label" terraform apply -auto-approve
for f in "${SLESS_FILES[@]}"; do
[[ -f "$DIR/$f.bak" ]] && mv "$DIR/$f.bak" "$DIR/$f"
done
log " sless tf-files restored"
}
cd "$DIR"
@@ -72,8 +85,52 @@ sep
log "PHASE 3: Mixed ops (delete+code+params)"
sep
log "--- 3a: destroy targets: stress_divzero, chaos_echo ---"
timed_op "phase3a-destroy-targets" terraform destroy -target=sless_service.stress_divzero -target=sless_service.chaos_echo -auto-approve
log "--- 3a: destroy stress_divzero, chaos_echo (comment out → apply → restore) ---"
python3 - <<'PYEOF'
import re, pathlib
def comment_out_resource(path, resource_type, resource_name):
text = pathlib.Path(path).read_text()
# Находим блок resource "type" "name" { ... } и оборачиваем в /* */
pattern = rf'(resource\s+"{re.escape(resource_type)}"\s+"{re.escape(resource_name)}"\s*\{{)'
match = re.search(pattern, text)
if not match:
print(f" WARNING: {resource_type}.{resource_name} not found in {path}")
return
# Найти закрывающую скобку блока
start = match.start()
depth = 0
i = match.start()
while i < len(text):
if text[i] == '{': depth += 1
elif text[i] == '}':
depth -= 1
if depth == 0:
end = i + 1
break
i += 1
block = text[start:end]
commented = "/* COMMENTED_OUT_FOR_TEST\n" + block + "\nCOMMENTED_OUT_FOR_TEST */"
pathlib.Path(path).write_text(text[:start] + commented + text[end:])
print(f" commented out: {resource_type}.{resource_name} in {path}")
comment_out_resource("stress.tf", "sless_service", "stress_divzero")
comment_out_resource("chaos_marathon.tf", "sless_service", "chaos_echo")
PYEOF
timed_op "phase3a-destroy-2" terraform apply -auto-approve
# Восстанавливаем закомментированные блоки
python3 - <<'PYEOF'
import pathlib, re
for fname in ("stress.tf", "chaos_marathon.tf"):
p = pathlib.Path(fname)
text = p.read_text()
text = re.sub(r'/\* COMMENTED_OUT_FOR_TEST\n', '', text)
text = re.sub(r'\nCOMMENTED_OUT_FOR_TEST \*/', '', text)
p.write_text(text)
print(f" restored: {fname}")
PYEOF
log " stress_divzero, chaos_echo removed from state and k8s"
log "--- 3b: code changes (new sha256 → kaniko) ---"
echo "" >> "$DIR/code/pg-counter/pg_counter.py"