Add new controller.SimpleFilter and controller.NoOpFilter utilities.
Signed-off-by: Matt Moyer <moyerm@vmware.com>
This commit is contained in:
parent
19c671a60a
commit
92fabf43b3
@ -11,16 +11,23 @@ import (
|
|||||||
"github.com/suzerain-io/pinniped/internal/controllerlib"
|
"github.com/suzerain-io/pinniped/internal/controllerlib"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NameAndNamespaceExactMatchFilterFactory(name, namespace string) controllerlib.FilterFuncs {
|
func NameAndNamespaceExactMatchFilterFactory(name, namespace string) controllerlib.Filter {
|
||||||
objMatchesFunc := func(obj metav1.Object) bool {
|
return SimpleFilter(func(obj metav1.Object) bool {
|
||||||
return obj.GetName() == name && obj.GetNamespace() == namespace
|
return obj.GetName() == name && obj.GetNamespace() == namespace
|
||||||
}
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// NoOpFilter returns a controllerlib.Filter that allows all objects.
|
||||||
|
func NoOpFilter() controllerlib.Filter {
|
||||||
|
return SimpleFilter(func(object metav1.Object) bool { return true })
|
||||||
|
}
|
||||||
|
|
||||||
|
// SimpleFilter takes a single boolean match function on a metav1.Object and wraps it into a proper controllerlib.Filter.
|
||||||
|
func SimpleFilter(match func(metav1.Object) bool) controllerlib.Filter {
|
||||||
return controllerlib.FilterFuncs{
|
return controllerlib.FilterFuncs{
|
||||||
AddFunc: objMatchesFunc,
|
AddFunc: match,
|
||||||
UpdateFunc: func(oldObj, newObj metav1.Object) bool {
|
UpdateFunc: func(oldObj, newObj metav1.Object) bool { return match(oldObj) || match(newObj) },
|
||||||
return objMatchesFunc(oldObj) || objMatchesFunc(newObj)
|
DeleteFunc: match,
|
||||||
},
|
|
||||||
DeleteFunc: objMatchesFunc,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user