fix(cd): 處理 K8s selector immutability 問題

問題: kustomize labels 配置變更導致 selector 不匹配
修復: 偵測到 "field is immutable" 錯誤時自動刪除重建 Deployment

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
OG T
2026-03-26 19:53:51 +08:00
parent fb03430469
commit 6421af05f9

View File

@@ -281,7 +281,19 @@ jobs:
echo "⏭️ 跳過 Web image 更新 (build skipped)"
fi
kubectl apply -k .
# 2026-03-26: 處理 selector immutability 問題
# 如果 apply 失敗 (通常是 selector 變更),先刪除再重建
if ! kubectl apply -k . 2>&1 | tee /tmp/apply.log; then
if grep -q "field is immutable" /tmp/apply.log; then
echo "⚠️ 偵測到 selector 不可變錯誤,執行強制重建..."
kubectl delete deployment awoooi-api awoooi-web awoooi-worker -n awoooi-prod --ignore-not-found
sleep 5
kubectl apply -k .
else
echo "❌ 部署失敗 (非 selector 問題)"
exit 1
fi
fi
# 2026-03-26: CoreDNS GitOps 同步 (ADR-026)
- name: Sync CoreDNS Config