Skip to content

Commit

Permalink
VolumeReplicationGroupReconciler must watch VolumeGroupReolication re…
Browse files Browse the repository at this point in the history
…sources

Signed-off-by: Elena Gershkovich <[email protected]>
  • Loading branch information
ELENAGER committed Oct 1, 2024
1 parent 6123107 commit ca3299c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
20 changes: 20 additions & 0 deletions internal/controller/volumereplicationgroup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ type VolumeReplicationGroupReconciler struct {
}

// SetupWithManager sets up the controller with the Manager.
//
// nolint: funlen
func (r *VolumeReplicationGroupReconciler) SetupWithManager(
mgr ctrl.Manager, ramenConfig *ramendrv1alpha1.RamenConfig,
) error {
Expand Down Expand Up @@ -97,6 +99,10 @@ func (r *VolumeReplicationGroupReconciler) SetupWithManager(
handler.EnqueueRequestsFromMapFunc(r.VRMapFunc),
builder.WithPredicates(rmnutil.CreateOrDeleteOrResourceVersionUpdatePredicate{}),
).
Watches(&volrep.VolumeGroupReplication{},
handler.EnqueueRequestsFromMapFunc(r.VGRMapFunc),
builder.WithPredicates(rmnutil.CreateOrDeleteOrResourceVersionUpdatePredicate{}),
).
Watches(&corev1.ConfigMap{}, handler.EnqueueRequestsFromMapFunc(r.configMapFun)).
Owns(&volrep.VolumeReplication{}).
Owns(&volrep.VolumeGroupReplication{})
Expand Down Expand Up @@ -1558,6 +1564,20 @@ func filterVRGDependentObjects(reader client.Reader, obj client.Object, log logr
return req
}

func (r *VolumeReplicationGroupReconciler) VGRMapFunc(ctx context.Context, obj client.Object) []reconcile.Request {
log := ctrl.Log.WithName("vgrmap").WithName("VolumeReplicationGroup")

vgr, ok := obj.(*volrep.VolumeGroupReplication)
if !ok {
log.Info("map function received non-vgr resource")

return []reconcile.Request{}
}

return filterVRGDependentObjects(r.Client, obj,
log.WithValues("vgr", types.NamespacedName{Name: vgr.Name, Namespace: vgr.Namespace}))
}

func (r *VolumeReplicationGroupReconciler) VRMapFunc(ctx context.Context, obj client.Object) []reconcile.Request {
log := ctrl.Log.WithName("vrmap").WithName("VolumeReplicationGroup")

Expand Down
14 changes: 7 additions & 7 deletions internal/controller/vrg_volrep.go
Original file line number Diff line number Diff line change
Expand Up @@ -1564,7 +1564,7 @@ func (v *VRGInstance) validateVRStatus(pvc *corev1.PersistentVolumeClaim, volRep
) bool {
// Check validated for primary during VRG deletion.
if state == ramendrv1alpha1.Primary && rmnutil.ResourceIsDeleted(v.instance) {
validated, ok := v.validateVRValidatedStatus(volRep)
validated, ok := v.validateVRValidatedStatus(volRep, status)
if !validated && ok {
v.log.Info(fmt.Sprintf("VolumeReplication %s/%s failed validation and can be deleted",
volRep.GetName(), volRep.GetNamespace()))
Expand All @@ -1574,16 +1574,16 @@ func (v *VRGInstance) validateVRStatus(pvc *corev1.PersistentVolumeClaim, volRep
}

// Check completed for both primary and secondary.
if !v.validateVRCompletedStatus(pvc, volRep, state) {
if !v.validateVRCompletedStatus(pvc, volRep, state, status) {
return false
}

// if primary, all checks are completed.
if state == ramendrv1alpha1.Secondary {
return v.validateAdditionalVRStatusForSecondary(pvc, volRep)
return v.validateAdditionalVRStatusForSecondary(pvc, volRep, status)
}

msg = "PVC in the VolumeReplicationGroup is ready for use"
msg := "PVC in the VolumeReplicationGroup is ready for use"
v.updatePVCDataReadyCondition(pvc.Namespace, pvc.Name, VRGConditionReasonReady, msg)
v.updatePVCDataProtectedCondition(pvc.Namespace, pvc.Name, VRGConditionReasonReady, msg)
v.updatePVCLastSyncTime(pvc.Namespace, pvc.Name, status.LastSyncTime)
Expand All @@ -1600,9 +1600,9 @@ func (v *VRGInstance) validateVRStatus(pvc *corev1.PersistentVolumeClaim, volRep
// - validated: true if the condition is true, otherwise false
// - ok: true if the check was succeesfull, false if the condition is missing, stale, or unknown.
func (v *VRGInstance) validateVRValidatedStatus(
volRep client.Object,
volRep client.Object, status *volrep.VolumeReplicationStatus,
) (bool, bool) {
conditionMet, errorMsg := isVRConditionMet(volRep, volrep.ConditionValidated, metav1.ConditionTrue)
conditionMet, errorMsg := isVRConditionMet(volRep, status, volrep.ConditionValidated, metav1.ConditionTrue)
if errorMsg != "" {
v.log.Info(fmt.Sprintf("%s (VolRep: %s/%s)", errorMsg, volRep.GetName(), volRep.GetNamespace()))
}
Expand All @@ -1614,7 +1614,7 @@ func (v *VRGInstance) validateVRValidatedStatus(
// the PVC DataReady and Protected conditions.
// Returns true if the condtion is true, false if the condition is missing, stale, ubnknown, of false.
func (v *VRGInstance) validateVRCompletedStatus(pvc *corev1.PersistentVolumeClaim, volRep client.Object,
state ramendrv1alpha1.ReplicationState,
state ramendrv1alpha1.ReplicationState, status *volrep.VolumeReplicationStatus,
) bool {
var (
stateString string
Expand Down

0 comments on commit ca3299c

Please sign in to comment.