File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -217,3 +217,18 @@ func (p StatusChangedPredicate) Update(e event.UpdateEvent) bool {
217
217
}
218
218
return ! reflect .DeepEqual (oldStatus , newStatus )
219
219
}
220
+
221
+ ////////////////////////////////////
222
+ /// IDENTITY MATCHING PREDICATES ///
223
+ ////////////////////////////////////
224
+
225
+ // ExactNamePredicate returns true if the object's name and namespace exactly match the specified values.
226
+ // The namespace can be set to '*' to match any namespace.
227
+ func ExactNamePredicate (name , namespace string ) predicate.Predicate {
228
+ return predicate .NewPredicateFuncs (func (obj client.Object ) bool {
229
+ if obj == nil {
230
+ return false
231
+ }
232
+ return obj .GetName () == name && (namespace == "*" || obj .GetNamespace () == namespace )
233
+ })
234
+ }
Original file line number Diff line number Diff line change @@ -234,6 +234,25 @@ var _ = Describe("Predicates", func() {
234
234
235
235
})
236
236
237
+ Context ("Identity" , func () {
238
+
239
+ It ("should match resources with the specified identity" , func () {
240
+ p := ctrlutils .ExactNamePredicate ("foo" , "bar" )
241
+ e := event.CreateEvent {Object : base }
242
+ Expect (p .Create (e )).To (BeTrue ())
243
+
244
+ p2 := ctrlutils .ExactNamePredicate ("foo" , "" )
245
+ Expect (p2 .Create (e )).To (BeFalse ())
246
+
247
+ p3 := ctrlutils .ExactNamePredicate ("foo" , "baz" )
248
+ Expect (p3 .Create (e )).To (BeFalse ())
249
+
250
+ p4 := ctrlutils .ExactNamePredicate ("foo" , "*" )
251
+ Expect (p4 .Create (e )).To (BeTrue ())
252
+ })
253
+
254
+ })
255
+
237
256
})
238
257
239
258
func updateEvent (old , new client.Object ) event.UpdateEvent {
You can’t perform that action at this time.
0 commit comments