Skip to content

Align primary VolRep PVC processing with secondary flow - #2592

Closed
ELENAGER wants to merge 1 commit into
RamenDR:mainfrom
ELENAGER:refactor-primary-PVC-handling
Closed

Align primary VolRep PVC processing with secondary flow#2592
ELENAGER wants to merge 1 commit into
RamenDR:mainfrom
ELENAGER:refactor-primary-PVC-handling

Conversation

@ELENAGER

@ELENAGER ELENAGER commented Jun 7, 2026

Copy link
Copy Markdown
Member

Primary reconciliation used processPVCsAsPrimary to handle all PVCs in one function, while secondary already processed each PVC via processPVCAsSecondary. Refactor primary to follow the same pattern: reconcileVolRepsAsPrimary loops per PVC, delegates to processPVCAsPrimary, and uses reconcilePVCVRAsPrimary for VR-specific work (mirroring reconcilePVCVRAsSecondary).

Summary by CodeRabbit

  • Refactor
    • Streamlined primary-side volume replication reconciliation with clearer, centralized per-volume decision logic and consistent handling for related CG-enabled volumes.
    • Improved primary VR processing behavior with standardized requeue/skip outcomes, more reliable destination-volume handle annotation, and consistent PV/PVC object upload handling during reconciliation.
  • User Impact
    • No user-facing changes or configuration updates; this release focuses on internal improvements only.

@coderabbitai

coderabbitai Bot commented Jun 7, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Refactors primary-side PVC processing: extracts per-PVC logic into processPVCAsPrimary, wraps VR handling in reconcilePVCVRAsPrimary, and moves grouped-CG reconciliation into the main loop.

Changes

Primary-side PVC Processing Refactoring

Layer / File(s) Summary
Primary PVC loop and per-PVC delegation
internal/controller/vrg_volrep.go
reconcileVolRepsAsPrimary now owns groupPVCs, iterates PVCs, and delegates per-PVC handling to processPVCAsPrimary, then reconciles grouped volume-group reps once after the loop.
Per-PVC primary decision helper
internal/controller/vrg_volrep.go
processPVCAsPrimary centralizes per-PVC logic: handle deleted/unprotect, update protected-PVC state, preparePVCForVRProtection (requeue/skip), group CG-enabled PVCs, or proceed to VR processing for non-CG PVCs.
VR processing and storage sync flow
internal/controller/vrg_volrep.go
reconcilePVCVRAsPrimary wraps processVRAsPrimary, requeues on VR-processing signals, annotates PV with destination-volume-handle from VR status, and uploads PV/PVC to S3 stores with requeue on failures.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • RamenDR/ramen#2595: Adds the volumegroupreplication-owner labeling that supplies the grouping key used by this PR to organize CG-enabled PVCs during primary reconciliation.

Suggested reviewers

  • ShyamsundarR
  • raghavendra-talur
  • BenamarMk
  • asn1809
  • nirs
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main refactoring work: aligning the primary VolRep PVC processing pattern with the secondary flow to improve consistency and maintainability.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

Comment thread internal/controller/vrg_volrep.go Outdated
if v.pvcUnprotectVolRepIfDeleted(*pvc, log) {
continue
}
v.processPVCAsPrimary(pvc, pvcNamespacedName, log, groupPVCs)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Using in-out paramters is not recommended, instead functions should return appropriate values.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I agree that returning values would be cleaner than using in-out parameters.

The main purpose of this PR was to synchronize the primary and secondary PVC processing flows, and that goal has been achieved. To avoid increasing the scope of this PR, I suggest we handle this improvement in a follow-up PR.

@ELENAGER
ELENAGER force-pushed the refactor-primary-PVC-handling branch from 3310ab0 to a352612 Compare June 8, 2026 12:39
Comment on lines -127 to +116
pvcNamespacedName := types.NamespacedName{Name: pvc.Name, Namespace: pvc.Namespace}
log := v.log.WithValues("pvc", pvcNamespacedName.String())
log := logWithPvcName(v.log, pvc)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks like a refactor that is out of scope for this PR. Maybe could be in a separate commit.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not exactly. My goal was to align the Primary and Secondary flows as closely as possible. In the Secondary flow, we initialize the logger using the logWithPvcName function.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

OK

@ELENAGER
ELENAGER requested review from asn1809 and raaizik June 9, 2026 15:01
@ELENAGER
ELENAGER force-pushed the refactor-primary-PVC-handling branch 2 times, most recently from 4d67a24 to 88c7064 Compare June 16, 2026 11:26
Primary reconciliation used processPVCsAsPrimary to handle all PVCs in
one function, while secondary already processed each PVC via
processPVCAsSecondary. Refactor primary to follow the same pattern:
reconcileVolRepsAsPrimary loops per PVC, delegates to processPVCAsPrimary,
and uses reconcilePVCVRAsPrimary for VR-specific work (mirroring
reconcilePVCVRAsSecondary).

Signed-off-by: Elena Gershkovich <elenage@il.ibm.com>
@ELENAGER
ELENAGER force-pushed the refactor-primary-PVC-handling branch from 88c7064 to 3bbe3a9 Compare June 16, 2026 11:27
@ELENAGER ELENAGER closed this Aug 13, 2026
@ELENAGER
ELENAGER deleted the refactor-primary-PVC-handling branch August 13, 2026 12:57
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.

3 participants