1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00
kyverno/pkg/informers/configmaps.go
Charles-Edouard Brétéché 88cfa4396a
fix: factorise confimap informer code (#7667)
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
Co-authored-by: shuting <shuting@nirmata.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2023-06-28 04:43:16 +00:00

46 lines
1.2 KiB
Go

package informers
import (
"time"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
corev1informers "k8s.io/client-go/informers/core/v1"
"k8s.io/client-go/kubernetes"
corev1listers "k8s.io/client-go/listers/core/v1"
"k8s.io/client-go/tools/cache"
)
type configMapInformer struct {
informer cache.SharedIndexInformer
lister corev1listers.ConfigMapLister
}
func NewConfigMapInformer(
client kubernetes.Interface,
namespace string,
name string,
resyncPeriod time.Duration,
) corev1informers.ConfigMapInformer {
indexers := cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}
options := func(lo *metav1.ListOptions) {
lo.FieldSelector = fields.OneTermEqualSelector(metav1.ObjectNameField, name).String()
}
informer := corev1informers.NewFilteredConfigMapInformer(
client,
namespace,
resyncPeriod,
indexers,
options,
)
lister := corev1listers.NewConfigMapLister(informer.GetIndexer())
return &configMapInformer{informer, lister}
}
func (i *configMapInformer) Informer() cache.SharedIndexInformer {
return i.informer
}
func (i *configMapInformer) Lister() corev1listers.ConfigMapLister {
return i.lister
}