cache

package
v0.0.0-...-792cabc Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2017 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DataResyncEvent

type DataResyncEvent struct {
	Namespaces []*namespacemodel.Namespace
	Pods       []*podmodel.Pod
	Policies   []*policymodel.Policy
}

DataResyncEvent wraps an entire state of K8s that should be reflected into VPP.

func NewDataResyncEvent

func NewDataResyncEvent() *DataResyncEvent

NewDataResyncEvent creates an empty instance of DataResyncEvent.

type Deps

type Deps struct {
	Log        logging.Logger
	PluginName core.PluginName
}

Deps lists dependencies of PolicyCache.

type PolicyCache

type PolicyCache struct {
	Deps
	// contains filtered or unexported fields
}

PolicyCache s used for a in-memory storage of K8s State data with fast lookups using idxmap-s. The cache processes K8s State data updates and RESYNC events through Update() and Resync() APIs, respectively. The cache allows to get notified about changes via convenient callbacks. A watcher needs to implement the interface PolicyCacheWatcher and subscribe for watching using Watch() API. The cache provides various fast lookup methods (e.g. by the label selector).

func (*PolicyCache) Init

func (pc *PolicyCache) Init() error

Init initializes policy cache.

func (*PolicyCache) ListAllNamespaces

func (pc *PolicyCache) ListAllNamespaces() (namespaces []nsmodel.ID)

ListAllNamespaces returns IDs of all known namespaces.

func (*PolicyCache) ListAllPods

func (pc *PolicyCache) ListAllPods() (pods []podmodel.ID)

ListAllPods returns IDs of all known pods.

func (*PolicyCache) ListAllPolicies

func (pc *PolicyCache) ListAllPolicies() (policies []policymodel.ID)

ListAllPolicies returns IDs of all policies.

func (*PolicyCache) LookupNamespace

func (pc *PolicyCache) LookupNamespace(namespace nsmodel.ID) (found bool, data *nsmodel.Namespace)

LookupNamespace returns data of a given namespace.

func (*PolicyCache) LookupNamespacesByLabelSelector

func (pc *PolicyCache) LookupNamespacesByLabelSelector(
	nsLabelSelector *policymodel.Policy_LabelSelector) (namespaces []nsmodel.ID)

LookupNamespacesByLabelSelector evaluates label selector (expression and/or match labels) and returns IDs of matching namespaces.

func (*PolicyCache) LookupPod

func (pc *PolicyCache) LookupPod(pod podmodel.ID) (found bool, data *podmodel.Pod)

LookupPod returns data of a given Pod.

func (*PolicyCache) LookupPodsByLabelSelector

func (pc *PolicyCache) LookupPodsByLabelSelector(
	podLabelSelector *policymodel.Policy_LabelSelector) (pods []podmodel.ID)

LookupPodsByLabelSelector evaluates label selector (expression and/or match labels) and returns IDs of matching pods.

func (*PolicyCache) LookupPodsByNSLabelSelector

func (pc *PolicyCache) LookupPodsByNSLabelSelector(policyNamespace string,
	podLabelSelector *policymodel.Policy_LabelSelector) (pods []podmodel.ID)

LookupPodsByNSLabelSelector evaluates label selector (expression and/or match labels) and returns IDs of matching pods in a namespace.

func (*PolicyCache) LookupPodsByNamespace

func (pc *PolicyCache) LookupPodsByNamespace(namespace nsmodel.ID) (pods []podmodel.ID)

LookupPodsByNamespace returns IDs of all pods inside a given namespace.

func (*PolicyCache) LookupPoliciesByPod

func (pc *PolicyCache) LookupPoliciesByPod(pod podmodel.ID) (policies []policymodel.ID)

LookupPoliciesByPod returns IDs of all policies assigned to a given pod.

func (*PolicyCache) LookupPolicy

func (pc *PolicyCache) LookupPolicy(policy policymodel.ID) (found bool, data *policymodel.Policy)

LookupPolicy returns data of a given Policy.

func (*PolicyCache) Resync

func (pc *PolicyCache) Resync(resyncEv datasync.ResyncEvent) error

Resync processes a datasync resync event associated with K8s State data. The cache content is full replaced with the received data and all subscribed watchers are notified. The function will forward any error returned by a watcher.

func (*PolicyCache) Update

func (pc *PolicyCache) Update(dataChngEv datasync.ChangeEvent) error

Update processes a datasync change event associated with K8s State data. The change is applied into the cache and all subscribed watchers are notified. The function will forward any error returned by a watcher.

func (*PolicyCache) Watch

