Skip to content

fix: treat empty existing mount as stale in ensureMountPoint - #2025

Open
OS-gustavosalvador wants to merge 4 commits into
kubernetes-sigs:mainfrom
OS-gustavosalvador:fix/1051-stale-empty-mount
Open

fix: treat empty existing mount as stale in ensureMountPoint#2025
OS-gustavosalvador wants to merge 4 commits into
kubernetes-sigs:mainfrom
OS-gustavosalvador:fix/1051-stale-empty-mount

Conversation

@OS-gustavosalvador

@OS-gustavosalvador OS-gustavosalvador commented Apr 23, 2026

Copy link
Copy Markdown

What type of PR is this?

/kind bug

What this PR does / why we need it:

On Linux, ensureMountPoint returned mounted=true for any existing mount whose directory could be read; no content check.

If NodePublishVolume was interrupted between mounting the tmpfs and writing the provider's files (driver pod killed, context cancelled), the empty tmpfs persisted. The retry short-circuited on "already mounted" and the pod started with an empty secrets directory. Readiness never recovered without manual intervention.

The fix: if the existing mount is empty, unmount it and return mounted=false so the caller performs a fresh mount. The Windows branch below already enforces the same contract via a different mechanism.

Reproduced in a local k3d cluster by killing the driver pod mid-Mount. Same branch with utils.go reverted to its parent: 0/3 runs recover. With the fix: 5/5 runs Ready within seconds of the next retry, zero restarts.

Which issue(s) this PR fixes:

Fixes #1051

TODOs:

  • squashed commits
  • includes documentation
  • adds unit tests

@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. labels Apr 23, 2026
@k8s-ci-robot
k8s-ci-robot requested review from aramase and enj April 23, 2026 15:45
@k8s-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: OS-gustavosalvador
Once this PR has been reviewed and has the lgtm label, please assign aramase for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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 needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Apr 23, 2026
@k8s-ci-robot

Copy link
Copy Markdown
Contributor

This issue is currently awaiting triage.

If secrets-store-csi-driver contributors determine this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Details

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.

@k8s-ci-robot

Copy link
Copy Markdown
Contributor

Welcome @OS-gustavosalvador!

It looks like this is your first PR to kubernetes-sigs/secrets-store-csi-driver 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/secrets-store-csi-driver has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@linux-foundation-easycla

linux-foundation-easycla Bot commented Apr 23, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: OS-gustavosalvador / name: OS-gustavosalvador (8ef87d1)

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Apr 23, 2026
@k8s-ci-robot

Copy link
Copy Markdown
Contributor

Hi @OS-gustavosalvador. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

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.

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. 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. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Apr 23, 2026
@OS-gustavosalvador
OS-gustavosalvador force-pushed the fix/1051-stale-empty-mount branch from 8ef87d1 to de8cc58 Compare April 23, 2026 16:11
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Apr 23, 2026
@enj enj moved this to Subprojects - Needs Triage in SIG Auth Apr 28, 2026
@enj enj added this to SIG Auth Apr 28, 2026

@stlaz stlaz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pre-review: please reduce the cognitive load of the PR for maintainers by hand-rewriting all of What this PR does / why we need it: and Special notes for your reviewer: and the code comments and the commit message.

Remove issue links from the code comments.

@github-project-automation github-project-automation Bot moved this from Subprojects - Needs Triage to Changes Requested in SIG Auth Jun 24, 2026
@kubernetes-prow

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: OS-gustavosalvador
Once this PR has been reviewed and has the lgtm label, please assign aramase for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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

On Linux, when the target is already mounted, check whether the
directory is empty and unmount it if so, so the caller performs a
fresh mount. Matches the contract the Windows branch already
enforces and prevents the retry from reporting success on a stale
empty tmpfs left by an interrupted NodePublishVolume.

Signed-off-by: Gustavo Salvador <gustavo.salvador@outsystems.com>
@OS-gustavosalvador
OS-gustavosalvador force-pushed the fix/1051-stale-empty-mount branch from de8cc58 to 8c5af2b Compare June 25, 2026 12:44
@OS-gustavosalvador

Copy link
Copy Markdown
Author

thanks @stlaz, adjusted as suggested 👍

@OS-gustavosalvador
OS-gustavosalvador requested a review from stlaz June 25, 2026 12:46

@stlaz stlaz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm kind of new to the code base, curious what @aramase thinks here.

Comment thread pkg/secrets-store/utils.go Outdated
@stlaz

stlaz commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

/ok-to-test

@kubernetes-prow kubernetes-prow Bot added the ok-to-test Indicates a non-member PR verified by an org member that is safe to test. label Jun 29, 2026
@kubernetes-prow kubernetes-prow Bot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jun 29, 2026
Signal mount state to the caller instead of unmounting; the caller
reuses the existing tmpfs and re-calls the provider.

Signed-off-by: Gustavo Salvador <gustavo.salvador@outsystems.com>
@OS-gustavosalvador

Copy link
Copy Markdown
Author

/retest

Signed-off-by: OS-gustavosalvador <gustavo.salvador@outsystems.com>
@OS-gustavosalvador

Copy link
Copy Markdown
Author

/retest

@OS-gustavosalvador
OS-gustavosalvador requested a review from stlaz July 7, 2026 13:02

@stlaz stlaz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

looks good, mostly nits

Comment thread pkg/secrets-store/nodeserver.go Outdated
// If it is mounted, it means this is not the first time mount request for this path.
isRemountRequest = mounted
// An empty existing mount is a previous interrupted call, not a remount.
isRemountRequest = mounted && hasContent

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

it's only remount request if it's mounted, original was more accurate.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

also looking at how the var is used elsewhere, adding "hasContent" might be wrong I think?

Comment thread pkg/secrets-store/nodeserver.go Outdated
Comment on lines 157 to 159
if !rotationEnabled && isRemountRequest {
klog.InfoS("target path is already mounted", "targetPath", targetPath, "pod", klog.ObjectRef{Namespace: podNamespace, Name: podName})
skipped = true

@stlaz stlaz Aug 20, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
if !rotationEnabled && isRemountRequest {
klog.InfoS("target path is already mounted", "targetPath", targetPath, "pod", klog.ObjectRef{Namespace: podNamespace, Name: podName})
skipped = true
if !rotationEnabled && mounted && hasContent {
klog.InfoS("target path is already mounted and populated", "targetPath", targetPath, "pod", klog.ObjectRef{Namespace: podNamespace, Name: podName})
skipped = true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@aramase is there any possibility that no content is the actual desired state?

return !notMnt, nil
entries, readErr := os.ReadDir(target)
if readErr == nil {
return true, len(entries) > 0, nil

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

let's maybe keep the original log line but move it to V(4)

Comment thread pkg/secrets-store/utils.go Outdated
// instead check if the dir exists for windows and if it's not empty
// If there are contents in the dir, then objects are already mounted
f, err := os.ReadDir(target)
// IsLikelyNotMountPoint always returns notMnt=true on Windows;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

keep the original comment

Comment thread pkg/secrets-store/utils.go Outdated
// ensureMountPoint ensures mount point is valid
func (ns *nodeServer) ensureMountPoint(target string) (bool, error) {
// ensureMountPoint reports whether the target is mounted and whether
// it has any content. The caller decides whether to mount, populate,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

don't make assumptions on what the caller wants to do with the return vals in the docs here

Signed-off-by: OS-gustavosalvador <gustavo.salvador@outsystems.com>
@OS-gustavosalvador

Copy link
Copy Markdown
Author

thanks again @stlaz, updated the code👍

@OS-gustavosalvador

Copy link
Copy Markdown
Author

/retest

@kubernetes-prow

Copy link
Copy Markdown

@OS-gustavosalvador: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-secrets-store-csi-driver-image-scan fbc5bf3 link false /test pull-secrets-store-csi-driver-image-scan

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Details

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. I understand the commands that are listed here.

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

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Apparent race condition causes pods to mount secret volumes with no object content

5 participants