Skip to content

Conversation

@deepakkinni
Copy link
Collaborator

What this PR does / why we need it:
This PR implements snapshot limit enforcement for WCP environments to prevent users from exceeding a configurable maximum number of snapshots per volume.

What's Changed:

  • Added support for reading snapshot limit from namespace annotation csi.vsphere.max-snapshots-per-volume
  • Default limit is 4 snapshots per volume, with a hard cap of 32
  • Implemented per-volume mutex to serialize snapshot creation and prevent race conditions
  • Feature is gated behind the snapshot-limit-wcp FSS flag
  • Returns proper error when limit is reached, including current snapshot count

How it Works:
When creating a snapshot, the driver queries existing snapshots for the volume and checks against the configured limit. If the limit would be exceeded, the request is rejected with a FailedPrecondition error. Per-volume locking ensures that concurrent snapshot requests are serialized to prevent race conditions where multiple requests could bypass the limit check.

Which issue this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close that issue when PR gets merged): fixes #

Testing done:
Unit tests.

Unit Tests Added

TestGetSnapshotLimitFromNamespace - Tests for snapshot limit configuration:

  • WhenAnnotationExists_ValidValue - Reads valid limit from namespace annotation
  • WhenAnnotationExists_ValueEqualsMax - Handles limit set to maximum (32)
  • WhenAnnotationExists_ValueExceedsMax - Caps values exceeding 32 with warning
  • WhenAnnotationExists_ValueIsZero - Allows zero limit (disabled)
  • WhenAnnotationExists_ValueIsNegative - Rejects negative values
  • WhenAnnotationExists_InvalidFormat - Handles non-numeric annotation values
  • WhenAnnotationMissing - Uses default limit (4) when annotation is missing
  • WhenNamespaceNotFound - Handles namespace lookup failures
  • WhenK8sClientCreationFails - Handles K8s client initialization errors

TestSnapshotLockManager - Tests for per-volume lock management:

  • AcquireAndRelease_SingleVolume - Basic lock lifecycle
  • AcquireMultipleTimes_SameVolume - Multiple goroutines serialized properly
  • AcquireRelease_MultipleVolumes - Independent locks for different volumes
  • ConcurrentAccess_SameVolume - Concurrent requests properly serialized
  • ReleaseNonExistentLock - Graceful handling of invalid releases

Special notes for your reviewer:

Release note:

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Nov 17, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: deepakkinni

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

The pull request process is described here

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 approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Nov 17, 2025
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Nov 26, 2025
@k8s-ci-robot
Copy link
Contributor

PR needs rebase.

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. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants