Skip to content

fix: support PVC overlays for DM built-in volumes - #7024

Open
fgksgf wants to merge 3 commits into
mainfrom
agent/fix-dm-builtin-pvc-overlays
Open

fix: support PVC overlays for DM built-in volumes#7024
fgksgf wants to merge 3 commits into
mainfrom
agent/fix-dm-builtin-pvc-overlays

Conversation

@fgksgf

@fgksgf fgksgf commented Aug 7, 2026

Copy link
Copy Markdown
Member

Summary

  • Allow DM PVC overlays to target the built-in dataVolume.
  • Allow DMWorker PVC overlays to target the built-in relayVolume.
  • Apply the existing PVC overlay logic to those built-in PVCs without changing PVC specs, ownership, naming, or additional-volume behavior.

Why

ResourceTagger derives EBS cloud tags from tags.tidbcloud.com/* labels on PVCs. O11Y-2632914 identified three DM PVCs without those source labels because Cluster Service could not express PVC overlays for the built-in DM data and relay volumes.

The first E2E runs for this PR failed before executing any specs because Kubernetes rejected the generated DMGroup CRD: the new CEL validation rule exceeded the static cost budget. This update keeps the same validation semantics with a lower-cost expression and adds regression coverage for CRD CEL costs.

How

  • Extend DM and DMWorker CEL validation so overlay names may reference the built-in volume or an additional volume, while unknown names remain invalid.
  • Use singleton-list membership for the built-in volume comparison to stay within the Kubernetes static CEL cost budget.
  • Apply OverlayPersistentVolumeClaim to the built-in master data PVC and worker relay PVC.
  • Remove the consumed built-in overlay from a deep copy before invoking the existing additional-volume PVC builder.
  • Regenerate the four affected DM and DMWorker CRDs.
  • Add validation tests that compile the CEL rules for all four CRDs and enforce the Kubernetes runtime cost budget.

Testing

  • go test ./pkg/controllers/dm/tasks ./pkg/controllers/dmworker/tasks
  • cd tests/validation && go test ./...
  • make lint
  • make crd
  • Regenerated CRDs in a clean detached worktree and confirmed no diff.
  • Applied all generated CRDs to a local Kubernetes API server.
  • Server-side dry-run accepted built-in DM data and DMWorker relay overlays and rejected an unknown overlay name.

make verify/crd was attempted, but its temporary worktree failed before generation because Go resolved the macOS /var path as /private/var and treated the build path as outside the module. The equivalent clean-worktree regeneration check passed.

Risks and Reviewer Focus

  • This extends the legal meaning of an existing CRD field; it does not add a field or modify Pod labels.
  • A compatible Operator version and CRD must be released and deployed before Cluster Service emits built-in DM PVC overlays.
  • Existing PVCs are not backfilled by this change.

Summary by CodeRabbit

  • Bug Fixes

    • PVC overlays now correctly apply to built-in data and relay volumes.
    • Prevented built-in volume overlays from being applied twice when creating additional PVCs.
    • Volume claim validation now accepts overlays targeting built-in or additional volumes.
    • Invalid references to unknown volume claims continue to be rejected.
  • Tests

    • Added coverage for overlay application, validation rules, and invalid volume claim references.

@ti-chi-bot

ti-chi-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign fgksgf for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

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

@github-actions github-actions Bot added the v2 for operator v2 label Aug 7, 2026
@ti-chi-bot ti-chi-bot Bot added the size/L label Aug 7, 2026
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 399a3130-d1e6-4c59-a595-51e159238e75

📥 Commits

Reviewing files that changed from the base of the PR and between ebfa959 and 9f90624.

📒 Files selected for processing (1)
  • tests/validation/validation.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/validation/validation.go

📝 Walkthrough

Walkthrough

The change permits named overlays for built-in data and relay volume claims. DM and DMWorker PVC reconciliation applies these overlays to primary PVCs and excludes them from additional PVC generation. Validation tests cover valid built-in claims, invalid unknown claims, and CEL static costs.

Changes

Volume claim overlays

Layer / File(s) Summary
Built-in volume overlay validation
api/core/v1alpha1/*_types.go, manifests/crd/*dm*.yaml, tests/validation/*
Validation accepts dataVolume or relayVolume claim names in addition to entries in volumes. Unknown claim names remain invalid. Tests also compile CEL rules and check their static cost.
DM PVC overlay application
pkg/controllers/dm/tasks/pvc.go, pkg/controllers/dm/tasks/pvc_test.go
DM PVC generation applies the data volume overlay and removes it from the copied resource before generating additional PVCs. Tests verify labels and annotations.
DMWorker PVC overlay application
pkg/controllers/dmworker/tasks/pvc.go, pkg/controllers/dmworker/tasks/pvc_test.go
DMWorker PVC generation applies the relay volume overlay and removes it from the copied resource before generating additional PVCs. Tests verify both generated PVCs.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant DMResource
  participant DMPVCNewer
  participant PVCOverlay
  participant GeneratedPVCs
  DMResource->>DMPVCNewer: Reconcile PVCs
  DMPVCNewer->>PVCOverlay: Find data volume overlay
  PVCOverlay-->>DMPVCNewer: Return matching overlay
  DMPVCNewer->>GeneratedPVCs: Apply overlay to data PVC
  DMPVCNewer->>GeneratedPVCs: Generate additional PVCs without data overlay
Loading
sequenceDiagram
  participant DMWorkerResource
  participant DMWorkerPVCNewer
  participant PVCOverlay
  participant GeneratedPVCs
  DMWorkerResource->>DMWorkerPVCNewer: Reconcile PVCs
  DMWorkerPVCNewer->>PVCOverlay: Find relay volume overlay
  PVCOverlay-->>DMWorkerPVCNewer: Return matching overlay
  DMWorkerPVCNewer->>GeneratedPVCs: Apply overlay to relay PVC
  DMWorkerPVCNewer->>GeneratedPVCs: Generate additional PVCs without relay overlay
Loading

Suggested reviewers: tennix

Poem

I’m a rabbit with overlays bright,
Data and relay now dress just right.
Claims are checked by name and place,
Extra PVCs keep their space.
Hop, hop—no overlay twice!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding PVC overlay support for DM built-in volumes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch agent/fix-dm-builtin-pvc-overlays

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov-commenter

codecov-commenter commented Aug 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 41.00%. Comparing base (92aa7f6) to head (9f90624).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7024      +/-   ##
==========================================
+ Coverage   40.58%   41.00%   +0.42%     
==========================================
  Files         436      439       +3     
  Lines       25274    25541     +267     
==========================================
+ Hits        10258    10474     +216     
- Misses      15016    15067      +51     
Flag Coverage Δ
unittest 41.00% <100.00%> (+0.42%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@fgksgf
fgksgf requested review from tennix and a balanced review from Copilot August 7, 2026 11:42

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.

Pull request overview

This PR extends the existing PVC overlay mechanism so that DM's built-in dataVolume and DMWorker's built-in relayVolume can be targeted by overlay.volumeClaims, in addition to the previously-supported additional volumes. Previously the CEL validation rejected any overlay whose name did not match an additional volume, which excluded these built-in volumes. The change loosens validation to also accept the built-in volume name and applies the overlay when constructing the built-in PVCs, while removing the consumed overlay entry before delegating to the shared additional-volume builder (which panics on unknown overlay names).

Changes:

  • Broaden the CEL XValidation rule on DMTemplateSpec/DMWorkerTemplateSpec to accept the built-in volume name (dataVolume/relayVolume) or an additional volume name, and regenerate the four affected CRDs.
  • Apply OverlayPersistentVolumeClaim to the built-in data/relay PVCs, and strip the consumed built-in overlay from a deep copy before calling coreutil.PVCs.
  • Add unit tests for overlay application and validation tests for the new/rejected cases.

Reviewed changes

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

Show a summary per file
File Description
api/core/v1alpha1/dm_types.go Updates CEL rule to allow overlays targeting the built-in dataVolume.
api/core/v1alpha1/dmworker_types.go Updates CEL rule to allow overlays targeting the optional built-in relayVolume.
manifests/crd/core.pingcap.com_dms.yaml Regenerated CRD reflecting the DM CEL rule change.
manifests/crd/core.pingcap.com_dmgroups.yaml Regenerated CRD reflecting the DM CEL rule change.
manifests/crd/core.pingcap.com_dmworkers.yaml Regenerated CRD reflecting the DMWorker CEL rule change.
manifests/crd/core.pingcap.com_dmworkergroups.yaml Regenerated CRD reflecting the DMWorker CEL rule change.
pkg/controllers/dm/tasks/pvc.go Applies overlay to the data PVC and removes it from the additional-volume overlay copy.
pkg/controllers/dmworker/tasks/pvc.go Applies overlay to the relay PVC and removes it from the additional-volume overlay copy.
pkg/controllers/dm/tasks/pvc_test.go Adds test verifying data + additional volume overlays are applied.
pkg/controllers/dmworker/tasks/pvc_test.go Adds test verifying relay + additional volume overlays are applied.
tests/validation/dm_test.go Adds validation cases for built-in data overlay acceptance/rejection.
tests/validation/dmworker_test.go Adds validation cases for built-in relay overlay acceptance/rejection.
tests/validation/common_test.go Adds BuiltInVolumeClaimsOverlay helper generating the shared validation cases.

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

@fgksgf

fgksgf commented Aug 10, 2026

Copy link
Copy Markdown
Member Author

/test pull-e2e

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/validation/validation.go`:
- Around line 161-162: In the validation test before the loop over results, add
a non-empty assertion for results with the message “no CEL validation rules
found”. Keep the existing per-result require.Nil check unchanged.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4acab17f-24f8-4341-af1e-82430b830733

📥 Commits

Reviewing files that changed from the base of the PR and between efa42a2 and ebfa959.

📒 Files selected for processing (9)
  • api/core/v1alpha1/dm_types.go
  • api/core/v1alpha1/dmworker_types.go
  • manifests/crd/core.pingcap.com_dmgroups.yaml
  • manifests/crd/core.pingcap.com_dms.yaml
  • manifests/crd/core.pingcap.com_dmworkergroups.yaml
  • manifests/crd/core.pingcap.com_dmworkers.yaml
  • tests/validation/dm_test.go
  • tests/validation/dmworker_test.go
  • tests/validation/validation.go
🚧 Files skipped from review as they are similar to previous changes (6)
  • api/core/v1alpha1/dm_types.go
  • api/core/v1alpha1/dmworker_types.go
  • manifests/crd/core.pingcap.com_dmgroups.yaml
  • manifests/crd/core.pingcap.com_dms.yaml
  • manifests/crd/core.pingcap.com_dmworkergroups.yaml
  • manifests/crd/core.pingcap.com_dmworkers.yaml

Comment thread tests/validation/validation.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L v2 for operator v2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants