Skip to content

Commit

Permalink
fix pvc reclaimspace & keyrotation annotation filter
Browse files Browse the repository at this point in the history
This commit adds a check in StorageClass event handler
to filter out PVC not needed for Reconcile.

- If SC has only ReclaimSpace annotation, PVCs with ReclaimSpace
  annotation will be skipped.
- If SC has only KeyRotation annotation, PVCs with KeyRotation
  annotation will be skipped.
- If SC has both the ReclaimSpace and KeyRotation annotations,
  PVCs without either annotation or having any one of them will be enqueued.

Signed-off-by: Praveen M <[email protected]>
  • Loading branch information
iPraveenParihar committed Aug 13, 2024
1 parent ff53353 commit 0aeb5eb
Showing 1 changed file with 31 additions and 9 deletions.
40 changes: 31 additions & 9 deletions internal/controller/csiaddons/persistentvolumeclaim_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,14 @@ func (r *PersistentVolumeClaimReconciler) determineScheduleAndRequeue(
// storageClassEventHandler returns an EventHandler that responds to changes
// in StorageClass objects and generates reconciliation requests for all
// PVCs associated with the changed StorageClass.
// PVCs with rsCronJobScheduleTimeAnnotation are not enqueued.
//
// PVCs are enqueued for reconciliation if one of the following is true -
// - If the StorageClass has only ReclaimSpace annotation,
// PVCs without ReclaimSpace annotations will be enqueued.
// - If the StorageClass has only KeyRotation annotation,
// PVCs without the KeyRotation annotation will be enqueued.
// - If the StorageClass has both the ReclaimSpace and KeyRotation annotations,
// PVCs without either annotation or having any one of them will be enqueued.
func (r *PersistentVolumeClaimReconciler) storageClassEventHandler() handler.EventHandler {
return handler.EnqueueRequestsFromMapFunc(
func(ctx context.Context, obj client.Object) []reconcile.Request {
Expand All @@ -312,17 +319,32 @@ func (r *PersistentVolumeClaimReconciler) storageClassEventHandler() handler.Eve
return nil
}

_, scHasReclaimSpaceAnnotation := obj.GetAnnotations()[rsCronJobScheduleTimeAnnotation]
_, scHasKeyRotationAnnotation := obj.GetAnnotations()[krcJobScheduleTimeAnnotation]

var requests []reconcile.Request
for _, pvc := range pvcList.Items {
if _, ok := pvc.GetAnnotations()[rsCronJobScheduleTimeAnnotation]; ok {
continue

_, pvcHasReclaimSpaceAnnotation := pvc.GetAnnotations()[rsCronJobScheduleTimeAnnotation]
_, pvcHasKeyRotationAnnotation := pvc.GetAnnotations()[krcJobScheduleTimeAnnotation]

needToEnqueue := false

if scHasReclaimSpaceAnnotation && !pvcHasReclaimSpaceAnnotation {
needToEnqueue = true
}
if scHasKeyRotationAnnotation && !pvcHasKeyRotationAnnotation {
needToEnqueue = true
}

if needToEnqueue {
requests = append(requests, reconcile.Request{
NamespacedName: types.NamespacedName{
Name: pvc.Name,
Namespace: pvc.Namespace,
},
})
}
requests = append(requests, reconcile.Request{
NamespacedName: types.NamespacedName{
Name: pvc.Name,
Namespace: pvc.Namespace,
},
})
}

return requests
Expand Down

0 comments on commit 0aeb5eb

Please sign in to comment.