ContainerImage.Pinniped/internal/controller/utils.go
Matt Moyer a503fa8673 Pull controller-go back into this repository as internal/controllerlib.
Signed-off-by: Matt Moyer <moyerm@vmware.com>
2020-08-28 13:07:47 -05:00

35 lines
989 B
Go

/*
Copyright 2020 VMware, Inc.
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.FilterFuncs {
objMatchesFunc := func(obj metav1.Object) bool {
return obj.GetName() == name && obj.GetNamespace() == namespace
}
return controllerlib.FilterFuncs{
AddFunc: objMatchesFunc,
UpdateFunc: func(oldObj, newObj metav1.Object) bool {
return objMatchesFunc(oldObj) || objMatchesFunc(newObj)
},
DeleteFunc: objMatchesFunc,
}
}
// 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