mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-15 17:51:20 +00:00
51ac382c6c
* added configmap data substitution for foreground mutate and validate * added configmap data substitution for foreground mutate and validate fmt * added configmap lookup for background * added comments to resource cache * added configmap data lookup in preConditions * added parse strings in In operator and configmap lookup docs * added configmap lookup docs * modified configmap lookup docs
53 lines
1.7 KiB
Go
53 lines
1.7 KiB
Go
package resourcecache
|
|
|
|
import (
|
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
|
"k8s.io/client-go/informers"
|
|
"k8s.io/client-go/tools/cache"
|
|
)
|
|
|
|
// GVRCacheIface - allows operation on a single resource
|
|
type GVRCacheIface interface {
|
|
StopInformer()
|
|
IsNamespaced() bool
|
|
GetLister() cache.GenericLister
|
|
GetNamespacedLister(namespace string) cache.GenericNamespaceLister
|
|
}
|
|
|
|
// GVRCache ...
|
|
type GVRCache struct {
|
|
// GVR Group Version Resource of a resource
|
|
GVR schema.GroupVersionResource
|
|
// Namespaced - identifies if a resource is namespaced or not
|
|
Namespaced bool
|
|
// stopCh - channel to stop the informer when needed
|
|
stopCh chan struct{}
|
|
// genericInformer - contains instance of informers.GenericInformer for a specific resource
|
|
// which in turn contains Listers() which gives access to cached resources.
|
|
genericInformer informers.GenericInformer
|
|
}
|
|
|
|
// NewGVRCache ...
|
|
func NewGVRCache(gvr schema.GroupVersionResource, namespaced bool, stopCh chan struct{}, genericInformer informers.GenericInformer) GVRCacheIface {
|
|
return &GVRCache{GVR: gvr, Namespaced: namespaced, stopCh: stopCh, genericInformer: genericInformer}
|
|
}
|
|
|
|
// StopInformer ...
|
|
func (gvrc *GVRCache) StopInformer() {
|
|
close(gvrc.stopCh)
|
|
}
|
|
|
|
// IsNamespaced ...
|
|
func (gvrc *GVRCache) IsNamespaced() bool {
|
|
return gvrc.Namespaced
|
|
}
|
|
|
|
// GetLister - get access to Lister() instance of a resource in GVRCache
|
|
func (gvrc *GVRCache) GetLister() cache.GenericLister {
|
|
return gvrc.genericInformer.Lister()
|
|
}
|
|
|
|
// GetNamespacedLister - get access to namespaced Lister() instance of a resource in GVRCache
|
|
func (gvrc *GVRCache) GetNamespacedLister(namespace string) cache.GenericNamespaceLister {
|
|
return gvrc.genericInformer.Lister().ByNamespace(namespace)
|
|
}
|