diff --git a/pkg/controller/backup_repository_controller.go b/pkg/controller/backup_repository_controller.go index 968c0348cd..fc640dcef8 100644 --- a/pkg/controller/backup_repository_controller.go +++ b/pkg/controller/backup_repository_controller.go @@ -76,7 +76,12 @@ func (r *BackupRepoReconciler) SetupWithManager(mgr ctrl.Manager) error { For(&velerov1api.BackupRepository{}). Watches(s, nil). Watches(&source.Kind{Type: &velerov1api.BackupStorageLocation{}}, kube.EnqueueRequestsFromMapUpdateFunc(r.invalidateBackupReposForBSL), - builder.WithPredicates(kube.NewCreateOrUpdateEventPredicate(r.needInvalidBackupRepo))). + builder.WithPredicates( + // When BSL updates, check if the backup repositories need to be invalidated + kube.NewUpdateEventPredicate(r.needInvalidBackupRepo), + // When BSL is created, invalidate any backup repositories that reference it + kube.NewCreateEventPredicate(func (client.Object) bool{return true}, + ))). Complete(r) } @@ -104,16 +109,8 @@ func (r *BackupRepoReconciler) invalidateBackupReposForBSL(bslObj client.Object) return []reconcile.Request{} } -// needInvalidBackupRepo returns true if the BSL's storage type, bucket, prefix, CACert, or config has changed or if BSL was created. +// needInvalidBackupRepo returns true if the BSL's storage type, bucket, prefix, CACert, or config has changed func (r *BackupRepoReconciler) needInvalidBackupRepo(oldObj client.Object, newObj client.Object) bool { - if oldObj == nil { - // BSL was created because oldBSL is nil - // Return true so invalidateBackupReposForBSL is triggered - // BSL creationTimestamp should be newer than the BackupRepository's creationTimestamp if any. - // BSL was created after the BackupRepository, so we need to re-establish the BackupRepository on BSL creation. - return true - } - oldBSL := oldObj.(*velerov1api.BackupStorageLocation) newBSL := newObj.(*velerov1api.BackupStorageLocation) diff --git a/pkg/util/kube/predicate.go b/pkg/util/kube/predicate.go index 637c928195..9ac9d9894e 100644 --- a/pkg/util/kube/predicate.go +++ b/pkg/util/kube/predicate.go @@ -93,25 +93,6 @@ func NewUpdateEventPredicate(f func(client.Object, client.Object) bool) predicat } } -// NewCreateOrUpdateEventPredicate creates a new Predicate that checks the create or update events with the provided func -// and ignore others -func NewCreateOrUpdateEventPredicate(f func(client.Object, client.Object) bool) predicate.Predicate { - return predicate.Funcs{ - UpdateFunc: func(event event.UpdateEvent) bool { - return f(event.ObjectOld, event.ObjectNew) - }, - CreateFunc: func(event event.CreateEvent) bool { - return f(nil, event.Object) - }, - DeleteFunc: func(event event.DeleteEvent) bool { - return false - }, - GenericFunc: func(event event.GenericEvent) bool { - return false - }, - } -} - // FalsePredicate always returns false for all kinds of events type FalsePredicate struct{}