cache

package
v0.0.0-...-2d08fe4 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: Apache-2.0 Imports: 9 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
}

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 the IDs of all known pods.

func (*PolicyCache) ListAllPolicies

func (pc *PolicyCache) ListAllPolicies() (policyIDs []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) LookupPod

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

LookupPod returns data of a given Pod.

func (*PolicyCache) LookupPodsByLabelSelectorInsideNs

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

LookupPodsByLabelSelectorInsideNs evaluates pod label selectors in a namespace and returns IDs of matching pods.

func (*PolicyCache) LookupPodsByNamespace

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

LookupPodsByNamespace returns IDs of all pods inside a given namespace.

func (*PolicyCache) LookupPodsByNsLabelSelector

func (pc *PolicyCache) LookupPodsByNsLabelSelector(
	namespaceLabelSelector *policymodel.Policy_LabelSelector) (pods []podmodel.ID)

LookupPodsByNsLabelSelector evaluates namespace label selector and returns IDs of pods in the matched namespaces.

func (*PolicyCache) LookupPoliciesByPod

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

LookupPoliciesByPod returns the 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 the data of a given Policy.

func (*PolicyCache) Resync

func (pc *PolicyCache) Resync(kubeStateData controller.KubeStateData) error

Resync processes a K8s state data resync event. 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(kubeStateChange *controller.KubeStateChange) error

Update processes a K8s state data change event. 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 {
	// Resync processes a K8s state data resync event.
	// 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(kubeStateData controller.KubeStateData) error

	// Update processes a K8s state data change event.
	// The change is applied into the cache and all subscribed watchers are
	// notified.
	// The function will forward any error returned by a watcher.
	Update(kubeStateChange *controller.KubeStateChange) 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)

	// LookupPodsByNsLabelSelector evaluates namespace label selector (expression and/or match
	// labels) and returns IDs of pods in the matched namespaces.
	LookupPodsByNsLabelSelector(podLabelSelector *policymodel.Policy_LabelSelector) (pods []podmodel.ID)

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

	// LookupPodsByNamespace returns IDs of all pods inside a given namespace.
	LookupPodsByNamespace(policyNamespace string) (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)

	// 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(podID podmodel.ID, pod *podmodel.Pod) error

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

	// UpdatePod is called by Policy Cache when data of a pod were modified.
	UpdatePod(podID podmodel.ID, 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