cache

package
v0.0.0-...-ec175e0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 25, 2021 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultResyncDuration = time.Second * 180
	ResourceWatches       = &sync.Map{} // sync.Map{"resourceKey": [sync.Map{"namespace.resourceKey":"watchDetail"}]}
)
View Source
var Namespaces []string

Functions

func WatchCount

func WatchCount(onlyRunning bool) int

WatchCount returns the current count of watchers from the cache. If onlyRunning is true, the count will only include running watchers.

func WatchErrorHandlerFactory

func WatchErrorHandlerFactory(logger *zap.Logger, key string, stopCh chan<- struct{}) func(r *kcache.Reflector, err error)

WatchErrorHandlerFactory handles Reflector errors and ensures the Informer loop is shutdown when encountering an error.

func WatcherStop

func WatcherStop()

WatcherStop stops all running watchers.

Types

type FilteredWatchDetail

type FilteredWatchDetail struct {
	Detail *WatchDetail
	// contains filtered or unexported fields
}

FilteredWatcheDetail is a thin wrapped around a WatchDetail used when a NamespaceAll watcher is available it scopes that WatchDetail List and Get calls to a single namespace.

func (*FilteredWatchDetail) Drain

func (w *FilteredWatchDetail) Drain(ch chan<- interface{}, stopCh chan struct{})

func (*FilteredWatchDetail) Get

func (w *FilteredWatchDetail) Get(name string) (runtime.Object, error)

func (*FilteredWatchDetail) IsRunning

func (w *FilteredWatchDetail) IsRunning() int

func (*FilteredWatchDetail) Key

func (w *FilteredWatchDetail) Key() string

func (FilteredWatchDetail) List

func (w FilteredWatchDetail) List(selector labels.Selector) ([]runtime.Object, error)

func (*FilteredWatchDetail) Namespace

func (w *FilteredWatchDetail) Namespace() string

func (*FilteredWatchDetail) Stop

func (w *FilteredWatchDetail) Stop()

type ResourceCache

type ResourceCache struct {
	// contains filtered or unexported fields
}
var Resources *ResourceCache

func NewResourceCache

func NewResourceCache() *ResourceCache

func (*ResourceCache) Add

func (r *ResourceCache) Add(key string, resources ...resource.Resource)

func (*ResourceCache) Get

func (r *ResourceCache) Get(key string) []resource.Resource

type ResourceLister

type ResourceLister interface {
	// List will return all objects in this namespace
	List(selector labels.Selector) (ret []runtime.Object, err error)
	// Get will attempt to retrieve by namespace and name
	Get(name string) (runtime.Object, error)
	// Drain will get events from the queue and send them to the provided channel
	Drain(ch chan<- interface{}, stopCh chan struct{})
	// Stop
	Stop()
	// Namespace
	Namespace() string
	// Key
	Key() string
	// IsRunning returns the count of underlying Watchers that are running for the ResourceLister
	IsRunning() int
}

func WatchForResource

func WatchForResource(r resource.Resource, namespaces ...string) (ResourceLister, error)

WatchForResource returns a WatchDetail for the given Resource.

func WatchList

func WatchList(onlyRunning bool) []ResourceLister

WatchList returns the current list of watchers from the cache. If onlyRunning is true, the list will only include running watchers.

type WatchDetail

type WatchDetail struct {
	Informer kcache.SharedInformer
	StopCh   chan struct{}
	Resource resource.Resource
	Logger   *zap.Logger

	Queue *workqueue.Type
	// contains filtered or unexported fields
}

WatchDetail holds the details of an Informer and Lister for a specific resource. An optionally configured event queue.

func (*WatchDetail) Drain

func (w *WatchDetail) Drain(ch chan<- interface{}, stopCh chan struct{})

Drain will get events off of the WatchDetail.Queue and send them to the provided channel.

func (*WatchDetail) Get

func (w *WatchDetail) Get(name string) (runtime.Object, error)

func (*WatchDetail) IsRunning

func (w *WatchDetail) IsRunning() int

IsRunning returns true if the Informer loop for the WatchDetail is running.

func (*WatchDetail) Key

func (w *WatchDetail) Key() string

func (*WatchDetail) List

func (w *WatchDetail) List(selector labels.Selector) ([]runtime.Object, error)

func (*WatchDetail) Namespace

func (w *WatchDetail) Namespace() string

func (*WatchDetail) Stop

func (w *WatchDetail) Stop()

Stop closes the StopCh shutting down the Drain and Informer loops.

type Watcher

type Watcher struct {
	// contains filtered or unexported fields
}

Watcher holds referenecs to the Kubernetes types and a logger. Use NewWatcher to create instances of Watcher.

func NewWatcher

func NewWatcher(ctx context.Context, options ...WatcherOption) (*Watcher, error)

NewWatcher creates a Watcher object. This object is used to hold the reference to the Kubernetes types that implement Informers and Listers.

func (*Watcher) Watch

func (w *Watcher) Watch(ctx context.Context, namespace string, res resource.Resource, queueEvents bool) (ResourceLister, error)

Watch creates a new WatchDetail and starts the watch loop for the given Resource If queueEvents is true, all events for the resource will be added to the WatcheDetail.Queue To handle the events use WatchDetail.Drain

type WatcherOption

type WatcherOption func(*Watcher)

func WithDynamicClient

func WithDynamicClient(d dynamic.Interface) WatcherOption

func WithLogger

func WithLogger(logger *zap.Logger) WatcherOption

func WithNamespace

func WithNamespace(namespace string) WatcherOption

type WrappedWatchDetails

type WrappedWatchDetails struct {
	Listers []ResourceLister
}

WrappedWatchDetails combines multiple WatchDetail in to a single call to allow for simple multi-namespace List and Get calls. As a result of this, the other ResourceLister calls have been encoded to be multi-value as a comma seprated string. The responsiblilty of parsing these values is the callers.

func (*WrappedWatchDetails) Drain

func (w *WrappedWatchDetails) Drain(ch chan<- interface{}, stopCh chan struct{})

Drain will get events off of the WatchDetail.Queue and send them to the provided channel.

func (*WrappedWatchDetails) Get

func (w *WrappedWatchDetails) Get(name string) (runtime.Object, error)

func (*WrappedWatchDetails) IsRunning

func (w *WrappedWatchDetails) IsRunning() int

func (*WrappedWatchDetails) Key

func (w *WrappedWatchDetails) Key() string

func (*WrappedWatchDetails) List

func (w *WrappedWatchDetails) List(selector labels.Selector) ([]runtime.Object, error)

func (*WrappedWatchDetails) Namespace

func (w *WrappedWatchDetails) Namespace() string

func (*WrappedWatchDetails) Stop

func (w *WrappedWatchDetails) Stop()

Stop closes the StopCh shutting down the Drain and Informer loops.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL