Skip to content

Commit 7c13832

Browse files
committed
Mark BackupRepository not ready when BSL changed
Mark BackupRepository not ready when BSL changed Fixes #8860 Signed-off-by: Wenkai Yin(尹文开) <yinw@vmware.com>
1 parent bfd9bc5 commit 7c13832

File tree

3 files changed

+20
-45
lines changed

3 files changed

+20
-45
lines changed

changelogs/unreleased/8975-ywk253100

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Mark BackupRepository not ready when BSL changed

pkg/controller/backup_repository_controller.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
apierrors "k8s.io/apimachinery/pkg/api/errors"
3232
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3333
"k8s.io/apimachinery/pkg/labels"
34+
"k8s.io/apimachinery/pkg/types"
3435
clocks "k8s.io/utils/clock"
3536
ctrl "sigs.k8s.io/controller-runtime"
3637
"sigs.k8s.io/controller-runtime/pkg/builder"
@@ -104,14 +105,11 @@ func (r *BackupRepoReconciler) SetupWithManager(mgr ctrl.Manager) error {
104105
For(&velerov1api.BackupRepository{}, builder.WithPredicates(kube.SpecChangePredicate{})).
105106
WatchesRawSource(s).
106107
Watches(
108+
// mark BackupRepository as invalid when BSL is created, updated or deleted.
109+
// BSL may be recreated after deleting, so also include the create event
107110
&velerov1api.BackupStorageLocation{},
108111
kube.EnqueueRequestsFromMapUpdateFunc(r.invalidateBackupReposForBSL),
109-
builder.WithPredicates(
110-
// When BSL updates, check if the backup repositories need to be invalidated
111-
kube.NewUpdateEventPredicate(r.needInvalidBackupRepo),
112-
// When BSL is created, invalidate any backup repositories that reference it
113-
kube.NewCreateEventPredicate(func(client.Object) bool { return true }),
114-
),
112+
builder.WithPredicates(kube.NewUpdateEventPredicate(r.needInvalidBackupRepo)),
115113
).
116114
Complete(r)
117115
}
@@ -130,14 +128,17 @@ func (r *BackupRepoReconciler) invalidateBackupReposForBSL(ctx context.Context,
130128
return []reconcile.Request{}
131129
}
132130

131+
requests := []reconcile.Request{}
133132
for i := range list.Items {
134133
r.logger.WithField("BSL", bsl.Name).Infof("Invalidating Backup Repository %s", list.Items[i].Name)
135-
if err := r.patchBackupRepository(context.Background(), &list.Items[i], repoNotReady("re-establish on BSL change or create")); err != nil {
134+
if err := r.patchBackupRepository(context.Background(), &list.Items[i], repoNotReady("re-establish on BSL change, create or delete")); err != nil {
136135
r.logger.WithField("BSL", bsl.Name).WithError(err).Errorf("fail to patch BackupRepository %s", list.Items[i].Name)
136+
continue
137137
}
138+
requests = append(requests, reconcile.Request{NamespacedName: types.NamespacedName{Namespace: list.Items[i].Namespace, Name: list.Items[i].Name}})
138139
}
139140

140-
return []reconcile.Request{}
141+
return requests
141142
}
142143

143144
// needInvalidBackupRepo returns true if the BSL's storage type, bucket, prefix, CACert, or config has changed

pkg/util/kube/predicate.go

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,6 @@ func (SpecChangePredicate) Update(e event.UpdateEvent) bool {
4747
return !reflect.DeepEqual(oldSpec.Interface(), newSpec.Interface())
4848
}
4949

50-
// NewGenericEventPredicate creates a new Predicate that checks the Generic event with the provided func
51-
func NewGenericEventPredicate(f func(object client.Object) bool) predicate.Predicate {
52-
return predicate.Funcs{
53-
GenericFunc: func(event event.GenericEvent) bool {
54-
return f(event.Object)
55-
},
56-
}
57-
}
58-
5950
// NewAllEventPredicate creates a new Predicate that checks all the events with the provided func
6051
func NewAllEventPredicate(f func(object client.Object) bool) predicate.Predicate {
6152
return predicate.Funcs{
@@ -74,25 +65,6 @@ func NewAllEventPredicate(f func(object client.Object) bool) predicate.Predicate
7465
}
7566
}
7667

77-
// NewUpdateEventPredicate creates a new Predicate that checks the update events with the provided func
78-
// and ignore others
79-
func NewUpdateEventPredicate(f func(client.Object, client.Object) bool) predicate.Predicate {
80-
return predicate.Funcs{
81-
UpdateFunc: func(event event.UpdateEvent) bool {
82-
return f(event.ObjectOld, event.ObjectNew)
83-
},
84-
CreateFunc: func(event event.CreateEvent) bool {
85-
return false
86-
},
87-
DeleteFunc: func(event event.DeleteEvent) bool {
88-
return false
89-
},
90-
GenericFunc: func(event event.GenericEvent) bool {
91-
return false
92-
},
93-
}
94-
}
95-
9668
// FalsePredicate always returns false for all kinds of events
9769
type FalsePredicate struct{}
9870

@@ -116,19 +88,20 @@ func (f FalsePredicate) Generic(event.GenericEvent) bool {
11688
return false
11789
}
11890

119-
func NewCreateEventPredicate(f func(client.Object) bool) predicate.Predicate {
91+
// NewGenericEventPredicate creates a new Predicate that checks the Generic event with the provided func
92+
func NewGenericEventPredicate(f func(object client.Object) bool) predicate.Predicate {
12093
return predicate.Funcs{
121-
CreateFunc: func(event event.CreateEvent) bool {
122-
return f(event.Object)
123-
},
124-
DeleteFunc: func(event event.DeleteEvent) bool {
125-
return false
126-
},
12794
GenericFunc: func(event event.GenericEvent) bool {
128-
return false
95+
return f(event.Object)
12996
},
97+
}
98+
}
99+
100+
// NewUpdateEventPredicate creates a new Predicate that checks the Update event with the provided func
101+
func NewUpdateEventPredicate(f func(objectOld client.Object, objectNew client.Object) bool) predicate.Predicate {
102+
return predicate.Funcs{
130103
UpdateFunc: func(event event.UpdateEvent) bool {
131-
return false
104+
return f(event.ObjectOld, event.ObjectNew)
132105
},
133106
}
134107
}

0 commit comments

Comments
 (0)