2020-09-16 14:19:51 +00:00
|
|
|
// Copyright 2020 the Pinniped contributors. All Rights Reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
2020-08-09 17:04:05 +00:00
|
|
|
|
|
|
|
package controller
|
|
|
|
|
|
|
|
import (
|
|
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
|
2020-08-28 15:59:09 +00:00
|
|
|
"github.com/suzerain-io/pinniped/internal/controllerlib"
|
2020-08-09 17:04:05 +00:00
|
|
|
)
|
|
|
|
|
2020-09-09 19:55:59 +00:00
|
|
|
func NameAndNamespaceExactMatchFilterFactory(name, namespace string) controllerlib.Filter {
|
|
|
|
return SimpleFilter(func(obj metav1.Object) bool {
|
2020-08-09 17:04:05 +00:00
|
|
|
return obj.GetName() == name && obj.GetNamespace() == namespace
|
2020-09-09 19:55:59 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 {
|
2020-08-28 15:59:09 +00:00
|
|
|
return controllerlib.FilterFuncs{
|
2020-09-09 19:55:59 +00:00
|
|
|
AddFunc: match,
|
|
|
|
UpdateFunc: func(oldObj, newObj metav1.Object) bool { return match(oldObj) || match(newObj) },
|
|
|
|
DeleteFunc: match,
|
2020-08-09 17:04:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-28 15:59:09 +00:00
|
|
|
// Same signature as controllerlib.WithInformer().
|
2020-08-09 17:04:05 +00:00
|
|
|
type WithInformerOptionFunc func(
|
2020-08-28 15:59:09 +00:00
|
|
|
getter controllerlib.InformerGetter,
|
|
|
|
filter controllerlib.Filter,
|
|
|
|
opt controllerlib.InformerOption) controllerlib.Option
|
2020-08-11 17:14:57 +00:00
|
|
|
|
2020-08-28 15:59:09 +00:00
|
|
|
// Same signature as controllerlib.WithInitialEvent().
|
|
|
|
type WithInitialEventOptionFunc func(key controllerlib.Key) controllerlib.Option
|