Skip to content

fix: detect and remount stale NFS mounts in NodePublishVolume#1108

Merged
andyzhangx merged 2 commits intokubernetes-csi:masterfrom
andyzhangx:fix-stale-nfs-remount
Apr 19, 2026
Merged

fix: detect and remount stale NFS mounts in NodePublishVolume#1108
andyzhangx merged 2 commits intokubernetes-csi:masterfrom
andyzhangx:fix-stale-nfs-remount

Conversation

@andyzhangx
Copy link
Copy Markdown
Member

What type of PR is this?
/kind bug

What this PR does / why we need it:
When an NFS server restarts, existing mounts on nodes become stale. If a pod with fsGroup is then restarted, kubelet's applyFSGroup calls lstat on the mount path and fails with ESTALE (stale NFS file handle) before the CSI driver gets a chance to remount.

This PR fixes NodePublishVolume to detect stale mounts and automatically unmount + remount them, so that kubelet's subsequent applyFSGroup succeeds.

How does it work:

  1. When the target path is already mounted, do an os.Lstat check
  2. If ESTALE is detected, unmount the stale mount
  3. Fall through to the normal mount path for a fresh mount

Which issue(s) this PR fixes:
Ref #927

Does this PR introduce a user-facing change?

Fix stale NFS mount detection in NodePublishVolume: pods with fsGroup can now recover after NFS server restart without manual intervention.

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. labels Apr 19, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andyzhangx

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 19, 2026
@k8s-ci-robot k8s-ci-robot requested review from carlory and gnufied April 19, 2026 02:21
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Apr 19, 2026
@andyzhangx andyzhangx force-pushed the fix-stale-nfs-remount branch from cac3012 to 7f2a9ee Compare April 19, 2026 02:23
When an NFS server restarts, existing mounts become stale. If a pod
with fsGroup is restarted, kubelet calls applyFSGroup which does
lstat on the mount path and fails with ESTALE before CSI driver gets
a chance to remount.

Fix by checking for stale file handles when the target path is already
mounted. If detected, unmount the stale mount and proceed with a
fresh mount.

Ref 927
@andyzhangx andyzhangx force-pushed the fix-stale-nfs-remount branch from 7f2a9ee to 3e7f21b Compare April 19, 2026 02:25
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 19, 2026
@andyzhangx andyzhangx requested a review from Copilot April 19, 2026 02:25
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes kubelet applyFSGroup failures after NFS server restarts by detecting stale NFS mounts in NodePublishVolume and forcing an unmount/remount when a stale file handle is detected.

Changes:

  • Add an os.Lstat check on already-mounted target paths to detect stale NFS handles.
  • On ESTALE, unmount the target and proceed with a fresh mount.
  • Introduce a helper (isStaleFileHandle) to classify stale-handle errors.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/nfs/nodeserver.go
Comment thread pkg/nfs/nodeserver.go
- Make os.Lstat injectable via lstatFunc package variable for testability
- Add NodePublishVolume test case covering ESTALE detection -> unmount -> remount
- Add TestIsStaleFileHandle with coverage for ESTALE errno, wrapped errors,
  string matching, and negative cases
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 19, 2026
@andyzhangx
Copy link
Copy Markdown
Member Author

Addressed the review comment — added unit tests for the stale mount detection path in 3ce23a8:

  • Introduced lstatFunc package-level variable (defaults to os.Lstat) so tests can inject errors
  • Added TestNodePublishVolume case that injects syscall.ESTALE, verifies unmount+remount succeeds
  • Added TestIsStaleFileHandle covering ESTALE errno, wrapped ESTALE, string-match variants, and negative cases

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

pkg/nfs/nodeserver_test.go:33

  • This test now imports syscall and uses syscall.ESTALE/ENOENT. Those constants are not available on Windows, so pkg/nfs unit tests may stop compiling on GOOS=windows. If Windows builds are still supported, gate these tests behind build tags (e.g. !windows) or avoid OS-specific errno constants in the test inputs.
import (
	"context"
	"errors"
	"fmt"
	"os"
	"reflect"
	"strings"
	"syscall"
	"testing"

	"github.com/container-storage-interface/spec/lib/go/csi"
	"github.com/kubernetes-csi/csi-driver-nfs/test/utils/testutil"
	"github.com/stretchr/testify/assert"
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/nfs/nodeserver.go
Comment thread pkg/nfs/nodeserver.go
Comment thread pkg/nfs/nodeserver_test.go
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/nfs/nodeserver_test.go
Comment thread pkg/nfs/nodeserver_test.go
@andyzhangx andyzhangx merged commit 1ea4fdd into kubernetes-csi:master Apr 19, 2026
24 of 25 checks passed
@andyzhangx
Copy link
Copy Markdown
Member Author

/cherrypick release-4.13

@k8s-infra-cherrypick-robot
Copy link
Copy Markdown

@andyzhangx: new pull request created: #1109

Details

In response to this:

/cherrypick release-4.13

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants