File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -217,3 +217,17 @@ func (p StatusChangedPredicate) Update(e event.UpdateEvent) bool {
217217	}
218218	return  ! reflect .DeepEqual (oldStatus , newStatus )
219219}
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+ func  ExactNamePredicate (name , namespace  string ) predicate.Predicate  {
227+ 	return  predicate .NewPredicateFuncs (func (obj  client.Object ) bool  {
228+ 		if  obj  ==  nil  {
229+ 			return  false 
230+ 		}
231+ 		return  obj .GetName () ==  name  &&  obj .GetNamespace () ==  namespace 
232+ 	})
233+ }
Original file line number Diff line number Diff line change @@ -234,6 +234,22 @@ var _ = Describe("Predicates", func() {
234234
235235	})
236236
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+ 
251+ 	})
252+ 
237253})
238254
239255func  updateEvent (old , new  client.Object ) event.UpdateEvent  {
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments