1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-08 17:06:57 +00:00
kyverno/pkg/sharedinformer/sharedinformerfactory.go

58 lines
1.7 KiB
Go
Raw Normal View History

2019-05-15 12:29:09 -07:00
package sharedinformer
import (
"fmt"
2019-05-21 11:00:09 -07:00
policyclientset "github.com/nirmata/kyverno/pkg/client/clientset/versioned"
informers "github.com/nirmata/kyverno/pkg/client/informers/externalversions"
infomertypes "github.com/nirmata/kyverno/pkg/client/informers/externalversions/policy/v1alpha1"
v1alpha1 "github.com/nirmata/kyverno/pkg/client/listers/policy/v1alpha1"
2019-05-15 12:29:09 -07:00
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/cache"
)
2019-06-05 17:43:59 -07:00
//PolicyInformer access policy informers
2019-05-15 12:29:09 -07:00
type PolicyInformer interface {
GetLister() v1alpha1.PolicyLister
GetInfomer() cache.SharedIndexInformer
}
2019-06-05 17:43:59 -07:00
// SharedInfomer access shared informers
2019-05-15 12:29:09 -07:00
type SharedInfomer interface {
PolicyInformer
Run(stopCh <-chan struct{})
}
type sharedInfomer struct {
policyInformerFactory informers.SharedInformerFactory
}
2019-06-05 17:43:59 -07:00
//NewSharedInformerFactory returns shared informer
2019-05-15 12:29:09 -07:00
func NewSharedInformerFactory(clientConfig *rest.Config) (SharedInfomer, error) {
// create policy client
policyClientset, err := policyclientset.NewForConfig(clientConfig)
if err != nil {
return nil, fmt.Errorf("Error creating policyClient: %v\n", err)
}
//TODO: replace with NewSharedInformerFactoryWithOptions
policyInformerFactory := informers.NewSharedInformerFactory(policyClientset, 0)
return &sharedInfomer{
policyInformerFactory: policyInformerFactory,
}, nil
}
func (si *sharedInfomer) Run(stopCh <-chan struct{}) {
si.policyInformerFactory.Start(stopCh)
}
func (si *sharedInfomer) getInfomer() infomertypes.PolicyInformer {
return si.policyInformerFactory.Kyverno().V1alpha1().Policies()
2019-05-15 12:29:09 -07:00
}
func (si *sharedInfomer) GetInfomer() cache.SharedIndexInformer {
return si.getInfomer().Informer()
}
func (si *sharedInfomer) GetLister() v1alpha1.PolicyLister {
return si.getInfomer().Lister()
}