Skip to content

fix(csi): enforce create volume capacity limits - #706

Open
jmclong (jmclong) wants to merge 2 commits into
mainfrom
fix/jlong/create-capacity-limit
Open

jmclong (jmclong) wants to merge 2 commits into
mainfrom
fix/jlong/create-capacity-limit

Conversation

@jmclong

@jmclong jmclong (jmclong) commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Reject create requests whose extent/stripe-rounded allocation cannot fit limit_bytes. Check the actual allocation too and return OutOfRange without deleting an unexpectedly oversized LV. Translate wrapped capacity errors to gRPC OutOfRange; matching existing-volume behavior remains unchanged.

Validation

  • go test -race ./internal/csi/core/lvm ./internal/csi/controller -count=1 (with a temporary coverage profile)
  • All commit pre-commit hooks passed.
  • Regression coverage includes exact bounds, striped rounding, missing extent metadata, preservation of an unexpected oversized allocation. The strict mock rejects any removal call.
  • Current branch coverage: core/lvm package 81.7%, EnsureVolume 91.4%, and checkCapacityLimit 100%.
  • Focused mutation testing was not rerun for this follow-up; its earlier permission denial remains a validation limitation.

Scope and limitations

One bug from the mutation audit. The expansion-limit PR will build on this helper. Existing EnsureVolume complexity decreased from 27 to 25; no helper proliferation. LVM analysis used candidate 2.03.23 source, not a proven shipped RPM. Mixed-version rollout/rollback was not runtime-tested; rollback restores the old limit-handling defect.

Concrete scenario

The VG has 4 MiB extents and one PV. A CSI client requests exactly 1 MiB,
including an explicit 1 MiB upper bound:

# CSI CreateVolume request, not a Kubernetes manifest.
name: exact-one-mib
capacity_range:
  required_bytes: 1048576
  limit_bytes: 1048576
volume_capabilities:
  - block: {}
    access_mode:
      mode: SINGLE_NODE_WRITER

Before the fix, lvcreate rounds the allocation to 4 MiB and the first call
succeeds with capacity_bytes: 4194304, exceeding the client's maximum.
Repeating the identical request then finds that 4 MiB LV and returns
AlreadyExists because it does not fit the original range.

With the fix, the preflight rejects the impossible range with OutOfRange
before creating an LV. Changing only limit_bytes to 4194304 permits a
4 MiB allocation. For a two-PV RAID0 VG with 4 MiB extents, the corresponding
regression is a 5 MiB request with a 6 MiB maximum: stripe rounding requires
8 MiB, so creation must be rejected before allocation.

These are direct CSI boundary cases. A PVC's storage request alone does not
reproduce the explicit CSI upper bound; adding resources.limits.storage
is not a substitute for sending this request.

Regression references: TestLVM_Create and TestEnsureVolume.
The review follow-up is included in commit c225379: the post-create check
returns OutOfRange but preserves the LV; it never removes it. Race-enabled unit tests and six direct CSI
checks passed against the changed image in an isolated, linear-only Kind
fixture. The live checks covered impossible exact bounds, permitted rounding,
identical retry, exact extents, and an unlimited upper bound. Unexpected
post-create oversizing and preservation are covered by the strict mock
regression, not by an artificially induced live allocation mismatch.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Limit-only requests with unaligned upper bounds incorrectly return OutOfRange despite a feasible aligned allocation, requiring a normalization fix and regression test.

1 open issue
What changed in this PR

This PR adds capacity-limit enforcement to the driver's LVM-backed volume creation path, checking both predicted and actual allocation sizes.

Changes:

  • Reject allocations whose extent/stripe rounding exceeds the limit, and remove unexpectedly oversized fresh volumes while preserving cleanup errors.
  • Translate wrapped capacity errors to gRPC OutOfRange, leaving existing-volume handling unchanged.
  • Add regression tests and update fake LVM metadata and removal behavior.

Shipped LVM behavior and mixed-version rollout/rollback remain unverified.

File Description
internal/​pkg/​lvm/​fake.go Supplies extent metadata and handles qualified names during removal.
internal/​csi/​core/​lvm/​lvm.go Adds allocation-limit checks and oversized-volume cleanup.
internal/​csi/​core/​lvm/​lvm_test.go Tests stripe rounding, missing metadata, and cleanup outcomes.
internal/​csi/​core/​lvm/​controller_test.go Tests create-capacity boundaries and wrapped errors.
internal/​csi/​controller/​controller.go Maps capacity errors to gRPC OutOfRange.
internal/​csi/​controller/​controller_test.go Verifies the new error mapping.

Review effort: Balanced

Comment on lines +590 to +591
if err := checkCapacityLimit(capacity, limit, vg, int64(vg.PVCount)); err != nil {
return 0, err
jmclong (jmclong) and others added 2 commits November 12, 2026 20:15
Reject impossible extent and stripe rounding before allocation, clean up unexpected oversized new volumes, and return OutOfRange through the controller.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 4b7b1d07-f11e-424c-9e41-dedfe5e59990
Keep the capacity error without deleting the newly allocated LV. Use a strict mock regression to reject any removal call.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 0d8ae189-7c6e-42f6-8133-1109a48b853b
@jmclong
jmclong (jmclong) force-pushed the fix/jlong/create-capacity-limit branch from c225379 to e8b39f6 Compare November 12, 2026 20:23

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants