ContainerImage.Pinniped/internal/controller/utils.go
Andrew Keesler eab5c2b86b
Save 2 lines by using inline-style comments for Copyright
Signed-off-by: Andrew Keesler <akeesler@vmware.com>
2020-09-16 10:35:19 -04:00

40 lines
1.3 KiB
Go

// Copyright 2020 the Pinniped contributors. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
package controller
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/suzerain-io/pinniped/internal/controllerlib"
)
func NameAndNamespaceExactMatchFilterFactory(name, namespace string) controllerlib.Filter {
return SimpleFilter(func(obj metav1.Object) bool {
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{
AddFunc: match,
UpdateFunc: func(oldObj, newObj metav1.Object) bool { return match(oldObj) || match(newObj) },
DeleteFunc: match,
}
}
// Same signature as controllerlib.WithInformer().
type WithInformerOptionFunc func(
getter controllerlib.InformerGetter,
filter controllerlib.Filter,
opt controllerlib.InformerOption) controllerlib.Option
// Same signature as controllerlib.WithInitialEvent().
type WithInitialEventOptionFunc func(key controllerlib.Key) controllerlib.Option