// Setup adds a controller that schedules KubernetesApplications.
func Setup(mgr ctrl.Manager, l logging.Logger) error {
name := "scheduler/" + strings.ToLower(workloadv1alpha1.KubernetesApplicationGroupKind)
return ctrl.NewControllerManagedBy(mgr).
Named(name).
For(&workloadv1alpha1.KubernetesApplication{}).
WithEventFilter(&predicate.Funcs{CreateFunc: CreatePredicate, UpdateFunc: UpdatePredicate}).
Complete(&Reconciler{
kube: mgr.GetClient(),
scheduler: &roundRobinScheduler{kube: mgr.GetClient()},
log: l.WithValues("controller", name),
})
}
// Funcs is a function that implements Predicate.
type Funcs struct {
// Create returns true if the Create event should be processed
CreateFunc func(event.CreateEvent) bool
// Delete returns true if the Delete event should be processed
DeleteFunc func(event.DeleteEvent) bool
// Update returns true if the Update event should be processed
UpdateFunc func(event.UpdateEvent) bool
// Generic returns true if the Generic event should be processed
GenericFunc func(event.GenericEvent) bool
}
网友评论