topology

package
v0.4.8-beta.2 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ParentTypeKey = "parent"
	ChildTypeKey  = "child"
)

Variables

This section is empty.

Functions

func GVRNamespaced

func GVRNamespaced(gvr schema.GroupVersionResource, discoveryClient discovery.DiscoveryClient) bool

GVRNamespaced returns true if a given GVR is namespaced based on the result of discovery client

func GetByJSONPath

func GetByJSONPath(
	ctx context.Context,
	relatedResList *unstructured.UnstructuredList,
	relationshipType string,
	client *dynamic.DynamicClient,
	obj unstructured.Unstructured,
	relation *Relationship,
	relatedGVK schema.GroupVersionKind,
	objResourceNode ResourceGraphNode,
	relationshipGraph graph.Graph[string, RelationshipGraphNode],
	resourceGraph graph.Graph[string, ResourceGraphNode],
) (graph.Graph[string, ResourceGraphNode], error)

GetByJSONPath retrieves related resources based on JSON path from a given list of unstructured resources.

func GetByLabelSelector

func GetByLabelSelector(
	ctx context.Context,
	relatedResList *unstructured.UnstructuredList,
	relationshipType string,
	client *dynamic.DynamicClient,
	obj unstructured.Unstructured,
	relation *Relationship,
	relatedGVK schema.GroupVersionKind,
	objResourceNode ResourceGraphNode,
	relationshipGraph graph.Graph[string, RelationshipGraphNode],
	resourceGraph graph.Graph[string, ResourceGraphNode],
) (graph.Graph[string, ResourceGraphNode], error)

GetByLabelSelector retrieves related resources based on label selectors from a given list of unstructured resources.

func GetChildResourcesList

func GetChildResourcesList(ctx context.Context, client *dynamic.DynamicClient, childRelation *Relationship, namespace string) (*unstructured.UnstructuredList, error)

GetChildResourcesList returns an *unstructured.UnstructuredList representing all resources that matches the child GVK in the current namespace

func GetChildren

func GetChildren(
	ctx context.Context,
	client *dynamic.DynamicClient,
	obj unstructured.Unstructured,
	childRelation *Relationship,
	namespace, objName string,
	objResourceNode ResourceGraphNode,
	relationshipGraph graph.Graph[string, RelationshipGraphNode],
	resourceGraph graph.Graph[string, ResourceGraphNode],
) (graph.Graph[string, ResourceGraphNode], error)

GetChildren returns a graph that includes all of the child resources for the current obj that are described by the childRelation

func GetChildrenByOwnerReference

func GetChildrenByOwnerReference(
	ctx context.Context,
	childResList *unstructured.UnstructuredList,
	client *dynamic.DynamicClient,
	obj unstructured.Unstructured,
	childGVK schema.GroupVersionKind,
	relationshipGraph graph.Graph[string, RelationshipGraphNode],
	resourceGraph graph.Graph[string, ResourceGraphNode],
) (graph.Graph[string, ResourceGraphNode], error)

GetChildrenByOwnerReference returns a graph that includes all of the child resources for the current obj described by their children's OwnerReferences field

func GetParentResourcesList

func GetParentResourcesList(ctx context.Context, client *dynamic.DynamicClient, parentRelation *Relationship, namespace string) (*unstructured.UnstructuredList, error)

GetParentResourcesList returns an *unstructured.UnstructuredList representing all resources that matches the parent GVK in the current namespace

func GetParents

func GetParents(
	ctx context.Context,
	client *dynamic.DynamicClient,
	obj unstructured.Unstructured,
	parentRelation *Relationship,
	namespace, objName string,
	objResourceNode ResourceGraphNode,
	relationshipGraph graph.Graph[string, RelationshipGraphNode],
	resourceGraph graph.Graph[string, ResourceGraphNode],
) (graph.Graph[string, ResourceGraphNode], error)

GetParents returns a graph that includes all of the parent resources for the current obj that are described by the parentRelation

func GetParentsByOwnerReference

func GetParentsByOwnerReference(
	ctx context.Context,
	client *dynamic.DynamicClient,
	obj unstructured.Unstructured,
	objResourceNode ResourceGraphNode,
	relationshipGraph graph.Graph[string, RelationshipGraphNode],
	resourceGraph graph.Graph[string, ResourceGraphNode],
) (graph.Graph[string, ResourceGraphNode], error)

GetParentsByOwnerReference returns a graph that includes all of the parent resources for the current obj described by its OwnerReferences field

func RelationshipEquals

func RelationshipEquals(r, relation *Relationship) bool

RelationshipEquals returns true if two relationships are equal

Types

type Relationship

type Relationship struct {
	ParentNode    *RelationshipGraphNode
	ChildNode     *RelationshipGraphNode
	AutoGenerated bool
	Group         string              `json:"group,omitempty" yaml:"group,omitempty"`
	Version       string              `json:"version,omitempty" yaml:"version,omitempty"`
	Kind          string              `json:"kind,omitempty" yaml:"kind,omitempty"`
	ClusterScoped bool                `json:"clusterScoped,omitempty" yaml:"clusterScoped,omitempty"`
	Type          string              `json:"type,omitempty" yaml:"type,omitempty"`
	SelectorPath  string              `json:"selectorPath,omitempty" yaml:"selectorPath,omitempty"`
	JSONPath      []map[string]string `json:"jsonPath,omitempty" yaml:"jsonPath,omitempty"`
}

Relationship represents a connection between parent and child nodes in the relationship graph.

func InsertIfNotExist

func InsertIfNotExist(relationList []*Relationship, relation Relationship, relationshipDirection string) ([]*Relationship, error)

InsertIfNotExist inserts relation into relationList only if it does not exist already This is used to auto-generate two-way relationships when they are not declared explicitly

func (Relationship) GetHash

func (r Relationship) GetHash() string

GetHash method returns the hash of the relationship.

type RelationshipGraph

type RelationshipGraph struct {
	RelationshipNodes []*RelationshipGraphNode `json:"relationship,omitempty" yaml:"relationship,omitempty"`
}

RelationshipGraph represents the graph structure containing the relationships between nodes.

func BuildBuiltinRelationshipGraph

func BuildBuiltinRelationshipGraph(ctx context.Context, client *dynamic.DynamicClient) (graph.Graph[string, RelationshipGraphNode], *RelationshipGraph, error)

BuildBuiltinRelationshipGraph returns the relationship graph built from the YAML describing resource relationships

func BuildRelationshipGraph

BuildRelationshipGraph builds the complete relationship graph including the built-in one and customer-specified one

func (*RelationshipGraph) CountRelationshipGraph

func (rg *RelationshipGraph) CountRelationshipGraph(ctx context.Context, dynamicClient *dynamic.DynamicClient, discoveryClient *discovery.DiscoveryClient, countNamespace string) (*RelationshipGraph, error)

CountRelationshipGraph returns the same RelationshipGraph with the count for each resource

func (*RelationshipGraph) CountRelationshipGraphByCustomResourceGroup

func (rg *RelationshipGraph) CountRelationshipGraphByCustomResourceGroup(ctx context.Context, cl storage.SearchStorage, resourceGroup *entity.ResourceGroup, name string) (*RelationshipGraph, error)

CountRelationshipGraphByCustomResourceGroup returns the same RelationshipGraph with the count for each custom resource group

func (*RelationshipGraph) FindNodeByGVK

func (rg *RelationshipGraph) FindNodeByGVK(group, version, kind string) (*RelationshipGraphNode, error)

FindNodeByGVK locates the Node by GVK on a RelationshipGraph. Used to locate parent and child nodes when building the relationship graph

type RelationshipGraphNode

type RelationshipGraphNode struct {
	Group         string          `json:"group,omitempty" yaml:"group,omitempty"`
	Version       string          `json:"version,omitempty" yaml:"version,omitempty"`
	Kind          string          `json:"kind,omitempty" yaml:"kind,omitempty"`
	Parent        []*Relationship `json:"parent,omitempty" yaml:"parent,omitempty"`
	Children      []*Relationship `json:"children,omitempty" yaml:"children,omitempty"`
	ResourceCount int             `json:"resourceCount,omitempty" yaml:"resourceCount,omitempty"`
}

RelationshipGraphNode represents a node in the relationship graph.

func FindNodeOnGraph

func FindNodeOnGraph(g graph.Graph[string, RelationshipGraphNode], group, version, kind string) (*RelationshipGraphNode, error)

FindNodeOnGraph locates the Node on a built relationship graph. Used to locate parent and child nodes when traversing the relationship graph

func (RelationshipGraphNode) ConvertToMap

func (rgn RelationshipGraphNode) ConvertToMap() map[string]string

ConvertToMap method converts the relationship graph node to a map[string]string.

func (RelationshipGraphNode) GetHash

func (rgn RelationshipGraphNode) GetHash() string

GetHash method returns the hash of the relationship graph node.

type ResourceGraphNode

type ResourceGraphNode struct {
	Name      string
	Namespace string
	Group     string
	Version   string
	Kind      string
	Parent    []*ResourceGraphNode
	Children  []*ResourceGraphNode
}

ResourceGraphNode represents a node in the resource graph, containing resource-specific information.

func (ResourceGraphNode) GetHash

func (rgn ResourceGraphNode) GetHash() string

GetHash method returns the hash of the resource graph node.

Jump to

Keyboard shortcuts

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