Documentation ¶
Index ¶
- func ResolveDependencies(cache store.CacheStores, obj client.Object) ([]client.Object, error)
- type AdjacencyMap
- type AffectedCacheObjectMetadata
- type CacheGraphProvider
- type ConfigGraph
- type DefaultCacheGraphProvider
- type GeneratedCacheMetadata
- type GeneratedCacheMetadataCollector
- type Generator
- func (g *Generator) GenerateBackfillingBrokenObjects(currentCache store.CacheStores, lastValidCacheSnapshot *store.CacheStores, ...) (store.CacheStores, GeneratedCacheMetadata, error)
- func (g *Generator) GenerateExcludingBrokenObjects(cache store.CacheStores, brokenObjects []ObjectHash) (store.CacheStores, GeneratedCacheMetadata, error)
- type ObjectHash
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ResolveDependencies ¶
ResolveDependencies resolves dependencies for a given object. Dependencies are all objects referenced by the given object. For example, an Ingress object might refer to an IngressClass, Services, Plugins, etc. Every supported object type should explicitly have a case in this function.
Types ¶
type AdjacencyMap ¶
type AdjacencyMap map[ObjectHash][]ObjectHash
AdjacencyMap is a map of object hashes to their neighbours' hashes.
type AffectedCacheObjectMetadata ¶
type AffectedCacheObjectMetadata struct { Object client.Object CausingObjects []ObjectHash }
AffectedCacheObjectMetadata contains an object and a list of objects that caused it to be excluded or backfilled during the fallback process.
type CacheGraphProvider ¶
type CacheGraphProvider interface { // CacheToGraph returns a new ConfigGraph instance built from the given cache snapshot. CacheToGraph(cache store.CacheStores) (*ConfigGraph, error) }
type ConfigGraph ¶
type ConfigGraph struct {
// contains filtered or unexported fields
}
ConfigGraph is a graph representation of the Kubernetes resources kept in the cache. Vertices are objects, edges are dependencies between objects (dependency -> dependant). It allows to quickly determine which objects are affected by traversing the graph from the affected object to its dependants.
If you want to extend the graph with a new object type, you need to ensure ResolveDependencies function is implemented for that object type. If your object type has no dependencies, you can ignore it.
func NewConfigGraph ¶
func NewConfigGraph() *ConfigGraph
func (*ConfigGraph) AddEdge ¶
func (g *ConfigGraph) AddEdge(from, to ObjectHash) error
AddEdge adds an edge between two vertices in the graph.
func (*ConfigGraph) AddVertex ¶
func (g *ConfigGraph) AddVertex(obj client.Object) error
AddVertex adds a vertex to the graph.
func (*ConfigGraph) AdjacencyMap ¶
func (g *ConfigGraph) AdjacencyMap() (AdjacencyMap, error)
AdjacencyMap returns a map of object hashes to their neighbours' hashes.
func (*ConfigGraph) SubgraphObjects ¶
func (g *ConfigGraph) SubgraphObjects(sourceHash ObjectHash) ([]client.Object, error)
SubgraphObjects returns all objects in the graph reachable from the source object, including the source object. It uses a depth-first search to traverse the graph. If the source object is not in the graph, no objects are returned.
type DefaultCacheGraphProvider ¶
type DefaultCacheGraphProvider struct{}
DefaultCacheGraphProvider is a default implementation of the CacheGraphProvider interface.
func NewDefaultCacheGraphProvider ¶
func NewDefaultCacheGraphProvider() *DefaultCacheGraphProvider
func (DefaultCacheGraphProvider) CacheToGraph ¶
func (p DefaultCacheGraphProvider) CacheToGraph(c store.CacheStores) (*ConfigGraph, error)
CacheToGraph creates a new ConfigGraph from the given cache stores. It adds all objects from the cache stores to the graph as vertices as well as edges between objects and their dependencies resolved by the ResolveDependencies function.
type GeneratedCacheMetadata ¶
type GeneratedCacheMetadata struct { // BrokenObjects are objects that were reported as broken by the Kong Admin API. BrokenObjects []ObjectHash // ExcludedObjects are objects that were excluded from the fallback configuration as they were broken or either of their // dependencies was broken. ExcludedObjects []AffectedCacheObjectMetadata // BackfilledObjects are objects that were backfilled from the last valid cache state as they were broken or either of // their dependencies was broken. BackfilledObjects []AffectedCacheObjectMetadata }
GeneratedCacheMetadata contains metadata generated during the fallback process.
type GeneratedCacheMetadataCollector ¶
type GeneratedCacheMetadataCollector struct {
// contains filtered or unexported fields
}
GeneratedCacheMetadataCollector is a collector for cache metadata generated during the fallback process. It's primarily used to deduplicate the metadata and make it easier to work with.
func NewGenerateCacheMetadataCollector ¶
func NewGenerateCacheMetadataCollector(brokenObjects ...ObjectHash) *GeneratedCacheMetadataCollector
NewGenerateCacheMetadataCollector creates a new GeneratedCacheMetadataCollector instance.
func (*GeneratedCacheMetadataCollector) CollectBackfilled ¶
func (m *GeneratedCacheMetadataCollector) CollectBackfilled(backfilled client.Object, causing ObjectHash)
CollectBackfilled collects a backfilled object (an object that was backfilled from the last valid cache state as that or one of its dependencies was broken).
func (*GeneratedCacheMetadataCollector) CollectExcluded ¶
func (m *GeneratedCacheMetadataCollector) CollectExcluded(excluded client.Object, causing ObjectHash)
CollectExcluded collects an excluded object (an object that was excluded from the fallback configuration as it was broken or one of its dependencies was broken).
func (*GeneratedCacheMetadataCollector) Metadata ¶
func (m *GeneratedCacheMetadataCollector) Metadata() GeneratedCacheMetadata
Metadata generates the final cache metadata from the collected data.
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator is responsible for generating fallback cache snapshots.
func NewGenerator ¶
func NewGenerator(cacheGraphProvider CacheGraphProvider, logger logr.Logger) *Generator
func (*Generator) GenerateBackfillingBrokenObjects ¶
func (g *Generator) GenerateBackfillingBrokenObjects( currentCache store.CacheStores, lastValidCacheSnapshot *store.CacheStores, brokenObjects []ObjectHash, ) (store.CacheStores, GeneratedCacheMetadata, error)
func (*Generator) GenerateExcludingBrokenObjects ¶
func (g *Generator) GenerateExcludingBrokenObjects( cache store.CacheStores, brokenObjects []ObjectHash, ) (store.CacheStores, GeneratedCacheMetadata, error)
GenerateExcludingBrokenObjects generates a new cache snapshot that excludes all objects that depend on the broken objects.
type ObjectHash ¶
type ObjectHash struct { // UID is the unique identifier of the object. UID k8stypes.UID // Group is the object's group. Group string // Kind is the object's Kind. Kind string // Namespace is the object's Namespace. Namespace string // Name is the object's Name. Name string }
ObjectHash is a unique identifier for a given object that is used as a vertex key in the graph. It could consist of the object's UID only, but we also include the object's kind, namespace and name to make it easier to debug and understand the graph.
func GetObjectHash ¶
func GetObjectHash(obj client.Object) ObjectHash
GetObjectHash is a function that returns a unique identifier for a given object that is used as a vertex key in the graph.
func (ObjectHash) String ¶
func (h ObjectHash) String() string
String returns a string representation of the ObjectHash. It intentionally does not include the UID as it is not human-readable and is not necessary for debugging purposes.