mirror of https://github.com/knative/pkg.git
				
				
				
			Add symmetric filter helped based on OwnerRefable. (#2032)
Most resources stamped out by knative controllers have OwnerReferences synthesized via `kmeta.NewOwnerRef`, which requires the parent resource to implement `kmeta.OwnerRefable` for accessing the `GroupVersionKind`.
However, where we setup informer watches on those same children resources we have essentially relied on direct synthesis of the `Group[Version]Kind` where we could instead provide an empty instance of the controller resource and leverage `GetGroupVersionKind` to provide the GVK used for filtration.
So where before folks would write:
```golang
FilterFunc: controller.FilterControllerGK(v1alpha1.WithKind("MyType"))
```
They may now write:
```golang
FilterFunc: controller.FilterController(&v1alpha1.MyType{})
```
The latter is preferable in part because it is more strongly typed, but also shorter.
			
			
This commit is contained in:
		
							parent
							
								
									29092fe5b8
								
							
						
					
					
						commit
						8a9bf766d3
					
				| 
						 | 
					@ -152,6 +152,13 @@ func FilterControllerGK(gk schema.GroupKind) func(obj interface{}) bool {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// FilterController makes it simple to create FilterFunc's for use with
 | 
				
			||||||
 | 
					// cache.FilteringResourceEventHandler that filter based on the
 | 
				
			||||||
 | 
					// controlling resource.
 | 
				
			||||||
 | 
					func FilterController(r kmeta.OwnerRefable) func(obj interface{}) bool {
 | 
				
			||||||
 | 
						return FilterControllerGK(r.GetGroupVersionKind().GroupKind())
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// FilterWithName makes it simple to create FilterFunc's for use with
 | 
					// FilterWithName makes it simple to create FilterFunc's for use with
 | 
				
			||||||
// cache.FilteringResourceEventHandler that filter based on a name.
 | 
					// cache.FilteringResourceEventHandler that filter based on a name.
 | 
				
			||||||
func FilterWithName(name string) func(obj interface{}) bool {
 | 
					func FilterWithName(name string) func(obj interface{}) bool {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue