Skip to content

Investigate getting rid of CompositePredicate #241

@kaovilai

Description

@kaovilai

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?
},
).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions