Repository navigation
Conversation
Add the trident.netapp.io/shareToNamespaceSelector annotation for source PVCs. When it is set, a new subordinate volume is allowed only if the labels of its namespace match the Kubernetes label selector in the annotation. The namespace is read from the Kubernetes API when the subordinate volume configuration is validated, so removing a required label denies subsequent provisioning. Existing subordinate volumes and mounts are not affected. The selector is an alternative to trident.netapp.io/shareToNamespace. A source PVC that carries both annotations is rejected with an error that names the source PVC and asks the user to set only one of them. Empty or invalid selectors and namespace lookup failures also deny sharing. Behavior is unchanged when the selector annotation is absent, and the subordinate PVC still requires shareFromPVC and a TridentVolumeReference. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Change description
Add namespace label selector for cross-namespace volume sharing
Add the
trident.netapp.io/shareToNamespaceSelectorannotation for source PVCs. When it is set, a new subordinate volume is allowed only if the labels of its namespace match the Kubernetes label selector in the annotation. The namespace is read from the Kubernetes API when the subordinate volume configuration is validated, so removing a required label denies subsequent provisioning. Existing subordinate volumes and mounts are not affected.The selector is an alternative to
trident.netapp.io/shareToNamespace, as suggested in #1196. A source PVC that carries both annotations is rejected with an error that names the source PVC and asks the user to set only one of them. Empty or invalid selectors and namespace lookup failures also deny sharing. Behavior is unchanged when the selector annotation is absent, and the subordinate PVC still requiresshareFromPVCand aTridentVolumeReference.Project tracking
Related issue: #1196
This is an external contribution, and I do not have access to NetApp's Jira. The feature is tracked in GitHub issue #1196.
Do any added TODOs have an issue in the backlog?
No TODOs were added.
Did you add unit tests? Why not?
Yes, in
frontend/csi/controller_helpers/kubernetes/helper_test.go:TestValidateNamespaceSharing: 19 policy cases. These cover legacyshareToNamespacebehavior, selector-only matching, mismatched and missing labels, empty, whitespace, and invalid selectors, set, existence, and negative expressions, and six cases where both annotations are set. The test also verifies that the Namespace API is not called for legacy, conflicting, or invalid policies.TestValidateNamespaceSharing_ConflictMessage: the error identifies the source PVC, the destination namespace, both annotations, and the required action.TestValidateNamespaceSharing_NamespaceErrors: NotFound, Forbidden, and timeout errors from the Namespace lookup deny sharing and preserve the API error.TestValidateSubordinateVolumeConfig_NamespaceSelector: the full subordinate validation path using PVC, PV, and TVR caches with a fake client. It covers selector-only success, the existing storage-class, binding, and TVR checks, rejection when both annotations are added, and label removal and restoration.These checks passed locally with Go 1.27.3 on this branch:
Does this code need functional testing?
Yes. The following scenarios on an NFS backend that supports volume sharing:
ProvisioningFailedevent. The existing subordinate PVC and its mounts keep working.I have not yet run these on a live cluster. Only the unit tests above have been run.
Is a code review walkthrough needed? why or why not?
Probably not. The change is limited to
validateSubordinateVolumeConfigand a new helper,validateNamespaceSharing, in the Kubernetes controller helper. I am happy to walk through it if that would help.Should additional test coverage be executed in addition to pre-merge?
Please also run the existing cross-namespace volume sharing scenarios with
shareToNamespaceonly, to confirm that legacy behavior is unchanged.Does this code need a note in the changelog?
Yes. I cannot set labels on this repository, so could a maintainer please add
needs-changelog?Changelog
Added the
trident.netapp.io/shareToNamespaceSelectorsource PVC annotation, which allows a volume to be shared with namespaces whose labels match a Kubernetes label selector.Does this code require documentation changes?
Yes. The cross-namespace sharing page (
trident-use/volume-share.adocin NetAppDocs/trident) should describe the new annotation, its mutual exclusion withshareToNamespace, and the fact that label removal affects only new provisioning. I can open a PR there if the code change is accepted.Additional Information
CreateVolumeretries for volumes that already exist are not revoked. Cross-namespace clone authorization is unchanged.team notin (red)also match namespaces that have noteamlabel. Only trusted administrators should be able to set the labels used to authorize sharing.geton namespaces. No new permissions or informers are added, andgo.modis unchanged.Co-authored-bytrailer, a note in the PR description, or neither, or any restrictions I should follow? The commit currently includes aCo-Authored-By: Claudetrailer, and I am happy to adjust or remove it.