dep

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package dep provides lightweight Kubernetes resource dependency/dependent graph resolution, inspired by kube-lineage.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatJSON

func FormatJSON(result *Result, depsIsDependencies bool) (string, error)

FormatJSON renders the dependency result as a nested JSON structure.

func FormatTree

func FormatTree(result *Result, depsIsDependencies bool) string

FormatTree renders the dependency result as a kube-lineage-style tree string.

Types

type JSONNode

type JSONNode struct {
	Kind          string      `json:"kind"`
	Namespace     string      `json:"namespace,omitempty"`
	Name          string      `json:"name"`
	Ready         string      `json:"ready,omitempty"`
	Status        string      `json:"status,omitempty"`
	Age           string      `json:"age,omitempty"`
	Relationships []string    `json:"relationships,omitempty"`
	Children      []*JSONNode `json:"children,omitempty"`
}

JSONNode represents a node in JSON output format.

type Node

type Node struct {
	*unstructured.Unstructured
	UID          types.UID
	Kind         string
	Namespace    string
	Name         string
	Dependencies map[types.UID]RelationshipSet
	Dependents   map[types.UID]RelationshipSet
	Depth        uint
}

Node represents a Kubernetes object in a relationship tree.

func (*Node) AddDependency

func (n *Node) AddDependency(uid types.UID, r Relationship)

AddDependency adds a dependency relationship to this node.

func (*Node) AddDependent

func (n *Node) AddDependent(uid types.UID, r Relationship)

AddDependent adds a dependent relationship to this node.

func (*Node) GetDeps

func (n *Node) GetDeps(depsIsDependencies bool) map[types.UID]RelationshipSet

GetDeps returns either Dependencies or Dependents based on direction.

func (*Node) GetObjectReferenceKey

func (n *Node) GetObjectReferenceKey() ObjectReferenceKey

GetObjectReferenceKey returns the ObjectReferenceKey for this node.

type NodeList

type NodeList []*Node

NodeList contains a list of nodes for sorting.

func (NodeList) Len

func (n NodeList) Len() int

func (NodeList) Less

func (n NodeList) Less(i, j int) bool

func (NodeList) Swap

func (n NodeList) Swap(i, j int)

type NodeMap

type NodeMap map[types.UID]*Node

NodeMap contains a relationship tree stored as a map of nodes.

type ObjectReference

type ObjectReference struct {
	Group     string
	Kind      string
	Namespace string
	Name      string
}

ObjectReference is a reference to a Kubernetes object.

func (*ObjectReference) Key

Key converts the ObjectReference into an ObjectReferenceKey.

type ObjectReferenceKey

type ObjectReferenceKey string

ObjectReferenceKey is a compact string representation of an ObjectReference.

type Relationship

type Relationship string

Relationship represents a relationship type between two Kubernetes objects.

const (
	// Owner-Dependent relationships.
	RelationshipControllerRef Relationship = "ControllerReference"
	RelationshipOwnerRef      Relationship = "OwnerReference"

	// Pod relationships.
	RelationshipPodNode            Relationship = "PodNode"
	RelationshipPodServiceAccount  Relationship = "PodServiceAccount"
	RelationshipPodVolume          Relationship = "PodVolume"
	RelationshipPodContainerEnv    Relationship = "PodContainerEnvironment"
	RelationshipPodImagePullSecret Relationship = "PodImagePullSecret"

	// Service relationships.
	RelationshipService Relationship = "Service"

	// Ingress & IngressClass relationships.
	RelationshipIngressClass           Relationship = "IngressClass"
	RelationshipIngressClassParameters Relationship = "IngressClassParameters"
	RelationshipIngressService         Relationship = "IngressService"
	RelationshipIngressTLSSecret       Relationship = "IngressTLSSecret"

	// PersistentVolume & PersistentVolumeClaim relationships.
	RelationshipPersistentVolumeClaim        Relationship = "PersistentVolumeClaim"
	RelationshipPersistentVolumeStorageClass Relationship = "PersistentVolumeStorageClass"

	// RBAC relationships.
	RelationshipRoleBindingSubject        Relationship = "RoleBindingSubject"
	RelationshipRoleBindingRole           Relationship = "RoleBindingRole"
	RelationshipClusterRoleBindingSubject Relationship = "ClusterRoleBindingSubject"
	RelationshipClusterRoleBindingRole    Relationship = "ClusterRoleBindingRole"

	// PodDisruptionBudget relationships.
	RelationshipPodDisruptionBudget Relationship = "PodDisruptionBudget"

	// Event relationships.
	RelationshipEventRegarding Relationship = "EventRegarding"
)

Relationship constants for supported relationship types.

type RelationshipMap

type RelationshipMap struct {
	DependenciesByRef map[ObjectReferenceKey]RelationshipSet
	DependenciesByUID map[types.UID]RelationshipSet
	DependentsByRef   map[ObjectReferenceKey]RelationshipSet
	DependentsByUID   map[types.UID]RelationshipSet
}

RelationshipMap contains relationships a Kubernetes object has with others.

func NewRelationshipMap

func NewRelationshipMap() *RelationshipMap

NewRelationshipMap creates a new empty RelationshipMap.

func (*RelationshipMap) AddDependencyByKey

func (m *RelationshipMap) AddDependencyByKey(k ObjectReferenceKey, r Relationship)

AddDependencyByKey adds a dependency by object reference key.

func (*RelationshipMap) AddDependencyByUID

func (m *RelationshipMap) AddDependencyByUID(uid types.UID, r Relationship)

AddDependencyByUID adds a dependency by UID.

func (*RelationshipMap) AddDependentByKey

func (m *RelationshipMap) AddDependentByKey(k ObjectReferenceKey, r Relationship)

AddDependentByKey adds a dependent by object reference key.

type RelationshipSet

type RelationshipSet map[Relationship]struct{}

RelationshipSet contains a set of relationships.

func (RelationshipSet) List

func (s RelationshipSet) List() []string

List returns the contents as a sorted string slice.

type Result

type Result struct {
	NodeMap NodeMap
	RootUID types.UID
}

Result holds the output of a dependency resolution.

func Resolve

func Resolve(ctx context.Context, steveClient *steve.Client, clusterID, rootKind, rootNS, rootName, direction string, maxDepth int) (*Result, error)

Resolve resolves the dependency/dependent graph for a Kubernetes resource. direction: "dependents" (default) or "dependencies".

Jump to

Keyboard shortcuts

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