test(k8s): add csi node restart lifecycle scenario

This commit is contained in:
pingqiu committed 2026-05-05 13:41:20 -07:00
1 parent ccc06f4f94
commit 66bbbb0c1f
10 files changed
+316 -19

No files matched your search

@@ -144,6 +144,26 @@ func TestApplyAlphaBlockvolumes_WaitsForGeneratedManifestInsteadOfKubeSystem(t *
}
}
func TestAlphaAppDemo_CanRestartCSINodeBeforeReader(t *testing.T) {
body := g15dReadFile(t, "scripts", "run-alpha-app-demo.sh")
for _, want := range []string{
"SW_BLOCK_RESTART_CSI_NODE_BEFORE_READER",
"SW_BLOCK_DEMO_APP_MANIFEST",
"rollout restart ds/sw-block-csi-node",
"restart-csi-node-status.log",
"wait_pod_log_contains sw-block-demo-writer",
} {
if !strings.Contains(body, want) {
t.Fatalf("app demo script missing %q", want)
}
}
wrapper := g15dReadFile(t, "scripts", "run-k8s-csi-node-restart.sh")
if !strings.Contains(wrapper, "demo-app-pvc-writer-hold.yaml") {
t.Fatalf("restart wrapper must use mounted-writer manifest:\n%s", wrapper)
}
}
func g15dReadFile(t *testing.T, parts ...string) string {
t.Helper()
root := g15bRepoRoot(t)
@@ -0,0 +1,63 @@
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: sw-block-dynamic
provisioner: block.csi.seaweedfs.com
volumeBindingMode: Immediate
allowVolumeExpansion: false
parameters:
replicationFactor: "1"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: sw-block-demo-pvc
namespace: default
spec:
accessModes:
- ReadWriteOnce
storageClassName: sw-block-dynamic
resources:
requests:
storage: 1Mi
---
apiVersion: v1
kind: Pod
metadata:
name: sw-block-demo-writer
namespace: default
spec:
restartPolicy: Never
securityContext:
seccompProfile:
type: RuntimeDefault
containers:
- name: app
image: busybox:1.36
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
seccompProfile:
type: RuntimeDefault
command:
- /bin/sh
- -c
- |
set -eu
echo "[app-writer] writing through PVC mounted at /data"
dd if=/dev/urandom of=/data/demo.bin bs=4096 count=1
sha256sum /data/demo.bin > /data/demo.sha256
sync
sha256sum -c /data/demo.sha256
echo "[app-writer] wrote and verified /data/demo.bin"
echo "[app-writer] holding pod so CSI node restart happens while PVC is mounted"
sleep 3600
volumeMounts:
- name: data
mountPath: /data
volumes:
- name: data
persistentVolumeClaim:
claimName: sw-block-demo-pvc
+23 -15
View File
@@ -34,12 +34,12 @@ References:
- includes RX/TX stability tests, large write memory tests, OS smoke script,
loop mode, stress mode, TestOps registry entry, and sustained sync smoke.
- iSCSI-P2 supplemental session guards:
- status: local on `iscsi/frontend-completeness`, pending milestone PR.
- status: done in PR #41.
- includes rapid login/logout goroutine budget, concurrent target close
idempotency, target same-address restart, and NOP-Out queued during
Data-Out.
- iSCSI-P3 attach/detach loop tooling:
- status: local on `iscsi/frontend-completeness`, pending milestone PR.
- status: done in PR #41.
- includes `scripts/run-k8s-attach-detach-loop.sh` and TestOps registry
scenario `iscsi-p3-attach-detach-loop`.
- iSCSI-P2/P3 lab validation:
@@ -59,6 +59,10 @@ References:
- Owner-reference alpha default:
- status: done in PR #40.
- relevant to K8s cleanup and alpha install flow.
- iSCSI-P4 CHAP / Access Control:
- status: done in PR #41.
- includes target-side CHAP, CSI node CHAP, Kubernetes Secret wiring, and
QA evidence.
## Recently Closed Milestone: iSCSI-P2 Stability
@@ -71,8 +75,7 @@ References:
- Tasks:
- add RX/TX stability test pack:
- status: done in PR #26.
- supplemental guards: local on `iscsi/frontend-completeness`, pending
milestone PR.
- supplemental guards: done in PR #41.
- rapid login/logout without goroutine leak,
- many concurrent sessions,
- target close while I/O is active,
@@ -122,8 +125,7 @@ References:
behavior, not only protocol fakes.
- Tasks:
- status: QA green on `iscsi/frontend-completeness@e7c95ee`, pending
milestone PR.
- status: done in PR #41.
- sustained write/read through mounted filesystem,
- `SYNCHRONIZE_CACHE` pressure,
- multiple sessions sharing a volume if supported,
@@ -148,16 +150,15 @@ References:
- default loop count comes from `SW_BLOCK_ATTACH_DETACH_ITERATIONS`.
- #QA status: PASS on M02, 3 iterations.
## Current Active Milestone: iSCSI-P4 CHAP / Access Control
## Recently Closed Milestone: iSCSI-P4 CHAP / Access Control
- Goal:
- reach V2-level iSCSI auth behavior before any security-facing claim.
- Tasks:
- status: QA green on `iscsi/frontend-completeness@9a1fe07`, pending
milestone PR.
- status: done in PR #41.
- target-side CHAP login negotiation:
- status: local implementation + unit tests.
- status: done in PR #41.
- direct LoginOp is rejected when CHAP is required,
- `AuthMethod=None` is rejected when CHAP is required,
- target emits CHAP MD5 challenge,
@@ -165,7 +166,7 @@ References:
- wrong response fails closed,
- missing `CHAP_R` fails closed.
- `cmd/blockvolume` opt-in flags:
- status: local implementation + parse tests.
- status: done in PR #41.
- `--iscsi-chap-username`,
- `--iscsi-chap-secret`,
- flags require `--iscsi-listen`,
@@ -179,7 +180,7 @@ References:
- CSI node consumes CHAP credentials from `NodeStageVolumeRequest.Secrets`,
- controller publish path must not copy CHAP secrets into `publish_context`,
- node configures `iscsiadm` CHAP settings after discovery and before login.
- launcher can render target-side CHAP args from a Kubernetes Secret,
- launcher can render target-side CHAP env vars from a Kubernetes Secret,
- alpha runner can create the Secret and inject StorageClass
node-stage secret refs.
- replayed challenge rejected if supported by the protocol path,
@@ -199,13 +200,15 @@ References:
- default non-CHAP regression PASS on M02.
- V2 CHAP tests are the reference coverage inventory.
## Milestone: iSCSI-P5 CSI Node Lifecycle
## Current Active Milestone: iSCSI-P5 CSI Node Lifecycle
- Goal:
- make kubelet retry/restart behavior safe enough for real clusters.
- Tasks:
- status: active on `iscsi/frontend-completeness`.
- status: active on `iscsi/csi-node-lifecycle`.
- local CSI node lifecycle guards:
- status: done in PR #41.
- NodeStage idempotency,
- mounted staging path must belong to the same volume,
- mounted staging path for another volume fails closed.
@@ -225,6 +228,10 @@ References:
- local 3-cycle stage/unstage test leaves no staged state,
`.volume`, or `.transport`.
- wrong volume at staging path fails closed.
- #QA CSI node restart while PVC remains,
- script prepared: `scripts/run-k8s-csi-node-restart.sh`,
- TestOps scenario prepared: `iscsi-p5-csi-node-restart`,
- assignment: `internal/docs/qa-assignments/iscsi-p5-csi-node-lifecycle-validation.md`.
- Close bar:
- kubelet retries do not wedge the node plugin,
@@ -232,7 +239,8 @@ References:
- repeated create/delete works without manual host cleanup.
- QA/tooling:
- #QA needs K8s scenario scripts or TestOps entries.
- #QA needs M02 or equivalent K8s run of
`scripts/run-k8s-csi-node-restart.sh`.
- manual kubelet poking is allowed only for first reproduction.
## Milestone: iSCSI-P6 ALUA / MPIO / Mounted Failover
@@ -66,7 +66,7 @@ This is the short internal roadmap. Keep it current and readable.
- Current: OS initiator correctness, session stability, product-backed K8s
fio/attach-detach, and CHAP are implemented and evidenced.
- Next: CSI lifecycle and restart behavior.
- Next: CSI lifecycle and restart behavior under real Kubernetes.
- Later: ALUA/MPIO and mounted failover.
### Track C: Durable State
@@ -0,0 +1,69 @@
# QA Assignment: iSCSI P5 CSI Node Lifecycle Validation
Status: ready for QA.
Branch: `iscsi/csi-node-lifecycle`.
Scope: Kubernetes CSI node restart while a writer pod is holding the PVC mount,
then replacement app pod reads the same PVC.
## What This Verifies
- The app writer pod can write and verify data through a dynamic PVC.
- `sw-block-csi-node` can be restarted while the writer pod keeps the PVC
mounted.
- The writer pod can be deleted after the CSI node restart.
- A replacement reader pod can mount the same PVC and verify the existing data.
- Cleanup leaves no sw-block iSCSI sessions, PVCs, pods, or generated
blockvolume Deployment.
## Preconditions
- Linux Kubernetes lab node with k3s/kubectl, Docker, `iscsiadm`, and
loadable `iscsi_tcp`.
- Local images built from the same branch:
```bash
bash scripts/build-alpha-images.sh "$PWD"
```
## Test 1: CSI Node Restart Between Writer And Reader
```bash
RUN_ID="$(date -u +%Y%m%dT%H%M%SZ)-iscsi-p5-csi-node-restart"
SW_BLOCK_ARTIFACT_DIR="/tmp/sw-block-artifacts/$RUN_ID" \
bash scripts/run-k8s-csi-node-restart.sh "$PWD"
```
Expected:
- run log includes `restart_csi_node_before_reader=1`.
- run log includes `demo-app-pvc-writer-hold.yaml`.
- `writer.log` includes `holding pod so CSI node restart happens while PVC is mounted`.
- `restart-csi-node-status.log` shows the DaemonSet rollout completed.
- `writer.log` contains `/data/demo.bin: OK`.
- `reader.log` contains `/data/demo.bin: OK`.
- final line contains:
`[app-demo] PASS: app pod wrote data, replacement app pod read it back through the same PVC, cleanup complete`.
- `iscsi-sessions.after-delete.txt` contains no `iqn.2026-05.io.seaweedfs`.
- no generated `sw-blockvolume` Deployment remains.
## Report Format
QA should report:
- branch and commit SHA,
- host and kernel,
- exact command,
- result,
- artifact path,
- final PASS line,
- `restart-csi-node-status.log`,
- writer and reader checksum lines,
- cleanup state,
- any CSI node, kubelet, or iSCSI errors.
## Non-Claims
- No blockvolume process restart durability claim.
- No mounted failover claim.
- No ALUA, MPIO, NVMe, or multi-node claim.
- No performance claim.
@@ -289,6 +289,45 @@ func TestISCSIP3K8sFioRegistrationBuildsShellDriver(t *testing.T) {
}
}
func TestISCSIP5CSINodeRestartRegistrationBuildsShellDriver(t *testing.T) {
repoRoot := findRepoRoot(t)
raw, err := os.Open(registrationPath(repoRoot, "iscsi-p5-csi-node-restart.json"))
if err != nil {
t.Fatalf("open registration: %v", err)
}
defer raw.Close()
registration, err := DecodeRegistration(raw)
if err != nil {
t.Fatalf("DecodeRegistration: %v", err)
}
if registration.Scenario != "iscsi-p5-csi-node-restart" || registration.Driver.Type != "shell" {
t.Fatalf("registration=%+v", registration)
}
driver, err := registration.NewDriver(repoRoot)
if err != nil {
t.Fatalf("NewDriver: %v", err)
}
shell, ok := driver.(ShellDriver)
if !ok {
t.Fatalf("driver type=%T want ShellDriver", driver)
}
if !filepath.IsAbs(shell.Path) || filepath.Base(shell.Path) != "run-k8s-csi-node-restart.sh" {
t.Fatalf("shell path=%q", shell.Path)
}
if _, err := os.Stat(shell.Path); err != nil {
t.Fatalf("shell driver path missing: %v", err)
}
for _, want := range []string{"restart-csi-node-status.log", "writer.log", "reader.log", "iscsi-sessions.after-delete.txt"} {
if !containsString(registration.Artifacts, want) {
t.Fatalf("registration artifacts missing %q: %v", want, registration.Artifacts)
}
}
if got := registration.ScenarioDefaultParams["SW_BLOCK_LAUNCHER_PVC_OWNER_REF"]; got != "1" {
t.Fatalf("owner-ref default=%q want 1", got)
}
}
func containsString(values []string, want string) bool {
for _, value := range values {
if value == want {
@@ -0,0 +1,52 @@
{
"schema_version": "1.0",
"scenario": "iscsi-p5-csi-node-restart",
"gate": "iSCSI-P5",
"layer": "L5-k8s",
"driver": {
"type": "shell",
"path": "scripts/run-k8s-csi-node-restart.sh"
},
"default_timeout_s": 900,
"required_capabilities": [
"bash",
"kubectl",
"privileged-k8s-node",
"iscsiadm",
"iscsi_tcp-loadable",
"mount"
],
"required_images": [
"sw-block:local",
"sw-block-csi:local"
],
"qa_instruction": "internal/docs/qa-assignments/iscsi-p5-csi-node-lifecycle-validation.md",
"known_green_commit": "",
"scenario_default_params": {
"SW_BLOCK_LAUNCHER_PVC_OWNER_REF": "1"
},
"artifacts": [
"run.log",
"writer.log",
"writer.describe.txt",
"reader.log",
"restart-csi-node.log",
"restart-csi-node-status.log",
"csi-node-pods.after-restart.txt",
"generated-blockvolume.yaml",
"blockmaster.log",
"blockcsi-controller.log",
"csi-provisioner.log",
"csi-attacher.log",
"blockvolume-generated.log",
"iscsi-sessions.after-delete.txt",
"cleanup.log"
],
"non_claims": [
"Single-node Kubernetes only.",
"CSI node restart while the writer pod holds the PVC mount.",
"No blockvolume restart durability claim.",
"No mounted failover, ALUA, MPIO, NVMe, or multi-node claim.",
"No performance or soak claim."
]
}
+1
View File
@@ -15,6 +15,7 @@ This directory contains developer and QA helper scripts.
| `run-k8s-alpha-large.sh` | Optional 256 MiB Kubernetes alpha smoke for larger iSCSI write coverage. |
| `run-k8s-alpha-fio.sh` | Optional 256 MiB Kubernetes alpha smoke with a 60s fio randrw workload. |
| `run-k8s-attach-detach-loop.sh` | QA loop wrapper. Repeats the app PVC attach/write/read/delete flow and stores per-iteration artifacts. |
| `run-k8s-csi-node-restart.sh` | QA wrapper. Restarts the CSI node DaemonSet between writer and reader pods using the same PVC. |
| `build-alpha-images.sh` | Builds local Docker images used by the Kubernetes alpha harness. |
| `run-alpha-k8s-dynamic.sh` | Public dynamic PVC alpha smoke entry. |
| `run-alpha-app-demo.sh` | App-demo implementation used by `run-k8s-demo.sh`. |
+37 -3
View File
@@ -8,6 +8,8 @@ POLL_LOG="$ARTIFACT_DIR/poll.log"
IMAGE="${SW_BLOCK_IMAGE:-sw-block:local}"
CSI_IMAGE="${SW_BLOCK_CSI_IMAGE:-sw-block-csi:local}"
LAUNCHER_PVC_OWNER_REF="${SW_BLOCK_LAUNCHER_PVC_OWNER_REF:-0}"
RESTART_CSI_NODE_BEFORE_READER="${SW_BLOCK_RESTART_CSI_NODE_BEFORE_READER:-0}"
DEMO_APP_MANIFEST="${SW_BLOCK_DEMO_APP_MANIFEST:-$ROOT/deploy/k8s/alpha/demo-app-pvc.yaml}"
BLOCKVOLUME_NAMESPACE="kube-system"
if [[ "$LAUNCHER_PVC_OWNER_REF" == "1" || "$LAUNCHER_PVC_OWNER_REF" == "true" ]]; then
BLOCKVOLUME_NAMESPACE="$NAMESPACE"
@@ -80,7 +82,7 @@ cleanup() {
(
set +e
kubectl delete -f "$ROOT/deploy/k8s/alpha/demo-app-reader-pod.yaml" --ignore-not-found=true >>"$ARTIFACT_DIR/cleanup.log" 2>&1
kubectl delete -f "$ROOT/deploy/k8s/alpha/demo-app-pvc.yaml" --ignore-not-found=true >>"$ARTIFACT_DIR/cleanup.log" 2>&1
kubectl delete -f "$DEMO_APP_MANIFEST" --ignore-not-found=true >>"$ARTIFACT_DIR/cleanup.log" 2>&1
kubectl -n "$NAMESPACE" delete pod sw-block-demo-reader sw-block-demo-writer --ignore-not-found=true >>"$ARTIFACT_DIR/cleanup.log" 2>&1
kubectl -n "$NAMESPACE" delete pvc sw-block-demo-pvc --ignore-not-found=true >>"$ARTIFACT_DIR/cleanup.log" 2>&1
kubectl -n kube-system delete deploy -l app=sw-blockvolume --ignore-not-found=true >>"$ARTIFACT_DIR/cleanup.log" 2>&1
@@ -111,6 +113,25 @@ wait_pod_succeeded() {
return 1
}
wait_pod_log_contains() {
local pod="$1"
local pattern="$2"
local timeout_s="$3"
for _ in $(seq 1 "$timeout_s"); do
if kubectl -n "$NAMESPACE" logs "$pod" 2>/dev/null | grep -F -q "$pattern"; then
return 0
fi
phase="$(kubectl -n "$NAMESPACE" get pod "$pod" -o jsonpath='{.status.phase}' 2>/dev/null || true)"
if [[ "$phase" == "Failed" ]]; then
echo "pod $pod failed before log pattern $pattern" >&2
return 1
fi
sleep 1
done
echo "pod $pod did not emit log pattern $pattern before timeout" >&2
return 1
}
require_cmd kubectl
NODE_NAME="$(kubectl get nodes -o jsonpath='{.items[0].metadata.name}')"
@@ -148,6 +169,8 @@ log "image=$IMAGE"
log "csi_image=$CSI_IMAGE"
log "blockvolume_namespace=$BLOCKVOLUME_NAMESPACE"
log "launcher_pvc_owner_ref=$LAUNCHER_PVC_OWNER_REF"
log "restart_csi_node_before_reader=$RESTART_CSI_NODE_BEFORE_READER"
log "demo_app_manifest=$DEMO_APP_MANIFEST"
kubectl version --client=true >"$ARTIFACT_DIR/kubectl-version.txt" 2>&1 || true
kubectl get nodes -o wide >"$ARTIFACT_DIR/nodes.before.txt"
@@ -167,7 +190,7 @@ kubectl -n kube-system wait --for=condition=available deploy/sw-block-csi-contro
kubectl -n kube-system rollout status ds/sw-block-csi-node --timeout=120s
log "apply demo app PVC and writer pod"
kubectl apply -f "$ROOT/deploy/k8s/alpha/demo-app-pvc.yaml" | tee "$ARTIFACT_DIR/apply-demo-app.log"
kubectl apply -f "$DEMO_APP_MANIFEST" | tee "$ARTIFACT_DIR/apply-demo-app.log"
log "wait for launcher-generated blockvolume manifest"
for _ in $(seq 1 180); do
@@ -187,9 +210,20 @@ kubectl apply -f "$ARTIFACT_DIR/generated-blockvolume.yaml" | tee "$ARTIFACT_DIR
kubectl -n "$BLOCKVOLUME_NAMESPACE" wait --for=condition=available deploy -l app=sw-blockvolume --timeout=120s
log "wait for app writer completion"
wait_pod_succeeded sw-block-demo-writer 240
if [[ "$RESTART_CSI_NODE_BEFORE_READER" == "1" || "$RESTART_CSI_NODE_BEFORE_READER" == "true" ]]; then
wait_pod_log_contains sw-block-demo-writer "[app-writer] wrote and verified /data/demo.bin" 240
else
wait_pod_succeeded sw-block-demo-writer 240
fi
kubectl -n "$NAMESPACE" logs sw-block-demo-writer | tee "$ARTIFACT_DIR/writer.log"
if [[ "$RESTART_CSI_NODE_BEFORE_READER" == "1" || "$RESTART_CSI_NODE_BEFORE_READER" == "true" ]]; then
log "restart CSI node DaemonSet before replacing the app pod"
kubectl -n kube-system rollout restart ds/sw-block-csi-node | tee "$ARTIFACT_DIR/restart-csi-node.log"
kubectl -n kube-system rollout status ds/sw-block-csi-node --timeout=180s | tee "$ARTIFACT_DIR/restart-csi-node-status.log"
kubectl -n kube-system get pods -l app=sw-block-csi-node -o wide >"$ARTIFACT_DIR/csi-node-pods.after-restart.txt" 2>&1 || true
fi
log "delete writer pod but keep PVC"
kubectl -n "$NAMESPACE" delete pod sw-block-demo-writer --wait=true --timeout=120s | tee "$ARTIFACT_DIR/delete-writer.log"
+11
View File
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT="${1:-$(pwd)}"
export SW_BLOCK_RUN_LABEL="${SW_BLOCK_RUN_LABEL:-csi-node-restart}"
export SW_BLOCK_LAUNCHER_PVC_OWNER_REF="${SW_BLOCK_LAUNCHER_PVC_OWNER_REF:-1}"
export SW_BLOCK_RESTART_CSI_NODE_BEFORE_READER=1
export SW_BLOCK_DEMO_APP_MANIFEST="${SW_BLOCK_DEMO_APP_MANIFEST:-$ROOT/deploy/k8s/alpha/demo-app-pvc-writer-hold.yaml}"
exec bash "$ROOT/scripts/run-alpha-app-demo.sh" "$ROOT"