@@ -60,7 +60,7 @@ import (
6060 viper "github.com/apecloud/kubeblocks/pkg/viperx"
6161)
6262
63- // VolumePopulatorReconciler reconciles Backup dataSource PVCs.
63+ // VolumePopulatorReconciler coordinates data population and restore for PVCs.
6464type VolumePopulatorReconciler struct {
6565 client.Client
6666 Scheme * runtime.Scheme
@@ -93,11 +93,7 @@ type pvcRestoreDecision struct {
9393// +kubebuilder:rbac:groups=apps.kubeblocks.io,resources=components,verbs=get;list;watch
9494// +kubebuilder:rbac:groups=apps.kubeblocks.io,resources=componentdefinitions,verbs=get;list;watch
9595
96- // Reconcile is part of the main kubernetes reconciliation loop which aims to
97- // move the current state of the cluster closer to the desired state.
98- //
99- // For more details, check Reconcile and its Result here:
100- // - https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.11.0/pkg/reconcile
96+ // Reconcile advances a PVC's population and restore lifecycle.
10197func (r * VolumePopulatorReconciler ) Reconcile (ctx context.Context , req ctrl.Request ) (ctrl.Result , error ) {
10298 reqCtx := intctrlutil.RequestCtx {
10399 Ctx : ctx ,
@@ -185,9 +181,9 @@ func (r *VolumePopulatorReconciler) mapRestoreToPVCs(ctx context.Context, obj cl
185181 }
186182 includeTerminal := ! restore .DeletionTimestamp .IsZero () ||
187183 restore .Status .Phase == dpv1alpha1 .RestorePhaseCompleted || restore .Status .Phase == dpv1alpha1 .RestorePhaseFailed
188- // A postReady Restore is owned by its target Component, while its labels
189- // identify only the first source PVC that created it . Other Components in
190- // the Cluster can wait on the same Restore through postReady redirection.
184+ // The component-name label identifies the first source PVC's Component,
185+ // while the owner reference identifies the target Component . Other
186+ // Components can wait on the same Restore through postReady redirection.
191187 return r .mapRestorePVCs (ctx , restore .Namespace , client.MatchingLabels {
192188 constant .AppInstanceLabelKey : clusterName ,
193189 }, restore .Labels [dptypes .ClusterUIDLabelKey ], includeTerminal )
@@ -203,10 +199,9 @@ func (r *VolumePopulatorReconciler) mapComponentToPVCs(ctx context.Context, obj
203199 if clusterName == "" || componentName == "" {
204200 return nil
205201 }
206- // A PVC can depend on another Component through a redirected postReady
207- // Restore. That relationship is derived from Backup status and is not
208- // represented on the Component, so a Component event must fan out to all
209- // active restore PVCs in its Cluster.
202+ // Normal Component updates can unblock redirected postReady restores in
203+ // other Components. Fan out to unfinished restore PVCs in the Cluster,
204+ // since those dependencies are not represented on the Component itself.
210205 labels := client.MatchingLabels {
211206 constant .AppInstanceLabelKey : clusterName ,
212207 }
@@ -216,8 +211,8 @@ func (r *VolumePopulatorReconciler) mapComponentToPVCs(ctx context.Context, obj
216211 }
217212 includeTerminal := ! comp .DeletionTimestamp .IsZero ()
218213 if includeTerminal {
219- // Component deletion is a termination signal only for restore PVCs
220- // physically owned by that Component .
214+ // Deletion targets this Component's restore PVCs, including terminal
215+ // PVCs that may still have restore resources to clean up .
221216 labels [constant .KBAppComponentLabelKey ] = componentName
222217 }
223218 return r .mapRestorePVCs (ctx , comp .Namespace , labels , string (clusterOwner .UID ), includeTerminal )
@@ -423,9 +418,10 @@ func (r *VolumePopulatorReconciler) syncPVC(reqCtx intctrlutil.RequestCtx, pvc *
423418 return nil
424419}
425420
426- // handleRestoreParentLifecycle makes Cluster and Component dependencies part of
427- // the PVC restore state machine. Parent deletion is the only cancellation
428- // signal; the target PVC deletion timestamp is intentionally irrelevant.
421+ // handleRestoreParentLifecycle validates parent identity and protection, and
422+ // initiates restore termination when the Cluster or Component is deleting.
423+ // It returns true when normal restore processing should stop. Target PVC
424+ // deletion alone does not request restore termination.
429425func (r * VolumePopulatorReconciler ) handleRestoreParentLifecycle (reqCtx intctrlutil.RequestCtx ,
430426 pvc * corev1.PersistentVolumeClaim ) (bool , error ) {
431427 clusterName := pvc .Labels [constant .AppInstanceLabelKey ]
@@ -438,15 +434,13 @@ func (r *VolumePopulatorReconciler) handleRestoreParentLifecycle(reqCtx intctrlu
438434 cluster := & appsv1.Cluster {}
439435 clusterKey := types.NamespacedName {Namespace : pvc .Namespace , Name : clusterName }
440436 if err := r .Client .Get (reqCtx .Ctx , clusterKey , cluster ); err != nil {
441- // Unmarked PVCs may be standalone DP restores that happen to use app
442- // labels. Marked PVCs are known Cluster restores and must retry .
437+ // App labels alone do not establish Cluster restore identity;
438+ // standalone DP restores may use the same labels .
443439 if apierrors .IsNotFound (err ) && ! hasClusterIdentity {
444440 return false , nil
445441 }
446- // A retained target PVC can outlive its Cluster after its VP-owned
447- // finalizer and side effects have been released. Do not restart or poll
448- // the completed cancellation path merely because App-owned restore
449- // identity remains on that PVC.
442+ // Do not restart a retained target after its Cluster is gone and VP
443+ // has released the target finalizer.
450444 if apierrors .IsNotFound (err ) &&
451445 ! controllerutil .ContainsFinalizer (pvc , dptypes .DataProtectionFinalizerName ) {
452446 return true , nil
0 commit comments