From 94c7fa0608a4ea66ea32d5e068186f866a8201eb Mon Sep 17 00:00:00 2001 From: Manohar Reddy Date: Thu, 12 Nov 2026 08:55:35 +0100 Subject: [PATCH] fix(pnfs): make an MDS move clean, and hold the MDS in maintenance The guest could never power down. The host-path forwarder, which carries the guest's NVMe/TCP connections to the storage nodes through the mds-proxy, was served under the runner's stop-signal context, so SIGTERM closed it, and every spliced connection, at the moment the supervisor pressed the power button. The guest then hung unmounting the exported XFS ("no usable path - requeuing I/O") and never powered down: on every MDS move the runner logged "guest did not power down within 20s, killed QEMU", and every pNFS client stalled for those 20 s on top of the restart and grace period. The supervisor now starts the storage path itself, under a context that outlives the stop signal and ends only once QEMU has exited. A drain evicted the MDS freely. The maintenance window's budget held the SPDK pod, the management API, and FoundationDB, and nothing else, so draining a worker evicted the MDS at once, even while the control plane refused or deferred the maintenance the drain was for; the RCA pnfs_mds_not_in_eviction_targets_rca_20261111 saw this three times in a day. evictionTargets is now a list of label selectors, and the MDS is selected by the presence of storage.simplyblock.io/cluster-id, which only its pods carry, so its pod template is unchanged and an upgrade does not move it. --- csi-driver/cmd/mds-runner/main.go | 12 +++--- csi-driver/internal/mds/runner/supervisor.go | 12 ++++++ .../internal/mds/runner/supervisor_test.go | 37 ++++++++++++++++ operator/docs/tests/test-plan-pnfs-rwx.md | 2 + operator/internal/controllers/driver/mds.go | 2 +- .../controllers/node/hostmaintenance_test.go | 42 +++++++++++++++++++ .../internal/controllers/node/workload.go | 42 +++++++++++++++---- operator/internal/utils/constants.go | 3 ++ 8 files changed, 137 insertions(+), 15 deletions(-) diff --git a/csi-driver/cmd/mds-runner/main.go b/csi-driver/cmd/mds-runner/main.go index 9530d4f8a..5e481392f 100644 --- a/csi-driver/cmd/mds-runner/main.go +++ b/csi-driver/cmd/mds-runner/main.go @@ -185,12 +185,6 @@ func run(ctx context.Context, c config) error { if err := netsetup.Apply(ctx, plan, netsetup.ExecIPTables); err != nil { return err } - if plan.HostPath { - if err := startHostPath(ctx, plan, c.hostProxy); err != nil { - return err - } - } - if err := os.MkdirAll(c.runDir, 0o700); err != nil { return err } @@ -239,6 +233,12 @@ func run(ctx context.Context, c config) error { guest.Arch, guest.Hostname, guest.CPUs, guest.MemoryMiB, guest.Address, uplink) sup := &runner.Supervisor{ + StoragePath: func(ctx context.Context) error { + if !plan.HostPath { + return nil + } + return startHostPath(ctx, plan, c.hostProxy) + }, Start: runner.StartProcess(binary, args, os.Stdout, os.Stderr), Probe: runner.GRPCHealthProbe(agentAddress), Powerdown: func(ctx context.Context) error { diff --git a/csi-driver/internal/mds/runner/supervisor.go b/csi-driver/internal/mds/runner/supervisor.go index 69b4ed3de..3eb135cf2 100644 --- a/csi-driver/internal/mds/runner/supervisor.go +++ b/csi-driver/internal/mds/runner/supervisor.go @@ -38,6 +38,11 @@ type Process interface { // Supervisor runs one guest. type Supervisor struct { + // StoragePath starts what carries the guest's connections to its storage, + // before QEMU, and serves it until ctx ends. Run hands it a context that + // outlives Run's own and ends only once QEMU has exited, because a guest + // powering down still flushes and unmounts through it. Optional. + StoragePath func(ctx context.Context) error // Start starts QEMU. Start func(ctx context.Context) (Process, error) // Probe returns nil while the guest is healthy. @@ -64,6 +69,13 @@ type Supervisor struct { // it down, or until it fails. It returns nil only for a shutdown that was // asked for. func (s *Supervisor) Run(ctx context.Context) error { + if s.StoragePath != nil { + storage, stopStorage := context.WithCancel(context.WithoutCancel(ctx)) + defer stopStorage() + if err := s.StoragePath(storage); err != nil { + return fmt.Errorf("starting the guest's storage path: %w", err) + } + } proc, err := s.Start(ctx) if err != nil { return fmt.Errorf("starting QEMU: %w", err) diff --git a/csi-driver/internal/mds/runner/supervisor_test.go b/csi-driver/internal/mds/runner/supervisor_test.go index 39210a8c7..53572e491 100644 --- a/csi-driver/internal/mds/runner/supervisor_test.go +++ b/csi-driver/internal/mds/runner/supervisor_test.go @@ -283,3 +283,40 @@ func TestAFailedDrainStillPowersDown(t *testing.T) { t.Errorf("Run = %v, want a clean shutdown", err) } } + +// Regression: 2026-11-11-mds-forwarder-dies-before-guest. The host-path +// forwarder carries the guest's NVMe/TCP connections, and it was served under +// the runner's stop-signal context. SIGTERM therefore cut the guest's storage +// at the moment the power button was pressed: unmounting the exported XFS hung +// on paths that no longer existed, the guest never powered down, and QEMU was +// killed after the shutdown grace on every MDS move (about 20 s of client +// stall each time). +func TestTheGuestKeepsItsStorageUntilItHasPoweredDown(t *testing.T) { + q := newFakeQEMU() + s := supervisor(q) + var storage context.Context + s.StoragePath = func(ctx context.Context) error { storage = ctx; return nil } + s.Powerdown = func(context.Context) error { + // The guest flushes and unmounts on the way down, through its storage. + if storage.Err() != nil { + return errors.New("the guest's storage path is gone") + } + q.stop(nil) + return nil + } + ctx, cancel := context.WithCancel(context.Background()) + done := runAsync(ctx, s) + + waitFor(t, "readiness", s.Ready) + cancel() + + if err := result(t, done); err != nil { + t.Errorf("Run after a requested shutdown = %v, want nil", err) + } + if q.killed.Load() { + t.Error("QEMU was killed: the guest lost its storage before it could power down") + } + if storage.Err() == nil { + t.Error("the storage path outlived Run") + } +} diff --git a/operator/docs/tests/test-plan-pnfs-rwx.md b/operator/docs/tests/test-plan-pnfs-rwx.md index 992530861..a283cb515 100644 --- a/operator/docs/tests/test-plan-pnfs-rwx.md +++ b/operator/docs/tests/test-plan-pnfs-rwx.md @@ -199,6 +199,7 @@ restarted rather than migrated (design ยง13). | U-104 | The runner's debug key is a private pair the guest accepts, new at every boot | Positive | `TestDebugSSHKeyIsAPrivatePairTheGuestAccepts`, `TestDebugSSHKeyIsNewEveryBoot` | | U-105 | Regression (run `pnfs-1791652310`): the runner drains the guest and waits before the power button, and a failed drain still powers it down | Regression | `TestShutdownDrainsTheGuestBeforeThePowerButton`, `TestAFailedDrainStillPowersDown` | | U-117 | Regression (2026-11-11-standby-guest-never-activated): a guest booted without its state mounted is activated, a blank state disk is formatted first, an unreadable one never, and a serving guest is left as it is | Regression | `TestAGuestBootedAsAStandbyIsActivated`, `TestABlankStateDiskIsFormattedFirst`, `TestAnUnreadableStateDiskIsNeverFormatted`, `TestAGuestAlreadyServingIsLeftAsItIs` | +| U-116 | Regression (2026-11-11-mds-forwarder-dies-before-guest): the guest keeps its storage path through the power-down, so it powers down instead of being killed | Regression | `TestTheGuestKeepsItsStorageUntilItHasPoweredDown` | | U-106 | The drain drops every packet carrying a request to the guest's NFS port and lets bare ACKs through | Positive | `TestTheDrainDropsRequestsButNotAcknowledgments` | | U-107 | Regression (run `pnfs-1791662135`): the kernel command line keeps unknown exports answered with a retry for 60s after nfsd starts | Regression | `TestKernelCmdlineCarriesTheStaticAddress` | | U-76 | The relay resolves connections as the operator's identity, and delete proceeds without the control plane | Positive | `TestCreateHandsTheGuestAConnectionResolvedForTheOperatorsIdentity`, `TestDeleteGoesAheadWithoutTheControlPlane` | @@ -325,6 +326,7 @@ through the control plane's API. | O-49 | Regression (run `pnfs-1791662135`): exports reconcile concurrently, so a restart reassembles them together | Regression | `TestExportsReconcileConcurrently` | | O-50 | Regression (2026-11-11-mds-proxy-remote-ports): on a managed consumer with no StorageNode, the mds-proxy is told the listener ports the remote control plane reports, asked with the cluster secret | Regression | `TestTheMDSProxyIsToldTheListenerPortsOfARemoteStorageCluster` | | O-51 | A remote control plane that does not answer leaves the published mds-proxy ports in place | Negative | `TestAnUnreachableControlPlaneKeepsThePublishedPorts` | +| O-52 | Regression (2026-11-11-pnfs-mds-not-in-eviction-targets): a maintenance window holds the pNFS metadata server on the drained worker, and none on another worker | Regression | `TestTheWindowHoldsThePNFSMetadataServer` | --- diff --git a/operator/internal/controllers/driver/mds.go b/operator/internal/controllers/driver/mds.go index cff721780..beaec45ac 100644 --- a/operator/internal/controllers/driver/mds.go +++ b/operator/internal/controllers/driver/mds.go @@ -49,7 +49,7 @@ const KVMCapableValue = "true" // MDSClusterLabel carries the storage cluster's full ID on the metadata server // pod and its StatefulSet. The name only carries a prefix of it. -const MDSClusterLabel = "storage.simplyblock.io/cluster-id" +const MDSClusterLabel = utils.LabelMDSClusterID // MDSTemplateHashAnnotation records MDSTemplateHash on the metadata server // StatefulSet, so an operator release can tell whether the pod template is the diff --git a/operator/internal/controllers/node/hostmaintenance_test.go b/operator/internal/controllers/node/hostmaintenance_test.go index 386c6b90a..fe3611428 100644 --- a/operator/internal/controllers/node/hostmaintenance_test.go +++ b/operator/internal/controllers/node/hostmaintenance_test.go @@ -725,3 +725,45 @@ func TestAMaintenanceWindowSendsNothingToANodeLeavingTheCluster(t *testing.T) { }) } } + +// anMDSPod is the pNFS metadata server's pod, labeled as its StatefulSet labels +// it: by its per-cluster name and the cluster it serves. +func anMDSPod(worker string) *corev1.Pod { + return &corev1.Pod{ + ObjectMeta: metav1.ObjectMeta{ + Name: "simplyblock-pnfs-mds-2b201eb1-0", + Namespace: opsNamespace, + Labels: map[string]string{ + "app": "simplyblock-pnfs-mds-2b201eb1", + "storage.simplyblock.io/cluster-id": "2b201eb1-15b6-4bb6-a341-23acde78bb6c", + }, + }, + Spec: corev1.PodSpec{NodeName: worker}, + Status: corev1.PodStatus{Phase: corev1.PodRunning}, + } +} + +// Regression: 2026-11-11-pnfs-mds-not-in-eviction-targets. The window's budget +// held the SPDK pod, the management API, and FoundationDB, and nothing else, so +// a drain of the worker evicted the pNFS metadata server at once, even while +// the control plane refused or deferred the maintenance it was drained for. +// Every pNFS client in the cluster stalled until a new metadata server had +// booted and ended its grace period, three times in a day for maintenance that +// never ran. +func TestTheWindowHoldsThePNFSMetadataServer(t *testing.T) { + mds := anMDSPod(opsWorker) + elsewhere := anMDSPod("another-worker") + elsewhere.Name = "simplyblock-pnfs-mds-other-0" + r, apiClient := anOpsWorld(t, aControlPlane(), anSpdkPod(opsWorker, "4420"), mds, elsewhere) + + if err := r.Workload.BlockEviction( + context.Background(), opsNamespace, opsCluster, opsWorker); err != nil { + t.Fatalf("holding the eviction: %v", err) + } + if !guarded(t, apiClient, mds.Name) { + t.Error("the metadata server on the drained worker is not held by the window's budget") + } + if guarded(t, apiClient, elsewhere.Name) { + t.Error("a metadata server on another worker was held by this worker's window") + } +} diff --git a/operator/internal/controllers/node/workload.go b/operator/internal/controllers/node/workload.go index 150c8a0d8..308214e05 100644 --- a/operator/internal/controllers/node/workload.go +++ b/operator/internal/controllers/node/workload.go @@ -39,6 +39,8 @@ import ( policyv1 "k8s.io/api/policy/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/apimachinery/pkg/selection" "k8s.io/apimachinery/pkg/util/intstr" "sigs.k8s.io/controller-runtime/pkg/client" logf "sigs.k8s.io/controller-runtime/pkg/log" @@ -399,24 +401,48 @@ func (w *Workload) agentPodOn( // the window with nothing to ask, which is what the operator saw on 2026-09-29 // when its shutdown took a connection refused from the webAPI mid-flight. // +// The pNFS metadata server is here because every pNFS client in the cluster goes +// through it: evicting it stalls them all until a new one has booted and ended +// its grace period, which a drain must not cost while the control plane has not +// yet agreed to the maintenance. +// // The node agent's DaemonSet pod is deliberately absent. A budget over it holds // no drain, and the agent is what the window needs answering in AwaitingHost. -var evictionTargets = []map[string]string{ - {utils.LabelRole: utils.LabelSpdkProxyRole}, - {atlaskube.LabelApp: controlplane.ComponentWebAPI}, - {utils.LabelFDBClusterName: controlplane.ComponentFDBCluster}, +var evictionTargets = []labels.Selector{ + labels.SelectorFromSet(labels.Set{utils.LabelRole: utils.LabelSpdkProxyRole}), + labels.SelectorFromSet(labels.Set{atlaskube.LabelApp: controlplane.ComponentWebAPI}), + labels.SelectorFromSet(labels.Set{utils.LabelFDBClusterName: controlplane.ComponentFDBCluster}), + mdsPods, } +// mdsPods selects every pNFS metadata server pod, by the cluster label only they +// carry. +var mdsPods = func() labels.Selector { + req, err := labels.NewRequirement(utils.LabelMDSClusterID, selection.Exists, nil) + if err != nil { + panic(err) + } + return labels.NewSelector().Add(*req) +}() + // podsMatching lists the pods on one worker that carry every given label, // skipping any that is already on its way out. func (w *Workload) podsMatching( - ctx context.Context, namespace, worker string, labels map[string]string, + ctx context.Context, namespace, worker string, set map[string]string, +) ([]corev1.Pod, error) { + return w.podsSelected(ctx, namespace, worker, labels.SelectorFromSet(set)) +} + +// podsSelected lists the pods on one worker that the selector matches, skipping +// any that is already on its way out. +func (w *Workload) podsSelected( + ctx context.Context, namespace, worker string, selector labels.Selector, ) ([]corev1.Pod, error) { var pods corev1.PodList err := w.List(ctx, &pods, - client.InNamespace(namespace), client.MatchingLabels(labels)) + client.InNamespace(namespace), client.MatchingLabelsSelector{Selector: selector}) if err != nil { - return nil, fmt.Errorf("list the pods matching %v: %w", labels, err) + return nil, fmt.Errorf("list the pods matching %v: %w", selector, err) } on := make([]corev1.Pod, 0, len(pods.Items)) for i := range pods.Items { @@ -509,7 +535,7 @@ func (w *Workload) BlockEviction( ctx context.Context, namespace, cluster, worker string, ) error { for _, selector := range evictionTargets { - pods, err := w.podsMatching(ctx, namespace, worker, selector) + pods, err := w.podsSelected(ctx, namespace, worker, selector) if err != nil { return err } diff --git a/operator/internal/utils/constants.go b/operator/internal/utils/constants.go index 20241465e..de8090842 100644 --- a/operator/internal/utils/constants.go +++ b/operator/internal/utils/constants.go @@ -163,6 +163,9 @@ const ( // thing about it that is the same on every worker. LabelRole = "role" LabelSpdkProxyRole = "simplyblock-storage-node" + // LabelMDSClusterID names the cluster a pNFS metadata server pod serves. Only + // metadata server pods carry it. + LabelMDSClusterID = "storage.simplyblock.io/cluster-id" ) // NodeIsLeaving reports whether a control-plane node status, lowercased, is one