func (pc *PolicyCache) Watch(watcher PolicyCacheWatcher) error

Watch subscribes a new watcher.

type PolicyCacheAPI

type PolicyCacheAPI interface {
	// Update processes a datasync change event associated with K8s State data.
	// The change is applied into the cache and all subscribed watchers are
	// notified.
	// The function will forward any error returned by a watcher.
	Update(dataChngEv datasync.ChangeEvent) error

	// Resync processes a datasync resync event associated with K8s State data.
	// The cache content is full replaced with the received data and all
	// subscribed watchers are notified.
	// The function will forward any error returned by a watcher.
	Resync(resyncEv datasync.ResyncEvent) error

	// Watch subscribes a new watcher.
	Watch(watcher PolicyCacheWatcher) error

	// LookupPod returns data of a given Pod.
	LookupPod(pod podmodel.ID) (found bool, data *podmodel.Pod)

	// LookupPodsByLabelSelector evaluates label selector (expression and/or match
	// labels) and returns IDs of matching pods.
	LookupPodsByLabelSelector(podLabelSelector *policymodel.Policy_LabelSelector) (pods []podmodel.ID)

	// LookupPodsByNSLabelSelector evaluates label selector (expression and/or match
	// labels and returns IDs of matching pods in a namespace.
	LookupPodsByNSLabelSelector(namespace string, podLabelSelector *policymodel.Policy_LabelSelector) (pods []podmodel.ID)

	// LookupPodsByNamespace returns IDs of all pods inside a given namespace.
	LookupPodsByNamespace(namespace nsmodel.ID) (pods []podmodel.ID)

	// ListAllPods returns IDs of all known pods.
	ListAllPods() (pods []podmodel.ID)

	// LookupPolicy returns data of a given Policy.
	LookupPolicy(policy policymodel.ID) (found bool, data *policymodel.Policy)

	// LookupPoliciesByPod returns IDs of all policies assigned to a given pod.
	LookupPoliciesByPod(pod podmodel.ID) (policies []policymodel.ID)

	// ListAllPolicies returns IDs of all policies.
	ListAllPolicies() (policies []policymodel.ID)

	// LookupNamespace returns data of a given namespace.
	LookupNamespace(namespace nsmodel.ID) (found bool, data *nsmodel.Namespace)

	// LookupNamespacesByLabelSelector evaluates label selector (expression
	// and/or match labels) and returns IDs of matching namespaces.
	LookupNamespacesByLabelSelector(nsLabelSelector *policymodel.Policy_LabelSelector) (namespaces []nsmodel.ID)

	// ListAllNamespaces returns IDs of all known namespaces.
	ListAllNamespaces() (namespaces []nsmodel.ID)
}

PolicyCacheAPI defines API of PolicyCache used for a non-persistent storage of K8s State data with fast lookups. The cache processes K8s State data updates and RESYNC events through Update() and Resync() APIs, respectively. The cache allows to get notified about changes via convenient callbacks. A watcher needs to implement the interface PolicyCacheWatcher and subscribe for watching using Watch() API. The cache provides various fast lookup methods (e.g. by the label selector).

type PolicyCacheWatcher

type PolicyCacheWatcher interface {
	// Resync is called by Policy Cache during a RESYNC event.
	Resync(data *DataResyncEvent) error

	// AddPod is called by Policy Cache when a new pod is created.
	AddPod(pod *podmodel.Pod) error

	// DelPod is called by Policy Cache after a pod was removed.
	DelPod(pod *podmodel.Pod) error

	// UpdatePod is called by Policy Cache when data of a pod were modified.
	UpdatePod(oldPod, newPod *podmodel.Pod) error

	// AddPolicy is called by Policy Cache when a new policy is created.
	AddPolicy(policy *policymodel.Policy) error

	// DelPolicy is called by Policy Cache after a policy was removed.
	DelPolicy(policy *policymodel.Policy) error

	// UpdatePolicy is called by Policy Cache when date of a policy were
	// modified.
	UpdatePolicy(oldPolicy, newPolicy *policymodel.Policy) error

	// AddNamespace is called by Policy Cache when a new namespace is created.
	AddNamespace(ns *nsmodel.Namespace) error

	// DelNamespace is called by Policy Cache after a namespace was removed.
	DelNamespace(ns *nsmodel.Namespace) error

	// UpdateNamespace is called by Policy Cache when data of a namespace were
	// modified.
	UpdateNamespace(oldNs, newNs *nsmodel.Namespace) error
}

PolicyCacheWatcher defines interface that a PolicyCache watcher must implement.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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