Repository navigation
feat(rwx): v2 — HA (DRBD-replicated) ReadWriteMany support - #2
Closed
DeanKamali wants to merge 23 commits into
Closed
DeanKamali wants to merge 23 commits into
DeanKamali wants to merge 23 commits into
Conversation
v1 layers NFS on top of an RWO HwameiStor LocalVolume. A new controller watches PVCs bound to the lvm.hwameistor.io/rwx provisioner and builds a backing RWO PVC, a selector-less ClusterIP Service, and a mirror NFS PV. A new per-node hwameistor-nfs-server DaemonSet (nfs-reactor + Ganesha) mounts the backing LV and exports it. Why this shape: pod count is O(nodes), not O(PVCs), matching Piraeus's linstor-csi-nfs-server pattern. Everything is gated on rwx.enabled=false by default — existing RWO workflows are untouched. The HwameiStor CSI driver still advertises SINGLE_NODE_WRITER only; multi-writer semantics live at the NFS protocol layer, so Kubernetes's single-attachment guarantee for the backing RWO PVC is preserved. Known gaps for v1 (documented): Ganesha DBus client is a stub (logs calls; real godbus integration is a standalone follow-up), HA/DRBD failover is deferred to v2, and e2e tests are deferred.
- Add Dockerfile + Makefile targets for new local-storage-nfs-reactor binary so it can be built and pushed like the other components. - Add .github/workflows/release-rwx-images.yml: on pushes to feat/rwx-v1/main, compile and push both local-storage and local-storage-nfs-reactor images to docker.io/stackblaze/hwameistor-*. The workflow uses DOCKERHUB_USERNAME/DOCKERHUB_TOKEN repo secrets. - Replace the Ganesha DBus stub with a real godbus/dbus/v5 client (vendored). Reconnects on transport failure so Ganesha restarts don't take the reactor down. - Helm override file hack/central-rwx-values.yaml pins the images at stackblaze/* for the central-cluster rollout. - Cluster-ops helpers under hack/: wipe-nvme-pool, survey-nvme-pool, claim-nvme-disks, smoke-rwo. These were used to migrate central off TopoLVM and onto HwameiStor and are kept around so the steps are repeatable on other clusters.
- Release workflow now pushes only to ghcr.io/stackblaze (+packages: write permission). GHCR is where every other HwameiStor image lives, so a single-registry setup avoids needing per-component registry overrides in the chart. - central-rwx-values.yaml no longer overrides global.hwameistorImageRegistry. Instead it only overrides the two image repos, which get concatenated with the default ghcr.io prefix. The previous docker.io override broke ImagePullBackOff for the other components (admission, auditor, etc.) on the central cluster. - Add hack/central-storageclass-nvme.yaml so the backing RWO StorageClass used by hack/central-rwx-values.yaml is reproducible.
The reactor reads LocalVolumeReplica.Status.DevicePath to find the host device node to bind-mount into /srv/exports/<uid>. Without list/watch on that resource the informer fails to sync and the container crashloops. Caught on central during rwx.enabled=true rollout.
The upstream ghcr.io/kubernetes-sigs/nfs-ganesha image has /bin/bash as
its entrypoint with no default command, so the container exited 0
immediately on start. Replace with an explicit command that:
- mkdirs the runtime dirs ganesha expects
(/run/dbus, /var/lib/nfs/ganesha, /usr/local/var/run/ganesha)
- starts dbus-daemon --system --fork (the reactor connects to
/run/dbus/system_bus_socket to add/remove exports)
- execs ganesha.nfsd -F -L /dev/stdout -f /etc/ganesha/ganesha.conf
Also add the NFS_KRB5 { Active_krb5 = false; } block Ganesha requires
when no Kerberos is configured (matches the Piraeus template).
Caught rolling out on central with rwx.enabled=true.
HwameiStor's LVM CSI driver only formats a volume when the kubelet calls
NodeStageVolume, which never happens for RWX backing PVCs because no
consumer pod attaches them directly (they're fronted by an NFS PV). So
the reactor needs to mkfs the LV itself before the very first mount.
The fix:
- blkid probes the device for an existing filesystem signature
- if blank, we mkfs.xfs (or mkfs.ext4 per requested fsType) and proceed
- if the device already has a different filesystem we refuse to mount
rather than silently overwriting
Also flip the NVMe StorageClass to volumeBindingMode: Immediate. The RWX
reactor can only mount and export the LV once the backing PVC is bound,
and no consumer pod ever directly touches that PVC — so
WaitForFirstConsumer deadlocks provisioning.
Known follow-up: our rwx reconciler should set the
volume.kubernetes.io/selected-node annotation on the backing PVC so
HwameiStor's scheduler has a topology hint. For now operators need to
patch that annotation manually (or use a SC with allowedTopologies).
godbus expects 'unix:path=/path' not 'unix:/path'. The lax form was rejected at connect time with 'invalid address (neither path nor abstract set)'. Applies to both the flag default in the reactor binary and the DaemonSet arg in the Helm chart.
Ganesha's DBus AddExport takes a path to a config *file* on disk plus an EXPORT(Export_Id = N) selector expression, not inline config text. Write the export block to <ExportRoot>/<uid>.conf and pass that. Also switch the default fsType from ext4 -> xfs when the LV doesn't carry a Status.PublishedFSType, matching what HwameiStor's default StorageClass creates and what the rest of the platform uses. Updated the unit tests to use t.TempDir() for ExportRoot so write/mkdir is hermetic on any platform.
Two fixes for the central-cluster rollout: 1. rwx-pvc-controller now stamps volume.kubernetes.io/selected-node on the backing PVC at create time, picking any Ready LocalStorageNode. HwameiStor's CSI driver rejects CreateVolume without a topology hint, but the normal WaitForFirstConsumer path deadlocks because no user pod ever directly mounts the backing PVC (the NFS PV sits in front). This removes the operator-facing chicken-and-egg where PVCs stayed Pending with 'not found accessibility requirements'. 2. The reactor now calls Ganesha RemoveExport(id) before every AddExport. On reactor restart our in-memory state is fresh but Ganesha remembers the previous registration; without pre-remove, AddExport fails with 'Duplicate export id' / 'Pseudo path is a duplicate' and the export never converges. RemoveExport is informational on failure — if the export isn't there, the followup AddExport is what matters. Tests: LocalStorageNode/List added to the reconciler test scheme so the new list call is registered.
Ganesha's DBus doesn't return distinct error codes — both 'Pseudo path already exists' and 'Duplicate export id' show up as 'invalid param value' with the real reason buried in the details string. Likewise RemoveExport on a missing id returns 'Export id not found'. These are idempotency-friendly semantics (the desired state is reached) so the reactor should treat them as success and proceed to write the EndpointSlice. Previously the reactor was looping forever because AddExport kept erroring even after Ganesha had already registered the export.
Passing EXPORT(Export_Id = N) as the DBus AddExport selector caused
Ganesha v6.5 to reply 'Error finding exports ... No such file or
directory' when the file's current Export_Id didn't match N (e.g.
reactor restart re-wrote the file with a different allocated id).
Since each config file we write contains exactly one EXPORT{} block,
passing an empty selector is unambiguous and avoids the mismatch —
Ganesha adds whatever EXPORT it finds in that file.
The previous startup script did 'dbus-daemon --fork' then 'exec ganesha.nfsd', which replaced bash (PID 1) with ganesha and orphaned the forked dbus-daemon. With no init/reaper in the container the orphan got reaped, so Ganesha's dbus thread failed on startup with 'DBUS not initialized'. The reactor's AddExport calls then got 'connection refused' forever. Keep bash as PID 1, run both dbus-daemon (--nofork) and ganesha.nfsd as children, wait -n so the container exits when either child dies (Kubelet restarts us). Same result as a real init but no extra tooling.
Ganesha v6.5 has an upstream bug where calling RemoveExport on an unknown export id corrupts internal state and makes the very next AddExport segfault the daemon. Reproduced on both the upstream sig-storage image and quay.io/piraeusdatastore/piraeus-csi-nfs-server. Changes: - Drop the pre-AddExport RemoveExport call. AddExport's error handler already treats 'already added' / 'duplicate pseudo path' as success, so re-running on restart is safe (and won't crash ganesha). - Derive export IDs deterministically (fnv-1a over the UID) instead of allocating a fresh one each time. Restarts reuse the same id for the same export, so there's nothing for a stale RemoveExport to look up. - Switch the ganesha image to piraeusdatastore/piraeus-csi-nfs-server v1.10.6 — it has a working dbus-daemon + ganesha.nfsd under the standard /var/run/ganesha paths and is maintained against a real NFS data plane (Piraeus). Upstream sig-storage nfs-ganesha:V6.5 has a /bin/bash entrypoint and no CMD, which made it exit immediately. - Add /var/run/ganesha to the mkdir list in the startup script (the piraeus image looks for ganesha.pid there). - hack/probe-piraeus.yaml: short-lived diagnostic pod used during this investigation, kept so others can reproduce the probe.
Ganesha's DBus AddExport selector parser is whitespace-strict and rejects 'EXPORT(Export_Id = N)' with 'Error finding exports ... No such file or directory'. The working form is 'EXPORT(Export_Id=N)'. Verified against the mailing-list canonical example: dbus-send ... AddExport string:/path/to/export.conf 'string:EXPORT(Export_Id=3)' This restores the selector (my previous commit dropped it entirely to dodge the space bug, but then ganesha added ALL exports in the file, which breaks multi-volume reactors). With the correct syntax we can once again pick exactly the one EXPORT we just wrote.
Ganesha v6.5's reply when AddExport targets an EXPORT that's already registered is 'Selected entries in <path> already active!!!'. Include that substring in the idempotency matcher so the reactor advances past AddExport and writes the EndpointSlice.
Two fixes to let the reactor finish a full reconcile cycle against Ganesha v6.5: 1. EndpointSlice label 'endpointslice.kubernetes.io/managed-by' was set to 'hwameistor.io/nfs-reactor'. Label VALUES can't contain '/' (only label keys can). Switched to the plain identifier 'hwameistor-nfs-reactor'. The apiserver was rejecting every create/update with a label-validation error, so the EndpointSlice for RWX Services never materialised. 2. /srv/exports is now a hostPath (/var/lib/hwameistor/nfs-exports) instead of an emptyDir. The reactor mounts backing LVs there; with emptyDir those mounts died with the pod, and the next reactor pod hit 'device or resource busy' because the LV was still mounted in the old pod's per-pod kubelet dir. A stable host-visible path keeps mounts alive across reactor restarts and lets ganesha keep serving exports.
NFSv4 clients mount the pseudo-root path that Ganesha publishes, not the real server-side Path. Our EXPORT template already sets Path = '/srv/exports/<uid>' Pseudo = '/<uid>' but the mirror PV was putting the real Path into share + volumeHandle, so mount.nfs tried 'server:/srv/exports/<uid>' and got 'No such file or directory' from ganesha (it has no such pseudo-path). Switch share / volumeHandle to the pseudo path '/<uid>'. Introduce ExportPseudoPath helper and update the unit test expectation.
Default Ganesha template used Root_Squash which maps incoming root writes to nobody, breaking any pod that writes as uid 0 (which is the common case — alpine, debian, most K8s workloads). Flip to No_Root_Squash by default so the stack works out of the box. Matches Piraeus's template. Operators who want squashing can opt in per-StorageClass via the lvm.hwameistor.io/nfs-squash parameter (follow-up).
Post-implementation audit pass. Removes ~750 lines of overhead without changing behaviour or breaking any tests: - hack/: 8 yamls for smoke-testing and TopoLVM-→-HwameiStor migration on the central cluster. Deployment recipes belong in stackblaze-services, smoke tests belong in test/e2e/ when we write real ones. - state.go: dropped RebuildFromMounts (never useful — Reconcile is already idempotent and declarative), removed the lvToUID index (GetByLV now linear-scans; a node serves a handful of exports at most), simplified AllocateID to pure fnv-1a. - Merged rwxpvc/doc.go into reconciler.go's package comment. - Trimmed verbose comments across reactor.go, ganesha.go, reconciler.go, objects.go, endpointslice.go, mount_linux.go, mount_other.go per the project guideline to leave WHY-comments only. - Updated nfsreactor package doc to reflect the current implementation (no /proc/mounts rehydration claim).
Both packages need to agree on the rwx-export annotation key, the provisioner name, the export root path, and the selected-node annotation. Having two copies of each string is a drift bug waiting to happen — bump one, forget the other, silent breakage. Move them to a new leaf package pkg/local-storage/member/rwx so both sides import the same source of truth. The existing public names (RWXExportAnnotation, RWXProvisionerName, ExportAnnotation) are preserved as re-exports so downstream callers aren't broken.
For non-convertible LVs v1 works because there's one replica and one
node serves the export. For convertible (DRBD-replicated) LVs every
replica node satisfied v1's isLocallyReady, so two reactors raced to
mount the same device: DRBD auto-promotes one to Primary, the other
stays Secondary and mkfs loops with 'Read-only file system'. Verified
on central 2026-04-21.
v2 adds a DRBDClient interface (drbdsetup role <resource>) and makes
isLocallyReady branch on lv.Spec.Convertible:
- non-HA (v1 behaviour): any node with a Ready replica serves
- HA: only the DRBD Primary serves; the reactor asks DRBD directly
because HwameiStor's VolumeReplica.Primary is a static scheduling
hint, not the live role (cross-checked via drbdadm status)
Also includes the inverse path: an old Primary that gets demoted
(DRBD auto-promoted a peer after the old node's open dropped) sees
itself not-eligible on next reconcile and tears down cleanly.
What's new / what changes:
- pkg/local-storage/member/node/nfsreactor/drbd.go — DRBDClient +
real drbdsetup impl (~35 lines)
- reactor.go wires DRBDClient into the Reactor and switches
isLocallyReady on Convertible (~15 lines)
- reactor_test.go adds fakeDRBD + 4 HA test cases: Primary publishes,
Secondary skips, promotion takes over, demotion tears down
- build/local-storage-nfs-reactor/Dockerfile installs drbd90-utils
from ELRepo (binary only; kernel module lives on the host)
- helm/hwameistor/templates/storageclass-rwx-ha.yaml + values.yaml
ship a sample HA RWX StorageClass, off by default
- docs/rwx-v2-design.md spells out the verified semantics
No CRD changes. No behavioural change for existing v1 (non-HA) RWX
PVCs — the new branch short-circuits on Convertible==false.
…ootstrap Two fixes to the initial v2 implementation, found when live-testing on central: 1. Eligibility was checking lv.Spec.Convertible — wrong field. Convertible means 'this non-HA volume CAN later be transitioned to HA' (a migration flag). HA-ness is lv.Spec.ReplicaNumber >= 2, exposed as LocalVolume.IsHighAvailability(). Use that. 2. For a fresh HA LV nobody is DRBD Primary until something opens the device r/w. v1 relied on the CSI driver's ControllerPublish chain, but the RWX reactor IS the consumer — so it has to trigger the initial open itself. Without this, two Secondary reactors just sit there waiting for a Primary that never materialises, and consumer pods hang trying to mount the NFS PV (no EndpointSlice gets written). Fix: on an HA LV where we're currently Secondary, the lex-first replica node elects itself and attempts the mount. DRBD auto- promotes on the resulting open(2). Peers see themselves Secondary on next reconcile and back off. Tests: existing HA cases updated to pin lex-first so 'Secondary + not elector' vs 'Secondary + elector' are unambiguous. New test TestReconcile_HA_ElectsSelfOnBootstrap covers the promotion trigger.
Author
|
Superseded by consolidated PR — v1 + v2 in a single diff. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this solves
For a DRBD-replicated (HA) backing volume, v1's reactor treated every replica node as eligible to serve. Two reactors raced to mount the device — DRBD promoted one to Primary, the other looped forever with
mkfs: Read-only file system. No EndpointSlice stabilised, RWX mounts hung.How v2 picks the Primary
On HA volumes (
replicaNumber >= 2) the reactor consultsdrbdsetup role <resource>and only serves if Primary. On a fresh volume where nobody is Primary yet, the lex-first replica node elects itself and opens the device — DRBD auto-promotes on open.Verified on central
2-replica HA RWX PVC, two consumer pods on different nodes, shared write visible to both, DRBD
role:Primaryon exactly one node.Scope
~70 lines of Go (
drbd.go+ reactor tweak + tests), 1 new Helm sample SC (off by default), +drbd90-utils in the reactor image. No CRD changes. Non-HA RWX behavior unchanged.