Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(minikube): fence writers during partial bootstrap recovery

Alfredo Lopezf5f1bccc9b9e
diff --git a/scripts/minikube/full-setup.sh b/scripts/minikube/full-setup.sh
index 49a85fa95..17597cef7 100755
--- a/scripts/minikube/full-setup.sh
+++ b/scripts/minikube/full-setup.sh
@@ -1106,10 +1106,16 @@ ok "Minikube K8s API CIDRs refreshed"
# profile already owns a serving plane, while an unready control-api can mean
# that the runtime-role Secret is still waiting for the migration below. Do not
# cut HCC over in that state, but do not deadlock recovery on the same readiness
-# condition either. Keep the GFS-owned documents untouched, apply only the
-# explicit non-GFS portion of the overlay, then complete migrations/roles before
-# the full overlay and GFS credential reconciliation.
-GFS_OVERLAY_DEFERRED=false
+# condition either. Fence the control-plane writers before migrations/roles,
+# then complete the full overlay and GFS credential reconciliation only after
+# runtime-role readiness has been proved.
+PARTIAL_BOOTSTRAP_RECOVERY=false
+PARTIAL_CONTROL_API_REPLICAS=1
+PARTIAL_WORKFLOW_REPLICAS=1
+PARTIAL_HCC_REPLICAS=1
+PARTIAL_CONTROL_API_FENCED=false
+PARTIAL_WORKFLOW_FENCED=false
+PARTIAL_HCC_FENCED=false
control_api_is_ready() {
local state replicas ready
@@ -1125,25 +1131,106 @@ control_api_is_ready() {
[[ "$ready" == "$replicas" ]]
}
-apply_non_gfs_overlay() {
- local filtered_manifest
- filtered_manifest="$(mktemp "${TMPDIR:-/tmp}/evenfire-gfs-recovery.XXXXXX")"
- if ! $KC kustomize "$ACTIVE_MINIKUBE_RENDER_DIR" \
- | python3 "${PROJECT_DIR}/scripts/minikube/filter-gfs-resources.py" >"$filtered_manifest"; then
- rm -f -- "$filtered_manifest"
- err "Failed to render or filter the non-GFS overlay during recovery"
+runtime_role_secret_is_missing() {
+ local dsn
+ if ! dsn="$($KC -n control-plane get secret control-api-postgres-runtime \
+ -o 'jsonpath={.data.connection-string}' --ignore-not-found 2>/dev/null)"; then
+ return 2
+ fi
+ [ -z "$dsn" ]
+}
+
+fence_partial_control_api() {
+ local replicas pods
+ replicas="$($KC -n control-plane get deployment/control-api -o 'jsonpath={.spec.replicas}')" \
+ || return 1
+ if [[ ! "$replicas" =~ ^[1-9][0-9]*$ ]]; then
+ err "control-api replica count is invalid; refusing partial-bootstrap recovery"
return 1
fi
- if [ -s "$filtered_manifest" ]; then
- if ! $KC apply -f "$filtered_manifest"; then
- rm -f -- "$filtered_manifest"
- err "Failed to apply the non-GFS overlay during recovery"
- return 1
- fi
- else
- log "Filtered recovery overlay contains no non-GFS resources; skipping apply"
+ PARTIAL_CONTROL_API_REPLICAS="$replicas"
+ log "Fencing control-api writers at ${PARTIAL_CONTROL_API_REPLICAS} replica(s)"
+ $KC -n control-plane scale deployment/control-api --replicas=0 >/dev/null
+ pods="$($KC -n control-plane get pods -l 'app=control-api,!clerum.io/component' -o name)" \
+ || return 1
+ if [ -n "$pods" ]; then
+ $KC -n control-plane wait --for=delete pod \
+ -l 'app=control-api,!clerum.io/component' --timeout=180s >/dev/null
+ fi
+ PARTIAL_CONTROL_API_FENCED=true
+}
+
+fence_partial_workflow_reconciler() {
+ local replicas pods
+ replicas="$($KC -n control-plane get deployment/workflow-recipes -o 'jsonpath={.spec.replicas}')" \
+ || return 1
+ if [[ ! "$replicas" =~ ^[0-9]+$ ]]; then
+ err "workflow-recipes replica count is invalid; refusing partial-bootstrap recovery"
+ return 1
+ fi
+ PARTIAL_WORKFLOW_REPLICAS="$replicas"
+ log "Fencing workflow-recipes at ${PARTIAL_WORKFLOW_REPLICAS} replica(s)"
+ $KC -n control-plane scale deployment/workflow-recipes --replicas=0 >/dev/null
+ pods="$($KC -n control-plane get pods -l app=workflow-recipes -o name)" \
+ || return 1
+ if [ -n "$pods" ]; then
+ $KC -n control-plane wait --for=delete pod \
+ -l app=workflow-recipes --timeout=180s >/dev/null
+ fi
+ PARTIAL_WORKFLOW_FENCED=true
+}
+
+fence_partial_hcc() {
+ local replicas pods
+ replicas="$($KC -n control-plane get deployment/host-context-controller -o 'jsonpath={.spec.replicas}')" \
+ || return 1
+ if [[ ! "$replicas" =~ ^[0-9]+$ ]]; then
+ err "host-context-controller replica count is invalid; refusing partial-bootstrap recovery"
+ return 1
+ fi
+ PARTIAL_HCC_REPLICAS="$replicas"
+ log "Fencing host-context-controller at ${PARTIAL_HCC_REPLICAS} replica(s)"
+ $KC -n control-plane scale deployment/host-context-controller --replicas=0 >/dev/null
+ pods="$($KC -n control-plane get pods -l app=host-context-controller -o name)" \
+ || return 1
+ if [ -n "$pods" ]; then
+ $KC -n control-plane wait --for=delete pod \
+ -l app=host-context-controller --timeout=180s >/dev/null
+ fi
+ PARTIAL_HCC_FENCED=true
+}
+
+fence_partial_bootstrap_writers() {
+ # HCC is fenced first so it cannot reconcile the existing GlobalFileSystem
+ # while the control-plane writer window is being closed. The control-api
+ # selector excludes migration Jobs, which intentionally share app=control-api.
+ fence_partial_hcc
+ fence_partial_workflow_reconciler
+ fence_partial_control_api
+}
+
+restore_partial_control_api() {
+ if [ "$PARTIAL_CONTROL_API_FENCED" != true ]; then
+ return 1
+ fi
+ log "Restoring control-api to ${PARTIAL_CONTROL_API_REPLICAS} replica(s) after runtime-role provisioning"
+ $KC -n control-plane scale deployment/control-api \
+ --replicas="$PARTIAL_CONTROL_API_REPLICAS" >/dev/null
+ $KC -n control-plane rollout status deployment/control-api --timeout=180s >/dev/null
+ PARTIAL_CONTROL_API_FENCED=false
+}
+
+restore_partial_non_api_writers() {
+ if [ "$PARTIAL_WORKFLOW_FENCED" = true ]; then
+ $KC -n control-plane scale deployment/workflow-recipes \
+ --replicas="$PARTIAL_WORKFLOW_REPLICAS" >/dev/null
+ PARTIAL_WORKFLOW_FENCED=false
+ fi
+ if [ "$PARTIAL_HCC_FENCED" = true ]; then
+ $KC -n control-plane scale deployment/host-context-controller \
+ --replicas="$PARTIAL_HCC_REPLICAS" >/dev/null
+ PARTIAL_HCC_FENCED=false
fi
- rm -f -- "$filtered_manifest"
}
reconcile_existing_gfs_credentials() {
@@ -1183,8 +1270,19 @@ else
err "Unable to determine control-api readiness; refusing to classify the GFS upgrade path"
exit 1
fi
- GFS_OVERLAY_DEFERRED=true
- log "Existing GFS writer detected but control-api is not Ready — deferring GFS-owned overlay and credential cutover until runtime roles converge"
+ if runtime_role_secret_is_missing; then
+ PARTIAL_BOOTSTRAP_RECOVERY=true
+ log "Existing GFS writer and empty control-api runtime Secret detected — fencing writers until migrations and runtime roles converge"
+ fence_partial_bootstrap_writers
+ else
+ runtime_secret_status=$?
+ if [ "$runtime_secret_status" -ne 1 ]; then
+ err "Unable to inspect control-api-postgres-runtime; refusing to classify the GFS upgrade path"
+ exit 1
+ fi
+ err "Existing GFS writer detected but control-api is not Ready; refusing HCC cutover"
+ exit 1
+ fi
fi
else
log "Fresh bootstrap detected — reader staging deferred until migrations; GFSC remains fail-closed"
@@ -1196,13 +1294,12 @@ if [ "$RESET_DB" = true ]; then
# Keep control-api scaled to zero until migrations and role restoration are
# complete; applying the full overlay here would race it against a fresh DB.
$KC apply -k "$ACTIVE_MINIKUBE_RENDER_DIR" -l app=control-postgres
-elif [ "$GFS_OVERLAY_DEFERRED" = true ]; then
- log "Applying the non-GFS recovery overlay before database migration..."
- apply_non_gfs_overlay
+elif [ "$PARTIAL_BOOTSTRAP_RECOVERY" = true ]; then
+ log "Deferring the full kustomize overlay until control-api/runtime roles converge"
else
$KC kustomize "$ACTIVE_MINIKUBE_RENDER_DIR" | $KC apply -f -
fi
-ok "Kustomize overlay applied (full or non-GFS recovery phase)"
+ok "Kustomize overlay applied or safely deferred"
if [ "$RESET_DB" = true ]; then
log "Rebuilding database contracts and restoring GFS roles after reset..."
@@ -1246,14 +1343,23 @@ else
# live before normal staging on bootstrap or an idempotent upgrade. On the
# deferred recovery path this is also the point where the missing runtime
# Secret has been provisioned, so the previously blocked deployment can start.
- $KC scale deployment/control-api -n control-plane --replicas=1 >/dev/null
- $KC rollout status deployment/control-api -n control-plane --timeout=180s >/dev/null
+ if [ "$PARTIAL_BOOTSTRAP_RECOVERY" = true ]; then
+ restore_partial_control_api
+ if ! control_api_is_ready; then
+ err "Restored control-api is not Ready; refusing GFS cutover after runtime-role provisioning"
+ exit 1
+ fi
+ else
+ $KC scale deployment/control-api -n control-plane --replicas=1 >/dev/null
+ $KC rollout status deployment/control-api -n control-plane --timeout=180s >/dev/null
+ fi
- if [ "$GFS_OVERLAY_DEFERRED" = true ]; then
+ if [ "$PARTIAL_BOOTSTRAP_RECOVERY" = true ]; then
log "Control-api/runtime roles are Ready — reconciling GFS before the deferred full overlay"
reconcile_existing_gfs_credentials
$KC kustomize "$ACTIVE_MINIKUBE_RENDER_DIR" | $KC apply -f -
- ok "Deferred full kustomize overlay applied after control-api/runtime role readiness"
+ restore_partial_non_api_writers
+ ok "Deferred full kustomize overlay applied after fenced writer/runtime-role readiness"
fi
# On the upgrade path the full overlay may still cut HCC over to the
diff --git a/scripts/tests/test-gfs-deploy-contract.sh b/scripts/tests/test-gfs-deploy-contract.sh
index b126c8c38..7aa136832 100755
--- a/scripts/tests/test-gfs-deploy-contract.sh
+++ b/scripts/tests/test-gfs-deploy-contract.sh
@@ -154,7 +154,9 @@ for upgrade_path in Makefile scripts/minikube/pre-gate-sync.sh scripts/minikube/
grep -q 'get secret gfs-controller-db' "$upgrade_path" || fail "$upgrade_path does not distinguish partial bootstrap"
done
assert_minikube_upgrade_classifier() {
- local path="$1" start="$2" end="$3" block dsn classify ready abort reconcile fallback fresh
+ local path="$1" start="$2" end="$3" block block_start dsn classify ready abort reconcile fallback fresh
+ block_start="$(grep -nF -- "$start" "$path" | head -1 | cut -d: -f1)"
+ [[ -n "$block_start" ]] || fail "$path is missing the upgrade classifier anchor"
block="$(awk -v start="$start" -v end="$end" '
index($0, start) { active=1 }
active { print }
@@ -167,25 +169,40 @@ assert_minikube_upgrade_classifier() {
reconcile="$(grep -n 'reconcile-gfs-deploy-credentials.sh' <<<"$block" | head -1 | cut -d: -f1)"
fallback="$(grep -nE '^[[:space:]]*else' <<<"$block" | tail -1 | cut -d: -f1)"
fresh="$(grep -ni 'fresh bootstrap' <<<"$block" | tail -1 | cut -d: -f1)"
+ for line_name in dsn classify ready abort reconcile fallback fresh; do
+ line_value="${!line_name}"
+ if [[ -n "$line_value" ]]; then
+ printf -v "$line_name" '%d' "$((block_start + line_value - 1))"
+ fi
+ done
if [[ "$path" == *"scripts/minikube/full-setup.sh" ]]; then
- local readiness_probe deferred non_gfs_filter deferred_full_overlay post_ready post_reconcile
+ local readiness_probe partial_flag fence_call migration roles restore_api deferred_full_overlay post_ready post_reconcile
readiness_probe="$(grep -n 'if control_api_is_ready' <<<"$block" | head -1 | cut -d: -f1)"
- deferred="$(grep -n 'GFS_OVERLAY_DEFERRED=true' <<<"$block" | head -1 | cut -d: -f1)"
- non_gfs_filter="$(grep -n 'filter-gfs-resources.py' "$path" | head -1 | cut -d: -f1)"
+ if [[ -n "$readiness_probe" ]]; then
+ readiness_probe=$((block_start + readiness_probe - 1))
+ fi
+ partial_flag="$(grep -n 'PARTIAL_BOOTSTRAP_RECOVERY=true' "$path" | head -1 | cut -d: -f1)"
+ fence_call="$(grep -nE '^[[:space:]]+fence_partial_bootstrap_writers$' "$path" | tail -1 | cut -d: -f1)"
+ migration="$(grep -n 'run-control-api-db-migration.sh' "$path" | head -1 | cut -d: -f1)"
+ roles="$(grep -n 'provision-control-api-runtime-roles.sh' "$path" | head -1 | cut -d: -f1)"
+ restore_api="$(grep -nE '^[[:space:]]+restore_partial_control_api$' "$path" | tail -1 | cut -d: -f1)"
deferred_full_overlay="$(grep -n 'Deferred full kustomize overlay applied' "$path" | head -1 | cut -d: -f1)"
post_ready="$(grep -n 'rollout status deployment/control-api.*timeout=180s' "$path" | tail -1 | cut -d: -f1)"
post_reconcile="$(grep -nE '^[[:space:]]+reconcile_existing_gfs_credentials$' "$path" | tail -1 | cut -d: -f1)"
- [[ -n "$dsn" && -n "$classify" && -n "$readiness_probe" && -n "$deferred" && \
- -n "$fallback" && -n "$fresh" && -n "$non_gfs_filter" && \
- -n "$deferred_full_overlay" && -n "$post_ready" && -n "$post_reconcile" ]] \
+ [[ -n "$dsn" && -n "$classify" && -n "$readiness_probe" && -n "$partial_flag" && \
+ -n "$fence_call" && -n "$fallback" && -n "$fresh" && -n "$migration" && \
+ -n "$roles" && -n "$restore_api" && -n "$deferred_full_overlay" && \
+ -n "$post_ready" && -n "$post_reconcile" ]] \
|| fail "$path recovery classifier is incomplete"
[[ "$dsn" -lt "$classify" && "$classify" -lt "$readiness_probe" && \
- "$readiness_probe" -lt "$deferred" && "$deferred" -lt "$fallback" && \
- "$fallback" -lt "$fresh" && "$non_gfs_filter" -lt "$deferred_full_overlay" && \
+ "$readiness_probe" -lt "$partial_flag" && "$partial_flag" -lt "$fence_call" && \
+ "$fence_call" -lt "$fallback" && "$fallback" -lt "$fresh" && \
+ "$migration" -lt "$roles" && "$roles" -lt "$restore_api" && \
+ "$restore_api" -lt "$post_reconcile" && "$post_reconcile" -lt "$deferred_full_overlay" && \
"$post_ready" -lt "$deferred_full_overlay" ]] \
- || fail "$path does not defer only the GFS-owned overlay until runtime-role readiness"
- ! grep -Fq 'Existing GFS writer detected but control-api is not Ready; refusing HCC cutover' "$path" \
- || fail "$path still deadlocks an unready partial bootstrap before runtime-role provisioning"
+ || fail "$path does not fence writers and defer the full overlay until runtime-role readiness"
+ grep -Fq 'Existing GFS writer detected but control-api is not Ready; refusing HCC cutover' "$path" \
+ || fail "$path no longer retains the fail-closed guard for an unrecognized unready upgrade"
else
[[ -n "$dsn" && -n "$classify" && -n "$ready" && -n "$abort" && -n "$reconcile" && -n "$fallback" && -n "$fresh" ]] \
|| fail "$path upgrade classifier is incomplete"