fix(db): use seconds for connection pool timeouts instead of milliseconds

ConfigMap values are in seconds (e.g. connection_timeout=30 means 30s),
but Duration::from_millis() interpreted them as ms (30ms), causing pool
timeout on startup. Changed to from_secs(). Also removed Namespace from
Helm chart to prevent cascade deletion of PVC/ConfigMap on uninstall.
This commit is contained in:
ZhenYi 2026-05-10 23:58:16 +08:00
parent 065c9e6aa5
commit b560d9ea0f
5 changed files with 14 additions and 19 deletions

View File

@ -25,16 +25,16 @@ command_exists kubectl || err "kubectl not found — install via https://kuberne
log "helm $(helm version --short)" log "helm $(helm version --short)"
log "kubectl $(kubectl version --client --short 2>/dev/null || kubectl version -o json 2>/dev/null | grep gitVersion)" log "kubectl $(kubectl version --client --short 2>/dev/null || kubectl version -o json 2>/dev/null | grep gitVersion)"
# ── 1. Ensure namespace with Helm ownership ────────────────────────── # ── 1. Ensure namespace (not managed by Helm — preserved on uninstall) ──
log "Ensuring namespace $NAMESPACE exists with Helm ownership..." log "Ensuring namespace $NAMESPACE exists..."
kubectl create namespace "$NAMESPACE" --dry-run=client -o yaml | kubectl apply -f - kubectl create namespace "$NAMESPACE" --dry-run=client -o yaml | kubectl apply -f -
kubectl label namespace "$NAMESPACE" app.kubernetes.io/managed-by=Helm --overwrite
kubectl label namespace "$NAMESPACE" meta.helm.sh/release-name="$RELEASE" --overwrite
kubectl label namespace "$NAMESPACE" meta.helm.sh/release-namespace="$NAMESPACE" --overwrite
kubectl annotate namespace "$NAMESPACE" meta.helm.sh/release-name="$RELEASE" --overwrite
kubectl annotate namespace "$NAMESPACE" meta.helm.sh/release-namespace="$NAMESPACE" --overwrite
# ── 2. Ensure prerequisites ───────────────────────────────────────── # ── 2. Ensure prerequisites ─────────────────────────────────────────
# Namespace must exist (not managed by Helm)
if ! kubectl get namespace "$NAMESPACE" &>/dev/null; then
err "Namespace '$NAMESPACE' not found — create it first: kubectl create namespace $NAMESPACE"
fi
# ConfigMap (must exist before Helm install) # ConfigMap (must exist before Helm install)
if ! kubectl get configmap "$CONFIG_MAP" -n "$NAMESPACE" &>/dev/null; then if ! kubectl get configmap "$CONFIG_MAP" -n "$NAMESPACE" &>/dev/null; then
err "ConfigMap '$CONFIG_MAP' not found in namespace '$NAMESPACE' — create it first" err "ConfigMap '$CONFIG_MAP' not found in namespace '$NAMESPACE' — create it first"

View File

@ -1,9 +1,4 @@
apiVersion: v1 apiVersion: v1
kind: Namespace
metadata:
name: {{ .Values.gingress.namespace | default "gingress-system" }}
---
apiVersion: v1
kind: ServiceAccount kind: ServiceAccount
metadata: metadata:
name: gingress-controller name: gingress-controller

View File

@ -161,7 +161,7 @@ ingress:
enabled: true enabled: true
className: "gingress" className: "gingress"
annotations: annotations:
cert-manager.io/cluster-issuer: "letsencrypt-prod" cert-manager.io/cluster-issuer: "cloudflare-acme-cluster-issuer"
gingress.io/git-backend: "deploy-gitserver:8021" gingress.io/git-backend: "deploy-gitserver:8021"
hosts: hosts:
- host: gitdata.ai - host: gitdata.ai

View File

@ -23,19 +23,19 @@ impl AppConfig {
if let Some(idle_timeout) = self.env.get("APP_DATABASE_IDLE_TIMEOUT") { if let Some(idle_timeout) = self.env.get("APP_DATABASE_IDLE_TIMEOUT") {
return Ok(idle_timeout.parse::<u64>()?); return Ok(idle_timeout.parse::<u64>()?);
} }
Ok(60000) // milliseconds Ok(600) // seconds
} }
pub fn database_max_lifetime(&self) -> anyhow::Result<u64> { pub fn database_max_lifetime(&self) -> anyhow::Result<u64> {
if let Some(max_lifetime) = self.env.get("APP_DATABASE_MAX_LIFETIME") { if let Some(max_lifetime) = self.env.get("APP_DATABASE_MAX_LIFETIME") {
return Ok(max_lifetime.parse::<u64>()?); return Ok(max_lifetime.parse::<u64>()?);
} }
Ok(300000) // milliseconds Ok(3600) // seconds
} }
pub fn database_connection_timeout(&self) -> anyhow::Result<u64> { pub fn database_connection_timeout(&self) -> anyhow::Result<u64> {
if let Some(connection_timeout) = self.env.get("APP_DATABASE_CONNECTION_TIMEOUT") { if let Some(connection_timeout) = self.env.get("APP_DATABASE_CONNECTION_TIMEOUT") {
return Ok(connection_timeout.parse::<u64>()?); return Ok(connection_timeout.parse::<u64>()?);
} }
Ok(5000) // milliseconds Ok(8) // seconds
} }
pub fn database_schema_search_path(&self) -> anyhow::Result<String> { pub fn database_schema_search_path(&self) -> anyhow::Result<String> {
if let Some(schema_search_path) = self.env.get("APP_DATABASE_SCHEMA_SEARCH_PATH") { if let Some(schema_search_path) = self.env.get("APP_DATABASE_SCHEMA_SEARCH_PATH") {

View File

@ -26,9 +26,9 @@ impl AppDatabase {
let conn_cfg = sea_orm::ConnectOptions::new(db_url) let conn_cfg = sea_orm::ConnectOptions::new(db_url)
.max_connections(max_connections) .max_connections(max_connections)
.min_connections(min_connections) .min_connections(min_connections)
.idle_timeout(Duration::from_millis(idle_timeout)) .idle_timeout(Duration::from_secs(idle_timeout))
.max_lifetime(Duration::from_millis(max_lifetime)) .max_lifetime(Duration::from_secs(max_lifetime))
.connect_timeout(Duration::from_millis(connection_timeout)) .connect_timeout(Duration::from_secs(connection_timeout))
.set_schema_search_path(schema_search_path) .set_schema_search_path(schema_search_path)
.sqlx_logging(false) .sqlx_logging(false)
.to_owned(); .to_owned();