@@ -31,6 +31,7 @@ import (
31
31
apierrors "k8s.io/apimachinery/pkg/api/errors"
32
32
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
33
33
"k8s.io/apimachinery/pkg/labels"
34
+ "k8s.io/apimachinery/pkg/types"
34
35
clocks "k8s.io/utils/clock"
35
36
ctrl "sigs.k8s.io/controller-runtime"
36
37
"sigs.k8s.io/controller-runtime/pkg/builder"
@@ -104,14 +105,11 @@ func (r *BackupRepoReconciler) SetupWithManager(mgr ctrl.Manager) error {
104
105
For (& velerov1api.BackupRepository {}, builder .WithPredicates (kube.SpecChangePredicate {})).
105
106
WatchesRawSource (s ).
106
107
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
107
110
& velerov1api.BackupStorageLocation {},
108
111
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 )),
115
113
).
116
114
Complete (r )
117
115
}
@@ -130,14 +128,17 @@ func (r *BackupRepoReconciler) invalidateBackupReposForBSL(ctx context.Context,
130
128
return []reconcile.Request {}
131
129
}
132
130
131
+ requests := []reconcile.Request {}
133
132
for i := range list .Items {
134
133
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 {
136
135
r .logger .WithField ("BSL" , bsl .Name ).WithError (err ).Errorf ("fail to patch BackupRepository %s" , list .Items [i ].Name )
136
+ continue
137
137
}
138
+ requests = append (requests , reconcile.Request {NamespacedName : types.NamespacedName {Namespace : list .Items [i ].Namespace , Name : list .Items [i ].Name }})
138
139
}
139
140
140
- return []reconcile. Request {}
141
+ return requests
141
142
}
142
143
143
144
// needInvalidBackupRepo returns true if the BSL's storage type, bucket, prefix, CACert, or config has changed
0 commit comments