There's a lot of code in this repo around composite predicate and switching predicates based on object triggering event.
I think its cause we just happen to use EventFilter that applies to all Fors, Watches.
It may be better to get rid of all those complicated logic if you could contain a predicate to within a type of watch.
Perhaps something like below. If we could get rid of at least 10 files out of this would be good.
|
For(&nacv1alpha1.NonAdminDownloadRequest{}, builder.WithPredicates(ctrlPredicate.Funcs{ |
|
// TODO: DeleteFunc: , delete velero download requests? |
|
// Process creates |
|
CreateFunc: func(_ event.TypedCreateEvent[client.Object]) bool { return true }, |
|
// TODO: UpdateFunc: , potentially don't process updates? |
|
// TODO: GenericFunc: , what to do with generic events? |
|
|
|
})). |
|
Named("nonadmindownloadrequest"). |
|
Watches(&velerov1.DownloadRequest{}, handler.Funcs{ |
|
UpdateFunc: func(ctx context.Context, tue event.TypedUpdateEvent[client.Object], rli workqueue.RateLimitingInterface) { |
|
if dr, ok := tue.ObjectNew.(*velerov1.DownloadRequest); ok && dr.Status.DownloadURL != "" { |
|
log := function.GetLogger(ctx, dr, "VeleroDownloadRequestHandler") |
|
log.V(1).Info("DownloadRequest populated with url") |
|
// on update, we need to reconcile NonAdminDownloadRequests to update |
|
rli.Add(reconcile.Request{ |
|
NamespacedName: types.NamespacedName{ |
|
Namespace: constant.NadrOriginNamespaceAnnotation, |
|
Name: constant.NadrOriginNameAnnotation, |
|
}, |
|
}) |
|
} |
|
}, |
|
// DeleteFunc: , TODO: if velero DownloadRequests gets cleaned up, delete this? |
|
}, |
|
). |
There's a lot of code in this repo around composite predicate and switching predicates based on object triggering event.
I think its cause we just happen to use EventFilter that applies to all Fors, Watches.
It may be better to get rid of all those complicated logic if you could contain a predicate to within a type of watch.
Perhaps something like below. If we could get rid of at least 10 files out of this would be good.
oadp-non-admin/internal/controller/nonadmindownloadrequest_controller.go
Lines 84 to 109 in 0df85a8