phase132: prove nvme desired path reconnect

This commit is contained in:
pingqiu committed 2026-07-04 14:48:23 -07:00
1 parent e622bea61d
commit cfaf29cc11
10 files changed
+769 -42

No files matched your search

+5 -3
View File
@@ -78,7 +78,9 @@ This is an **alpha** product path for supported lab clusters, not production.
multi-volume path churn, repeated stage/unstage residue checks, a bounded
writer/reader soak, a baseline over the configured 100GbE TCP frontend
address, a source-gated CSI-node reconnect owner contract, and a live
host-path reconnect gate for scoped `nvme disconnect -d` path loss. This is a
host-path reconnect gate for scoped `nvme disconnect -d` path loss, plus a
live desired path-set replacement gate where CSI-node connects the new
desired NVMe path without remounting the pod. This is a
supported-lab source-gated claim, not a broad NVMe
compatibility, RoCE/NVMe-RDMA, production HA, or performance/SLO claim.
- Replay support bundles offline.
@@ -101,8 +103,8 @@ These are narrow alpha claims tied to documented gates. See
- Transparent Kubernetes node-loss failover without pod recreate.
- Broad NVMe/RoCE compatibility, performance/SLO, or transparent failover
parity beyond the documented supported-lab gates. The CSI-node reconnect
owner and host-path reconnect gate exist; control-plane desired path-set
replacement/failover remains next.
owner, host-path reconnect gate, and desired path-set replacement gate exist;
stale host-path pruning after replacement remains next.
- Broad distro/kernel/initiator compatibility.
- Upgrade or rollback execution. The status layer can report install drift, but
it does not run Helm or kubectl mutations.
@@ -33,6 +33,8 @@ The supported-lab claim is intentionally narrow:
- two mounted volumes remain isolated through path loss and restore;
- bounded multi-volume churn passes across three alternating loss/restore
cycles;
- changed control-plane desired path sets cause CSI-node to connect the new
desired NVMe/TCP path for a mounted pod without remounting;
- uninstall/cleanup leaves zero Seaweed Block Kubernetes, iSCSI, process,
multipath, and hostPath residue.
@@ -69,6 +71,7 @@ The supported-lab claim is intentionally narrow:
| 129 | CSI mounted NVMe restage contract | PASS |
| 130 | CSI-node reconnect owner/trigger contract | PASS |
| 131 | Live Kubernetes host-path reconnect through CSI-node owner | PASS |
| 132 | Live Kubernetes desired path-set change through CSI-node owner | PASS |
Key QA sign-offs:
@@ -84,6 +87,7 @@ Key QA sign-offs:
- `internal/docs/qa-assignments/phase129-nvme-k8s-mounted-restage-qa-signoff.md`
- `internal/docs/qa-assignments/phase130-nvme-reconnect-owner-qa-signoff.md`
- `internal/docs/qa-assignments/phase131-nvme-k8s-reconnect-live-qa-signoff.md`
- `internal/docs/qa-assignments/phase132-nvme-k8s-desired-path-change-qa-signoff.md`
## Performance Baseline
+4
View File
@@ -102,6 +102,10 @@ Seaweed Block can already demonstrate a narrow Kubernetes block-storage loop:
live cross-node writer/reader gate against a routable NVMe/TCP target. This
is still not a RoCE, performance/SLO, broad compatibility, or production HA
claim.
- Kubernetes NVMe/TCP mounted reconnect is source-gated through changed
desired path-set evidence: CSI-node can connect a newly published desired
NVMe path without pod remount and keep mounted I/O working. Stale host-path
pruning after replacement remains the next correctness gap.
- Install drift status for current versus desired chart/app/image identity
without upgrade execution.
- CRD/RBAC status-writer conformance coverage for the failures that previously
+41 -34
View File
@@ -1,24 +1,31 @@
# Current Plan: Phase 132 Kubernetes NVMe Desired Path-Set Change Close Gate
# Current Plan: Phase 133 Kubernetes NVMe Stale Path Pruning Close Gate
Status: planning.
Phase 131 proved live host-path reconnect: a mounted RF=2 NVMe/TCP PVC starts
with two host paths, one controller/path is disconnected with scoped
`nvme disconnect -d`, and the CSI-node owner reconnects the missing path while
pod UID, I/O, and status surfaces stay correct.
Phase 132 proved live desired path-set convergence: a mounted RF=2 NVMe/TCP PVC
started with two desired paths, one generated frontend path was replaced with a
different reachable address, `SwBlockVolume.status.nvme.nvmeAddrs` changed from
old to new, the CSI-node owner connected the new path, pod UID/I/O were
preserved, and CRD/report/dashboard agreed.
Phase 132 should close the remaining NVMe Kubernetes failover semantics gap:
the desired frontend path set itself changes after replacement/failover, and
the mounted pod reconnects to the new desired path.
The live run also exposed the next gap:
```text
stale_old_host_path_after_desired_change=true
host_path_count_after_desired_change=3
```
The product connects new desired paths, but it does not yet prune stale mounted
NVMe paths for the same NQN that are no longer in the desired set.
## Goal
```text
mounted RF=2 NVMe/TCP PVC starts with two desired paths
-> one frontend/replica path is replaced or failed over
-> control-plane publish evidence changes to the new desired path set
-> CSI-node reconnect owner observes the changed desired path set
-> owner connects the new desired path without remount
-> one frontend/replica path is replaced with a different reachable address
-> control-plane desired path set changes old->new
-> CSI-node reconnect owner connects the new desired path
-> CSI-node reconnect owner disconnects the stale old path for the same NQN
-> mounted pod UID is preserved and I/O still works
-> CRD/report/dashboard agree
```
@@ -26,15 +33,18 @@ mounted RF=2 NVMe/TCP PVC starts with two desired paths
## Required Evidence
```text
phase132_nvme_k8s_desired_path_change_status=ok
phase133_nvme_k8s_stale_path_prune_status=ok
initial_path_count=2
old_desired_path=<addr>
new_desired_path=<addr>
desired_path_set_changed=true
path_loss_or_replacement_detected=true
reconnect_owner=csi-node
reconnect_invoked=true
new_desired_path_connected=true
stale_old_path_detected=true
stale_old_path_pruned=true
host_path_count_after_prune=2
host_paths_after_prune=<new + remaining desired only>
pod_uid_preserved=true
mounted_io_after_reconnect=ok
crd_status_agrees=true
@@ -44,28 +54,25 @@ cleanup_status=ok
## Boundaries
- Do not reuse host-only path disconnect as proof; Phase 131 already covers
that.
- Do not claim pass if Linux auto-reconnects the same old path without a
control-plane desired path change.
- Do not use `nvme disconnect-all` for injected failure.
- Do not use `nvme disconnect-all` as proof or implementation.
- Do not disconnect paths for other NQNs or other volumes.
- Do not prune a path unless current control-plane evidence positively excludes
that address from the desired set for the same NQN.
- Do not claim pass if only the new path connects while the old host path
remains.
- Do not claim NVMe/RDMA/RoCE or performance/SLO.
## Candidate Gate Design
1. Start from the Phase131 live setup with `stage2Multipath.enabled=true` and
`csiNode.nvmeReconnect.enabled=true`.
2. Force one frontend path to be replaced with a different reachable
`addr/NQN`-compatible path, or add a controlled replacement frontend target
for the same NQN/NSID while the old path is removed.
3. Assert `SwBlockVolume.status.nvme.nvmeAddrs` changes from old to new.
4. Assert CSI-node owner logs reconnect for the new path.
5. Assert mounted pod UID and I/O are preserved.
6. Assert CRD/report/dashboard agree and cleanup is clean.
1. Extend the CSI-node mounted NVMe reconnect owner to list current host paths
for the staged NQN.
2. After connecting all desired paths, compute stale connected paths:
`connected_for_nqn - desired_addrs`.
3. Disconnect stale paths by scoped controller/path only.
4. Reuse the Phase132 live setup and desired-path replacement injection.
5. Assert the new desired path is connected and the old host path is gone.
6. Assert mounted pod UID/I/O, CRD/report/dashboard agreement, and cleanup.
## Next After Phase 132
If Phase 132 passes, the NVMe Kubernetes correctness loop is strong enough to
return to write-path performance optimization from Phase 126. If it blocks,
record whether the missing piece is frontend replacement machinery,
publish-evidence propagation, or CSI-node trigger semantics.
If Phase 133 passes, the Kubernetes NVMe mounted failover path has a much
stronger correctness loop: fresh desired paths connect and stale paths are
bounded. Then return to write-path performance optimization from Phase 126.
@@ -0,0 +1,124 @@
# Phase 132 Finished Plan: Kubernetes NVMe Desired Path-Set Change Close Gate
Status: complete. Live QA PASS on 2026-07-04.
## Problem
Phase 131 proved that the CSI-node reconnect owner can restore a missing host
NVMe path when the control-plane desired path set is unchanged.
The remaining correctness gap was stronger:
```text
mounted RF=2 NVMe/TCP PVC
-> one frontend path is replaced
-> control-plane desired path set changes
-> mounted pod connects the new desired path without restage/remount
-> I/O continues
```
Without this gate, we could only claim host-path reconnect, not dynamic desired
path-set convergence.
## What Changed
Phase 132 adds a live gate:
```text
scripts/run-phase132-nvme-k8s-desired-path-change-gate.sh
testops/scenarios/nvme-tcp-k8s-desired-path-change-chain.yaml
```
The gate reuses the Phase 111/131 Kubernetes NVMe harness and adds a dedicated
`SW_BLOCK_NVME_DESIRED_PATH_CHANGE=1` branch. It:
1. Installs an RF=2 NVMe/TCP PVC with stage-2 multipath and the CSI-node
reconnect owner enabled.
2. Creates a mounted pod and records its UID.
3. Replaces one generated blockvolume Deployment's `--nvme-listen` address
with a different reachable address.
4. Waits for `SwBlockVolume.status.nvme.nvmeAddrs` to drop the old address and
include the new address.
5. Waits for CSI-node owner logs proving the new desired address was connected.
6. Verifies mounted I/O and pod UID preservation.
7. Verifies CRD, report, and dashboard agreement.
8. Verifies zero-residue cleanup.
## Verification
Local:
```text
bash -n scripts/run-phase111-nvme-k8s-path-loss-crd-gate.sh
bash -n scripts/run-phase132-nvme-k8s-desired-path-change-gate.sh
swblock validate testops/scenarios/nvme-tcp-k8s-desired-path-change-chain.yaml
git diff --check
```
Live:
```text
swblock run testops/scenarios/nvme-tcp-k8s-desired-path-change-chain.yaml
run=20260704-143757-a76e
result=PASS 31/31
```
Key evidence:
```text
phase132_nvme_k8s_desired_path_change_status=ok
initial_path_count=2
old_desired_path=192.168.1.181:4420
new_desired_path=192.168.1.181:4520
desired_path_set_changed=true
reconnect_owner=csi-node
reconnect_invoked=true
new_desired_path_connected=true
pod_uid_preserved=true
mounted_io_after_reconnect=ok
crd_status_agrees=true
report_dashboard_agree=true
cleanup_status=ok
```
## Finding
The live run found that the old host path remains connected after the desired
path set changes:
```text
stale_old_host_path_after_desired_change=true
host_path_count_after_desired_change=3
```
That is outside Phase 132's claim, but it is the next correctness gap. The CSI
owner should eventually prune mounted NVMe paths for the same NQN that are not
in the current desired path set, using scoped disconnects only.
## Closed Boundary
Phase 132 proves live Kubernetes NVMe desired path-set convergence:
```text
desired path set changes
-> CSI-node owner sees fresh control-plane evidence
-> new desired path connects
-> mounted pod UID is preserved
-> mounted I/O works
-> CRD/report/dashboard agree
```
Non-claims:
- no stale path pruning yet;
- no `nvme disconnect-all` proof;
- no NVMe/RDMA/RoCE;
- no performance/SLO claim;
- no production HA claim.
## Next
Phase 133 should close the stale-path cleanup gap: when desired NVMe addrs
change, the CSI-node owner should disconnect only stale paths for the same NQN
that are no longer desired, while preserving mounted I/O and avoiding
`disconnect-all`.
@@ -390,9 +390,13 @@ rebuild, delete safety, or cleanup must start as a separate gated phase.
A mounted RF=2 NVMe/TCP PVC starts with two host paths, one path is removed
with scoped `nvme disconnect -d`, CSI-node reconnects it, mounted I/O remains
correct, and CRD/report/dashboard agree.
- Phase 132 is active for the remaining desired path-set replacement/failover
gate. Durable backend batching is deferred until mounted-PVC reconnect is
proven for changed publish evidence, not just host-path reconnect.
- Phase 132 is closed for live Kubernetes NVMe desired path-set replacement.
A mounted RF=2 NVMe/TCP PVC starts with two desired paths, one generated
frontend address is replaced, `SwBlockVolume.status.nvme.nvmeAddrs` changes
old-to-new, CSI-node connects the new desired path, mounted I/O remains
correct, and CRD/report/dashboard agree. The run also exposed that the old
host path remains connected, so Phase 133 owns scoped stale-path pruning
before returning to durable backend batching.
- Later protocol candidates: complete a real NVMe/RDMA target, characterize
NVMe/TCP performance, or bridge to object/NIXL acceleration where the product
surface is object/storage rather than block PVC. Keep these separate so
@@ -998,8 +1002,8 @@ Approximate engineering effort if scope remains tight:
- Phase 129 is closed for the mounted NVMe restage primitive.
- Phase 130 is closed for the CSI-node NVMe reconnect owner/trigger contract.
- Phase 131 is closed for the live Kubernetes NVMe host-path reconnect gate.
- Phase 132 is active for the Kubernetes NVMe desired path-set change close
gate.
- Phase 132 is closed for the Kubernetes NVMe desired path-set change close
gate. Phase 133 owns stale host-path pruning after replacement.
- Phase 41-44 are the Operation Layer v0.5 release train: lifecycle-owner
foundation, real API/admission proof, first bounded finalizer mutation, and
delete lifecycle close gate.
@@ -0,0 +1,105 @@
# Phase 132 QA Sign-off: Kubernetes NVMe Desired Path-Set Change Close Gate
Verdict: PASS.
Runner:
```text
swblock run testops/scenarios/nvme-tcp-k8s-desired-path-change-chain.yaml
run=20260704-143757-a76e
result=PASS 31/31
```
## Gate Result
| Check | Result |
|---|---|
| RF=2 NVMe/TCP PVC starts with two desired paths | PASS |
| Mounted pod exists before path change | PASS |
| One blockvolume frontend path is replaced with a different reachable address | PASS |
| `SwBlockVolume.status.nvme.nvmeAddrs` changes from old to new | PASS |
| CSI-node reconnect owner observes the new desired path | PASS |
| Host connects the new desired path | PASS |
| Mounted pod UID is preserved | PASS |
| Mounted I/O after reconnect succeeds | PASS |
| CRD/report/dashboard agree | PASS |
| Cleanup verifier reports zero residue | PASS |
## Terminal Evidence
```text
phase132_nvme_k8s_desired_path_change_status=ok
reconnect_owner_enabled=true
reconnect_owner_interval=5s
stage2_multipath_enabled=true
mounted_pod_uid_before=fe461dee-c11c-4c20-add4-9b456867e3a8
volume_id=pvc-20228828-11d7-4c8e-9fda-8475b7151ab7
nvme_nqn=nqn.2026-05.io.seaweedfs:pvc-20228828-11d7-4c8e-9fda-8475b7151ab7
initial_path_count=2
initial_desired_paths=192.168.1.181:4420,192.168.1.184:4420
target_deployment=default/sw-blockvolume-pvc-20228828-11d7-4c8e-9fda-8475b7151ab7-r1
target_replica=r1
old_desired_path=192.168.1.181:4420
new_desired_path=192.168.1.181:4520
desired_path_set_changed=true
path_loss_or_replacement_detected=true
reconnect_owner=csi-node
reconnect_invoked=true
new_desired_path_connected=true
host_path_count_after_desired_change=3
host_paths_after_desired_change=192.168.1.181:4520,192.168.1.181:4420,192.168.1.184:4420
stale_old_host_path_after_desired_change=true
pod_uid_preserved=true
mounted_io_after_reconnect=ok
crd_status_agrees=true
report_dashboard_agree=true
surface_ready_reason=first_volume_verified
cleanup_status=ok
failure_count=0
```
The CSI-node log confirms the owner, not pod restage, connected the new desired
path:
```text
NodeStageVolume: pvc-20228828-11d7-4c8e-9fda-8475b7151ab7 reconciled mounted NVMe paths portals=192.168.1.184:4420,192.168.1.181:4520 target=nqn.2026-05.io.seaweedfs:pvc-20228828-11d7-4c8e-9fda-8475b7151ab7
MountedNVMeReconnectOwner: iteration checked=1 reconnected=1 failed=0
```
The report surface agrees with the new desired path set:
```text
managed_volume_nvme=pvc-20228828-11d7-4c8e-9fda-8475b7151ab7 nqn=nqn.2026-05.io.seaweedfs:pvc-20228828-11d7-4c8e-9fda-8475b7151ab7 nsid=1 addr=192.168.1.181:4520 addrs=192.168.1.181:4520,192.168.1.184:4420 path_count=2 multipath_observed=true reason=-
```
Cleanup verifier:
```text
cleanup_status=ok
k8s_residue_count=0
iscsi_residue_count=0
process_residue_count=0
multipath_residue_count=0
hostpath_residue_count=0
failure_count=0
```
## Finding
Non-blocking for Phase 132: the host still had the old path connected after the
desired set changed:
```text
stale_old_host_path_after_desired_change=true
host_path_count_after_desired_change=3
```
Phase 132 only claims that the new desired path is connected from changed
control-plane evidence while mounted I/O continues. It does not claim stale
host-path pruning. The next NVMe correctness phase should add scoped pruning of
NVMe paths for the same NQN that are no longer in the desired path set.
## Boundary
This gate does not use `nvme disconnect-all` as proof. It does not claim
NVMe/RDMA, RoCE, performance, production HA, or SLO behavior.
@@ -19,6 +19,7 @@ RECONNECT_OWNER="${SW_BLOCK_NVME_RECONNECT_OWNER:-0}"
RECONNECT_INTERVAL="${SW_BLOCK_NVME_RECONNECT_INTERVAL:-5s}"
HOST_PATH_DISCONNECT="${SW_BLOCK_NVME_HOST_PATH_DISCONNECT:-0}"
FORCE_STAGE2_MULTIPATH="${SW_BLOCK_NVME_FORCE_STAGE2_MULTIPATH:-0}"
DESIRED_PATH_CHANGE="${SW_BLOCK_NVME_DESIRED_PATH_CHANGE:-0}"
mkdir -p "${ARTIFACT_DIR}"/{bin,build,values,install,multi-volume,inject,surfaces,cleanup}
: >"${SUMMARY}"
@@ -235,6 +236,7 @@ for sub in walk(doc):
paths.extend(sub.get("Paths") or [])
print(f"path_count={len(paths)}")
print("addrs=" + ",".join(a for a in [addr(p.get("Address")) for p in paths] if a))
if paths:
first = paths[0]
name = first.get("Name") or first.get("Controller") or first.get("Device") or ""
@@ -268,6 +270,28 @@ wait_for_host_nvme_path_count() {
return 1
}
wait_for_host_nvme_addr() {
local label="$1"
local nqn="$2"
local want_addr="$3"
for _ in $(seq 1 90); do
write_host_nvme_path_info "${label}" "${nqn}" || true
local addrs
addrs="$(read_env_value "${ARTIFACT_DIR}/inject/nvme-path-info.${label}.env" addrs)"
if python3 - "${addrs}" "${want_addr}" <<'PY'
import sys
addrs = [a for a in sys.argv[1].split(",") if a]
raise SystemExit(0 if sys.argv[2] in addrs else 1)
PY
then
return 0
fi
sleep 1
done
echo "NVMe host path ${want_addr} did not appear for ${nqn}" >&2
return 1
}
wait_for_reconnect_owner_log() {
local out="$1"
for _ in $(seq 1 90); do
@@ -281,6 +305,19 @@ wait_for_reconnect_owner_log() {
return 1
}
wait_for_reconnect_owner_log_for_addr() {
local out="$1"
local addr="$2"
for _ in $(seq 1 90); do
kubectl -n "${HELM_NAMESPACE}" logs -l app=sw-block-csi-node -c block-csi --since=10m --prefix=true >"${out}" 2>&1 || true
if grep -q 'reconciled mounted NVMe paths' "${out}" && grep -Fq "${addr}" "${out}"; then
return 0
fi
sleep 1
done
return 1
}
volume_field_from_crd() {
local path="$1"
local expr="$2"
@@ -296,6 +333,42 @@ print(value if isinstance(value, (str, int, float, bool)) else "")
PY
}
wait_for_crd_nvme_addr_set_changed() {
local phase="$1"
local old_addr="$2"
local new_addr="$3"
local out_json="${ARTIFACT_DIR}/surfaces/swblockvolumes.${phase}.json"
for _ in $(seq 1 120); do
kubectl -n "${HELM_NAMESPACE}" get swblockvolumes -o json >"${out_json}" 2>/dev/null || true
python3 - "${out_json}" "${old_addr}" "${new_addr}" <<'PY' && return 0 || true
import json
import sys
path, old_addr, new_addr = sys.argv[1:]
try:
doc = json.load(open(path))
except Exception:
raise SystemExit(1)
items = doc.get("items") or []
if len(items) != 1:
raise SystemExit(1)
st = items[0].get("status") or {}
nv = st.get("nvme") or {}
addrs = nv.get("nvmeAddrs") or []
if st.get("status") != "ready" or st.get("reasonCode") != "first_volume_verified":
raise SystemExit(1)
if nv.get("pathCount") != 2:
raise SystemExit(1)
if new_addr not in addrs or old_addr in addrs:
raise SystemExit(1)
PY
sleep 2
done
echo "SwBlockVolume desired NVMe path set did not replace ${old_addr} with ${new_addr}" >&2
kubectl -n "${HELM_NAMESPACE}" get swblockvolumes -o yaml >&2 || true
return 1
}
write_summary "${PHASE_STATUS_KEY}=running"
cleanup
@@ -409,6 +482,233 @@ YAML
write_summary "mounted_pod_uid_before=${MOUNTED_POD_UID_BEFORE}"
fi
if [[ "${DESIRED_PATH_CHANGE}" == "1" || "${DESIRED_PATH_CHANGE}" == "true" ]]; then
echo "[phase111] replace one desired NVMe frontend path and wait for mounted reconnect"
kubectl -n "${APP_NAMESPACE}" get deploy -l app=sw-blockvolume -o json >"${ARTIFACT_DIR}/inject/blockvolume-deployments.before-desired-change.json"
python3 - "${ARTIFACT_DIR}" <<'PY' >"${ARTIFACT_DIR}/inject/desired-path-change.env"
import json
import sys
from pathlib import Path
base = Path(sys.argv[1])
crd = json.load(open(base/"surfaces/swblockvolumes.healthy.json"))
deploys = json.load(open(base/"inject/blockvolume-deployments.before-desired-change.json"))
items = crd.get("items") or []
if len(items) != 1:
raise SystemExit(f"need one SwBlockVolume, got {len(items)}")
st = items[0].get("status") or {}
nv = st.get("nvme") or {}
desired = nv.get("nvmeAddrs") or []
if len(desired) != 2:
raise SystemExit(f"need two desired NVMe paths, got {desired}")
primary = st.get("primaryReplicaID") or ""
volume_id = st.get("volumeID") or ""
nqn = nv.get("nqn") or ""
if not volume_id or not nqn:
raise SystemExit(f"missing volume_id/nqn in status: {st}")
current_addrs = set(desired)
candidates = []
for item in deploys.get("items") or []:
meta = item.get("metadata") or {}
labels = meta.get("labels") or {}
replica = labels.get("sw-block.seaweedfs.com/replica") or ""
namespace = meta.get("namespace") or "default"
name = meta.get("name") or ""
containers = ((item.get("spec") or {}).get("template") or {}).get("spec", {}).get("containers") or []
for ci, container in enumerate(containers):
if container.get("name") != "blockvolume":
continue
for ai, arg in enumerate(container.get("args") or []):
if not str(arg).startswith("--nvme-listen="):
continue
old_addr = str(arg).split("=", 1)[1]
if old_addr in current_addrs:
candidates.append((replica == primary, replica, namespace, name, ci, ai, old_addr))
if not candidates:
raise SystemExit(f"no deployment --nvme-listen matched desired addrs {desired}")
candidates.sort(key=lambda x: (x[0], x[1], x[3]))
_, replica, namespace, name, ci, ai, old_addr = candidates[0]
host, port_text = old_addr.rsplit(":", 1)
port = int(port_text)
used = {int(a.rsplit(":", 1)[1]) for a in current_addrs if a.startswith(host + ":")}
new_port = None
for offset in (100, 101, 102, 103, 104, 105, 200):
candidate = port + offset
if candidate not in used and candidate < 65535:
new_port = candidate
break
if new_port is None:
raise SystemExit(f"no replacement port for {old_addr}")
new_addr = f"{host}:{new_port}"
patch = [{"op": "replace", "path": f"/spec/template/spec/containers/{ci}/args/{ai}", "value": "--nvme-listen=" + new_addr}]
(base/"inject/desired-path-change-patch.json").write_text(json.dumps(patch))
for key, value in {
"volume_id": volume_id,
"nvme_nqn": nqn,
"target_namespace": namespace,
"target_deployment": name,
"target_replica": replica,
"old_desired_path": old_addr,
"new_desired_path": new_addr,
"initial_desired_paths": ",".join(desired),
"initial_path_count": str(len(desired)),
}.items():
print(f"{key}={value}")
PY
TARGET_NAMESPACE="$(read_env_value "${ARTIFACT_DIR}/inject/desired-path-change.env" target_namespace)"
TARGET_DEPLOY="$(read_env_value "${ARTIFACT_DIR}/inject/desired-path-change.env" target_deployment)"
VOLUME_ID="$(read_env_value "${ARTIFACT_DIR}/inject/desired-path-change.env" volume_id)"
NQN="$(read_env_value "${ARTIFACT_DIR}/inject/desired-path-change.env" nvme_nqn)"
OLD_DESIRED_PATH="$(read_env_value "${ARTIFACT_DIR}/inject/desired-path-change.env" old_desired_path)"
NEW_DESIRED_PATH="$(read_env_value "${ARTIFACT_DIR}/inject/desired-path-change.env" new_desired_path)"
INITIAL_PATH_COUNT="$(read_env_value "${ARTIFACT_DIR}/inject/desired-path-change.env" initial_path_count)"
INITIAL_DESIRED_PATHS="$(read_env_value "${ARTIFACT_DIR}/inject/desired-path-change.env" initial_desired_paths)"
TARGET_REPLICA="$(read_env_value "${ARTIFACT_DIR}/inject/desired-path-change.env" target_replica)"
write_summary "volume_id=${VOLUME_ID}"
write_summary "nvme_nqn=${NQN}"
write_summary "initial_path_count=${INITIAL_PATH_COUNT}"
write_summary "initial_desired_paths=${INITIAL_DESIRED_PATHS}"
write_summary "target_deployment=${TARGET_NAMESPACE}/${TARGET_DEPLOY}"
write_summary "target_replica=${TARGET_REPLICA}"
write_summary "old_desired_path=${OLD_DESIRED_PATH}"
write_summary "new_desired_path=${NEW_DESIRED_PATH}"
kubectl -n "${TARGET_NAMESPACE}" patch "deploy/${TARGET_DEPLOY}" --type=json --patch-file "${ARTIFACT_DIR}/inject/desired-path-change-patch.json" \
>"${ARTIFACT_DIR}/inject/patch-desired-path.txt" 2>&1
kubectl -n "${TARGET_NAMESPACE}" rollout status "deploy/${TARGET_DEPLOY}" --timeout=240s \
>"${ARTIFACT_DIR}/inject/rollout-desired-path-change.txt" 2>&1
kubectl -n "${TARGET_NAMESPACE}" get deploy,pod -l app=sw-blockvolume -o wide >"${ARTIFACT_DIR}/inject/blockvolume.after-desired-change.txt"
wait_for_crd_nvme_addr_set_changed "desired-change" "${OLD_DESIRED_PATH}" "${NEW_DESIRED_PATH}"
write_summary "desired_path_set_changed=true"
write_summary "path_loss_or_replacement_detected=true"
write_summary "reconnect_owner=csi-node"
if ! wait_for_reconnect_owner_log_for_addr "${ARTIFACT_DIR}/inject/csi-node-desired-path-change-owner.log" "${NEW_DESIRED_PATH}"; then
echo "CSI-node reconnect owner did not report new desired path ${NEW_DESIRED_PATH}" >&2
exit 1
fi
wait_for_host_nvme_addr "after-desired-path-change" "${NQN}" "${NEW_DESIRED_PATH}"
write_summary "reconnect_invoked=true"
write_summary "new_desired_path_connected=true"
HOST_PATH_COUNT_AFTER_DESIRED_CHANGE="$(read_env_value "${ARTIFACT_DIR}/inject/nvme-path-info.after-desired-path-change.env" path_count)"
HOST_PATHS_AFTER_DESIRED_CHANGE="$(read_env_value "${ARTIFACT_DIR}/inject/nvme-path-info.after-desired-path-change.env" addrs)"
write_summary "host_path_count_after_desired_change=${HOST_PATH_COUNT_AFTER_DESIRED_CHANGE}"
write_summary "host_paths_after_desired_change=${HOST_PATHS_AFTER_DESIRED_CHANGE}"
if python3 - "${HOST_PATHS_AFTER_DESIRED_CHANGE}" "${OLD_DESIRED_PATH}" <<'PY'
import sys
addrs = [a for a in sys.argv[1].split(",") if a]
raise SystemExit(0 if sys.argv[2] in addrs else 1)
PY
then
write_summary "stale_old_host_path_after_desired_change=true"
else
write_summary "stale_old_host_path_after_desired_change=false"
fi
if [[ "${MOUNTED_IO}" == "1" || "${MOUNTED_IO}" == "true" ]]; then
MOUNTED_POD_UID_CHANGED="$(kubectl -n "${APP_NAMESPACE}" get pod "${MOUNTED_POD}" -o jsonpath='{.metadata.uid}')"
if [[ "${MOUNTED_POD_UID_CHANGED}" != "${MOUNTED_POD_UID_BEFORE}" ]]; then
echo "mounted pod UID changed after desired path replacement: before=${MOUNTED_POD_UID_BEFORE} changed=${MOUNTED_POD_UID_CHANGED}" >&2
exit 1
fi
kubectl -n "${APP_NAMESPACE}" exec "${MOUNTED_POD}" -- sh -c 'set -eu; echo after-desired-path-change >> /data/phase132-mounted.txt; sync; grep after-desired-path-change /data/phase132-mounted.txt' >"${ARTIFACT_DIR}/inject/mounted-after-desired-path-change.log"
write_summary "pod_uid_preserved=true"
write_summary "mounted_io_after_reconnect=ok"
fi
with_master_port_forward "${ARTIFACT_DIR}/surfaces/desired-change-blockmaster-port-forward.log" \
"${ARTIFACT_DIR}/bin/sw-block" ops report \
--master-api "127.0.0.1:${STATUS_PORT}" \
--namespace "${APP_NAMESPACE}" \
--out "${ARTIFACT_DIR}/surfaces/desired-change-report" \
--timeout 30s >"${ARTIFACT_DIR}/surfaces/desired-change-report.stdout.txt" 2>"${ARTIFACT_DIR}/surfaces/desired-change-report.stderr.txt"
DASHBOARD_PORT="$(python3 - <<'PY'
import socket
s=socket.socket(); s.bind(("127.0.0.1",0)); print(s.getsockname()[1]); s.close()
PY
)"
"${ARTIFACT_DIR}/bin/sw-block" ops dashboard \
--from-bundle "${ARTIFACT_DIR}/surfaces/desired-change-report" \
--listen "127.0.0.1:${DASHBOARD_PORT}" >"${ARTIFACT_DIR}/surfaces/desired-change-dashboard.stdout.txt" 2>"${ARTIFACT_DIR}/surfaces/desired-change-dashboard.stderr.txt" &
DASH_PID=$!
for _ in $(seq 1 50); do
code="$(curl -s -o "${ARTIFACT_DIR}/surfaces/desired-change-dashboard-operator-snapshot.json" -w '%{http_code}' "http://127.0.0.1:${DASHBOARD_PORT}/operator-snapshot.json" || true)"
[[ "${code}" == "200" ]] && break
sleep 0.2
done
kill "${DASH_PID}" >/dev/null 2>&1 || true
wait "${DASH_PID}" >/dev/null 2>&1 || true
python3 - "${ARTIFACT_DIR}" "${VOLUME_ID}" "${OLD_DESIRED_PATH}" "${NEW_DESIRED_PATH}" <<'PY'
import json
import sys
from pathlib import Path
base = Path(sys.argv[1])
volume_id, old_addr, new_addr = sys.argv[2:]
crd = json.load(open(base/"surfaces/swblockvolumes.desired-change.json"))
status = crd["items"][0]["status"]
nvme = status.get("nvme") or {}
summary = (base/"surfaces/desired-change-report/summary.txt").read_text()
snapshot = json.load(open(base/"surfaces/desired-change-report/operator-snapshot.json"))
dashboard = json.load(open(base/"surfaces/desired-change-dashboard-operator-snapshot.json"))
def assert_status(name, st):
nv = st.get("nvme") or {}
addrs = nv.get("nvme_addrs") or nv.get("nvmeAddrs") or []
if st.get("status") != "ready" or (st.get("reason_code") or st.get("reasonCode")) != "first_volume_verified":
raise SystemExit(f"{name} status mismatch: {st}")
if nv.get("path_count") != 2 and nv.get("pathCount") != 2:
raise SystemExit(f"{name} path count mismatch: {nv}")
if new_addr not in addrs or old_addr in addrs:
raise SystemExit(f"{name} desired addrs mismatch: {addrs}")
if status.get("status") != "ready" or status.get("reasonCode") != "first_volume_verified":
raise SystemExit(f"CRD status mismatch: {status}")
if nvme.get("pathCount") != 2:
raise SystemExit(f"CRD path count mismatch: {nvme}")
if new_addr not in (nvme.get("nvmeAddrs") or []) or old_addr in (nvme.get("nvmeAddrs") or []):
raise SystemExit(f"CRD desired addrs mismatch: {nvme}")
if f"managed_volume={volume_id} status=ready reason=first_volume_verified" not in summary:
raise SystemExit("report missing ready/first_volume_verified")
nvme_lines = [line for line in summary.splitlines() if line.startswith(f"managed_volume_nvme={volume_id} ")]
if len(nvme_lines) != 1:
raise SystemExit("report missing managed_volume_nvme line")
if new_addr not in nvme_lines[0] or old_addr in nvme_lines[0] or "path_count=2" not in nvme_lines[0]:
raise SystemExit("report did not reflect desired path replacement")
for name, doc in (("operator_snapshot", snapshot), ("dashboard", dashboard)):
vols = doc.get("volumes") or []
if len(vols) != 1:
raise SystemExit(f"{name} volume count={len(vols)}")
assert_status(name, vols[0].get("status") or {})
(base/"nvme-k8s-desired-path-change-asserts.txt").write_text("\n".join([
"crd_status_agrees=true",
"report_dashboard_agree=true",
"surface_ready_reason=first_volume_verified",
]) + "\n")
PY
cat "${ARTIFACT_DIR}/nvme-k8s-desired-path-change-asserts.txt" >>"${SUMMARY}"
write_summary "${PHASE_STATUS_KEY}=ok"
cleanup
verify_rc=0
(
cd "${ROOT}"
SW_BLOCK_CLEANUP_WAIT_SECONDS=180 \
SW_BLOCK_ARTIFACT_DIR="${ARTIFACT_DIR}/cleanup/verify" bash scripts/verify-helm-cleanup.sh "${ROOT}" \
>"${ARTIFACT_DIR}/cleanup/verify.stdout.txt" 2>"${ARTIFACT_DIR}/cleanup/verify.stderr.txt"
) || verify_rc=$?
cat "${ARTIFACT_DIR}/cleanup/verify/cleanup-summary.txt" >>"${SUMMARY}"
grep -q '^cleanup_status=ok$' "${ARTIFACT_DIR}/cleanup/verify/cleanup-summary.txt"
if [[ "${verify_rc}" -ne 0 ]]; then
exit "${verify_rc}"
fi
echo "[phase111] PASS"
exit 0
fi
if [[ "${HOST_PATH_DISCONNECT}" == "1" || "${HOST_PATH_DISCONNECT}" == "true" ]]; then
echo "[phase111] disconnect one host NVMe path and wait for CSI-node reconnect owner"
VOLUME_ID="$(volume_field_from_crd "${ARTIFACT_DIR}/surfaces/swblockvolumes.healthy.json" "status.volumeID")"
@@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT="${1:-$(pwd)}"
export SW_BLOCK_NVME_PATH_LOSS_PHASE_STATUS_KEY="phase132_nvme_k8s_desired_path_change_status"
export SW_BLOCK_NVME_PATH_LOSS_SUMMARY_NAME="phase132-nvme-k8s-desired-path-change-summary.txt"
export SW_BLOCK_NVME_MOUNTED_IO="1"
export SW_BLOCK_NVME_MOUNTED_POD="${SW_BLOCK_NVME_MOUNTED_POD:-sw-block-phase132-mounted}"
export SW_BLOCK_NVME_RECONNECT_OWNER="1"
export SW_BLOCK_NVME_RECONNECT_INTERVAL="${SW_BLOCK_NVME_RECONNECT_INTERVAL:-5s}"
export SW_BLOCK_NVME_FORCE_STAGE2_MULTIPATH="1"
export SW_BLOCK_NVME_DESIRED_PATH_CHANGE="1"
exec bash "${ROOT}/scripts/run-phase111-nvme-k8s-path-loss-crd-gate.sh" "${ROOT}"
@@ -0,0 +1,162 @@
name: nvme-tcp-k8s-desired-path-change-chain
timeout: 60m
env:
product_root: "/tmp/seaweed_block"
ssh_key: "C:\\work\\dev_server\\testdev_key"
topology:
nodes:
m02:
host: 192.168.1.184
user: testdev
key: "{{ ssh_key }}"
phases:
- name: pre_clean
actions:
- action: pre_run_cleanup
node: m02
kill_patterns: "blockmaster,blockvolume,blockcsi,iscsi-target"
nvme_disconnect: "true"
iscsi_logout_prefix: "iqn.2026-05.io.seaweedfs"
- action: exec
node: m02
timeout: 5m
cmd: "helm status sw-block --namespace kube-system >/dev/null 2>&1 && helm uninstall sw-block --namespace kube-system --wait --timeout 240s || true; kubectl -n default delete pod sw-block-phase132-mounted --ignore-not-found=true --wait=true --timeout=120s || true; kubectl -n default delete pod -l sw-block-test=multi-volume --ignore-not-found=true --wait=true --timeout=120s || true; kubectl -n default delete pod sw-block-multi-reader-1 sw-block-multi-writer-1 --ignore-not-found=true --wait=true --timeout=120s || true; kubectl -n default delete pvc sw-block-multi-pvc-1 --ignore-not-found=true --wait=true --timeout=120s || true; kubectl delete storageclass sw-block-multi --ignore-not-found=true --wait=true --timeout=120s || true; kubectl -n default delete deploy -l app=sw-blockvolume --ignore-not-found=true --wait=false || true; kubectl -n kube-system delete deploy -l app=sw-blockvolume --ignore-not-found=true --wait=false || true; kubectl -n kube-system get swblockvolumes.block.seaweedfs.com -o name 2>/dev/null | xargs -r -n1 kubectl -n kube-system patch --type=merge -p '{\"metadata\":{\"finalizers\":[]}}' >/dev/null 2>&1 || true; kubectl -n kube-system delete swblockvolumes.block.seaweedfs.com --all --ignore-not-found=true --wait=true --timeout=60s || true; kubectl -n kube-system delete swblockclusters.block.seaweedfs.com --all --ignore-not-found=true --wait=true --timeout=60s || true; kubectl delete validatingadmissionpolicy,validatingadmissionpolicybinding -l app.kubernetes.io/instance=sw-block --ignore-not-found=true >/dev/null 2>&1 || true; kubectl delete crd swblockclusters.block.seaweedfs.com swblockvolumes.block.seaweedfs.com swblockreplicaeligibilities.block.seaweedfs.com swblockreplicarebuilds.block.seaweedfs.com swblockreplicafailbacks.block.seaweedfs.com swblockfrontendpublications.block.seaweedfs.com --ignore-not-found=true --wait=true --timeout=60s >/dev/null 2>&1 || true; kubectl get pv --no-headers 2>/dev/null | awk '/sw-block-multi/ {print $1}' | xargs -r -n1 kubectl patch pv --type=merge -p '{\"metadata\":{\"finalizers\":[]}}' >/dev/null 2>&1 || true; kubectl get pv --no-headers 2>/dev/null | awk '/sw-block-multi/ {print $1}' | xargs -r kubectl delete pv --wait=false >/dev/null 2>&1 || true; sudo -n nvme disconnect-all >/dev/null 2>&1 || true; rm -rf /mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase132-nvme-desired-path-change && mkdir -p /mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase132-nvme-desired-path-change/build /mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase132-nvme-desired-path-change/gate"
env.KUBECONFIG: "/etc/rancher/k3s/k3s.yaml"
- name: build_and_import_images
actions:
- action: exec
node: m02
timeout: 10m
cmd: "cd {{ product_root }} && bash scripts/build-alpha-images.sh {{ product_root }}"
env.SW_BLOCK_IMPORT_K3S: "1"
env.SW_BLOCK_IMPORT_K3S_NODES: "192.168.1.181"
env.SW_BLOCK_IMPORT_K3S_SSH_USER: "testdev"
env.SW_BLOCK_IMPORT_K3S_SSH_KEY: "{{ ssh_key }}"
env.SW_BLOCK_DOCKER_NO_CACHE: "1"
env.SW_BLOCK_ARTIFACT_DIR: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase132-nvme-desired-path-change/build"
- action: grep_log
node: m02
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase132-nvme-desired-path-change/build/alpha-images.env"
pattern: "SW_BLOCK_IMAGE_ID="
save_as: image_id_count
- action: assert_greater
actual: "{{ image_id_count }}"
threshold: "0"
- name: run_phase132_gate
actions:
- action: exec
node: m02
timeout: 45m
cmd: "cd {{ product_root }} && bash scripts/run-phase132-nvme-k8s-desired-path-change-gate.sh {{ product_root }}"
env.KUBECONFIG: "/etc/rancher/k3s/k3s.yaml"
env.SW_BLOCK_ARTIFACT_DIR: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase132-nvme-desired-path-change/gate"
- action: grep_log
node: m02
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase132-nvme-desired-path-change/gate/phase132-nvme-k8s-desired-path-change-summary.txt"
pattern: "^phase132_nvme_k8s_desired_path_change_status=ok$"
save_as: gate_ok
- action: assert_greater
actual: "{{ gate_ok }}"
threshold: "0"
- action: grep_log
node: m02
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase132-nvme-desired-path-change/gate/phase132-nvme-k8s-desired-path-change-summary.txt"
pattern: "^initial_path_count=2$"
save_as: initial_two
- action: assert_greater
actual: "{{ initial_two }}"
threshold: "0"
- action: grep_log
node: m02
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase132-nvme-desired-path-change/gate/phase132-nvme-k8s-desired-path-change-summary.txt"
pattern: "^desired_path_set_changed=true$"
save_as: desired_changed
- action: assert_greater
actual: "{{ desired_changed }}"
threshold: "0"
- action: grep_log
node: m02
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase132-nvme-desired-path-change/gate/phase132-nvme-k8s-desired-path-change-summary.txt"
pattern: "^path_loss_or_replacement_detected=true$"
save_as: replacement_detected
- action: assert_greater
actual: "{{ replacement_detected }}"
threshold: "0"
- action: grep_log
node: m02
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase132-nvme-desired-path-change/gate/phase132-nvme-k8s-desired-path-change-summary.txt"
pattern: "^reconnect_owner=csi-node$"
save_as: owner
- action: assert_greater
actual: "{{ owner }}"
threshold: "0"
- action: grep_log
node: m02
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase132-nvme-desired-path-change/gate/phase132-nvme-k8s-desired-path-change-summary.txt"
pattern: "^reconnect_invoked=true$"
save_as: reconnect_invoked
- action: assert_greater
actual: "{{ reconnect_invoked }}"
threshold: "0"
- action: grep_log
node: m02
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase132-nvme-desired-path-change/gate/phase132-nvme-k8s-desired-path-change-summary.txt"
pattern: "^new_desired_path_connected=true$"
save_as: new_path_connected
- action: assert_greater
actual: "{{ new_path_connected }}"
threshold: "0"
- action: grep_log
node: m02
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase132-nvme-desired-path-change/gate/phase132-nvme-k8s-desired-path-change-summary.txt"
pattern: "^pod_uid_preserved=true$"
save_as: uid_preserved
- action: assert_greater
actual: "{{ uid_preserved }}"
threshold: "0"
- action: grep_log
node: m02
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase132-nvme-desired-path-change/gate/phase132-nvme-k8s-desired-path-change-summary.txt"
pattern: "^mounted_io_after_reconnect=ok$"
save_as: io_ok
- action: assert_greater
actual: "{{ io_ok }}"
threshold: "0"
- action: grep_log
node: m02
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase132-nvme-desired-path-change/gate/phase132-nvme-k8s-desired-path-change-summary.txt"
pattern: "^crd_status_agrees=true$"
save_as: crd_agrees
- action: assert_greater
actual: "{{ crd_agrees }}"
threshold: "0"
- action: grep_log
node: m02
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase132-nvme-desired-path-change/gate/phase132-nvme-k8s-desired-path-change-summary.txt"
pattern: "^report_dashboard_agree=true$"
save_as: report_dashboard_agree
- action: assert_greater
actual: "{{ report_dashboard_agree }}"
threshold: "0"
- action: grep_log
node: m02
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase132-nvme-desired-path-change/gate/phase132-nvme-k8s-desired-path-change-summary.txt"
pattern: "^cleanup_status=ok$"
save_as: cleanup_ok
- action: assert_greater
actual: "{{ cleanup_ok }}"
threshold: "0"
- name: collect
always: true
actions:
- action: collect_path
node: m02
path: "/mnt/smb/work/share/g15d-k8s/{{ run_id }}-phase132-nvme-desired-path-change"
name: "remote-phases"
ignore_error: true