genericgraph

package
v3.11.19-1+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2018 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnknownEdgeKind = "UnknownEdge"
	// ReferencedByEdgeKind is the kind to use if you're building reverse links that don't have a specific edge in the other direction
	// other uses are discouraged.  You should create a kind for your edge
	ReferencedByEdgeKind = "ReferencedBy"
	// ContainsEdgeKind is the kind to use if one node's contents logically contain another node's contents.  A given node can only have
	// a single inbound Contais edge.  The code does not prevent contains cycles, but that's insane, don't do that.
	ContainsEdgeKind = "Contains"
)
View Source
const (
	UnknownNodeKind = "UnknownNode"
)

Variables

This section is empty.

Functions

func AddReversedEdge

func AddReversedEdge(g Interface, from, to graph.Node, edgeKinds sets.String) bool

AddReversedEdge adds a reversed edge for every passed edge and preserves the existing edge. Used to convert a one directional edge into a bidirectional edge, but will create duplicate edges if a bidirectional edge between two nodes already exists.

func ExistingDirectEdge

func ExistingDirectEdge(g Interface, from, to graph.Node, edgeKinds sets.String) bool

ExistingDirectEdge returns true if both from and to already exist in the graph and the edge kind is not ReferencedByEdgeKind (the generic reverse edge kind). This will purge the graph of any edges created by AddReversedEdge.

func GetContainingNode

func GetContainingNode(g Graph, containedNode graph.Node) graph.Node

GetContainingNode returns the direct predecessor that is linked to the node by a ContainsEdgeKind. It returns nil if no container is found.

func GetTopLevelContainerNode

func GetTopLevelContainerNode(g Graph, containedNode graph.Node) graph.Node

GetTopLevelContainerNode traverses the reverse ContainsEdgeKind edges until it finds a node that does not have an inbound ContainsEdgeKind edge. This could be the node itself

func IsFromDifferentNamespace

func IsFromDifferentNamespace(namespace string, node graph.Node) bool

IsFromDifferentNamespace returns if a node is in a different namespace than the one provided.

func NodesByKind

func NodesByKind(g Interface, nodes []graph.Node, kinds ...string) [][]graph.Node

func ReverseExistingDirectEdge

func ReverseExistingDirectEdge(g Interface, from, to graph.Node, edgeKinds sets.String) bool

ReverseExistingDirectEdge reverses the order of the edge and drops the existing edge only if both from and to already exist in the graph and the edge kind is not ReferencedByEdgeKind (the generic reverse edge kind).

func ReverseGraphEdge

func ReverseGraphEdge(g Interface, from, to graph.Node, edgeKinds sets.String) bool

ReverseGraphEdge reverses the order of the edge and drops the existing edge.

Types

type ByID

type ByID []graph.Node

ByID is a sorted group of nodes by ID

func (ByID) Len

func (m ByID) Len() int

func (ByID) Less

func (m ByID) Less(i, j int) bool

func (ByID) Swap

func (m ByID) Swap(i, j int)

type ByKey

type ByKey []Marker

func (ByKey) Len

func (m ByKey) Len() int

func (ByKey) Less

func (m ByKey) Less(i, j int) bool

func (ByKey) Swap

func (m ByKey) Swap(i, j int)

type ByNodeID

type ByNodeID []Marker

func (ByNodeID) Len

func (m ByNodeID) Len() int

func (ByNodeID) Less

func (m ByNodeID) Less(i, j int) bool

func (ByNodeID) Swap

func (m ByNodeID) Swap(i, j int)

type BySeverity

type BySeverity []Marker

func (BySeverity) Len

func (m BySeverity) Len() int

func (BySeverity) Less

func (m BySeverity) Less(i, j int) bool

func (BySeverity) Swap

func (m BySeverity) Swap(i, j int)

type Edge

type Edge struct {
	simple.Edge
	// contains filtered or unexported fields
}

func NewEdge

func NewEdge(from, to graph.Node, weight float64, kinds ...string) Edge

func (Edge) DOTAttributes

func (e Edge) DOTAttributes() []dot.Attribute

DOTAttributes implements an attribute getter for the DOT encoding

func (Edge) IsKind

func (e Edge) IsKind(kind string) bool

func (Edge) Kinds

func (e Edge) Kinds() sets.String

type EdgeFunc

type EdgeFunc func(g Interface, from, to graph.Node, edgeKinds sets.String) bool

EdgeFunc is passed a new graph, an edge in the current graph, and should mutate the new graph as needed. If true is returned, the existing edge will be added to the graph.

func EdgesOfKind

func EdgesOfKind(kinds ...string) EdgeFunc

EdgesOfKind returns a new EdgeFunc accepting the provided kinds of edges If no kinds are specified, the returned EdgeFunc will accept all edges

func RemoveInboundEdges

func RemoveInboundEdges(nodes []graph.Node) EdgeFunc

RemoveInboundEdges returns a new EdgeFunc dismissing any inbound edges to the provided set of nodes

func RemoveOutboundEdges

func RemoveOutboundEdges(nodes []graph.Node) EdgeFunc

type ExistenceChecker

type ExistenceChecker interface {
	// Found returns false if the node represents an object that we don't have the backing object for
	Found() bool
}

ExistenceChecker is an interface for those nodes that can be created without a backing object. This can happen when a node wants an edge to a non-existent node. We know the node should exist, The graph needs something in that location to track the information we have about the node, but the backing object doesn't exist.

type Graph

type Graph struct {
	// the standard graph
	graph.DirectedBuilder
	// helper methods for switching on the kind and types of the node
	GraphDescriber
	// contains filtered or unexported fields
}

func New

func New() Graph

New initializes a graph from input to output.

func (Graph) AddEdge

func (g Graph) AddEdge(from, to graph.Node, edgeKind string)

AddEdge implements MutableUniqueGraph

func (Graph) AddNode

func (g Graph) AddNode(n graph.Node)

func (Graph) EdgeSubgraph

func (g Graph) EdgeSubgraph(edgeFn EdgeFunc) Graph

EdgeSubgraph returns the directed subgraph with only the edges that match the provided function.

func (Graph) Edges

func (g Graph) Edges() []graph.Edge

func (Graph) Find

func (g Graph) Find(name UniqueName) graph.Node

func (Graph) FindOrCreate

func (g Graph) FindOrCreate(name UniqueName, fn NodeInitializerFunc) (graph.Node, bool)

func (Graph) InboundEdges

func (g Graph) InboundEdges(node graph.Node, edgeKinds ...string) []graph.Edge

InboundEdges returns all the inbound edges to node that are in the list of edgeKinds if edgeKinds is empty, then all edges are returned

func (Graph) NodesByKind

func (g Graph) NodesByKind(nodeKinds ...string) []graph.Node

NodesByKind returns all the nodes of the graph with the provided kinds

func (Graph) OutboundEdges

func (g Graph) OutboundEdges(node graph.Node, edgeKinds ...string) []graph.Edge

OutboundEdges returns all the outbound edges from node that are in the list of edgeKinds if edgeKinds is empty, then all edges are returned

func (Graph) PredecessorEdges

func (g Graph) PredecessorEdges(node graph.Node, fn EdgeFunc, edgeKinds ...string)

PredecessorEdges invokes fn with all of the predecessor edges of node that have the specified edge kind.

func (Graph) PredecessorNodesByEdgeKind

func (g Graph) PredecessorNodesByEdgeKind(node graph.Node, edgeKinds ...string) []graph.Node

PredecessorNodesByEdgeKind returns all the predecessor nodes of the given node that can be reached via edges of the provided kinds

func (Graph) RemoveEdge

func (g Graph) RemoveEdge(e graph.Edge)

func (Graph) RemoveNode

func (g Graph) RemoveNode(node graph.Node)

func (Graph) String

func (g Graph) String() string

func (Graph) Subgraph

func (g Graph) Subgraph(nodeFn NodeFunc, edgeFn EdgeFunc) Graph

Subgraph returns the directed subgraph with only the nodes and edges that match the provided functions.

func (Graph) SubgraphWithNodes

func (g Graph) SubgraphWithNodes(nodes []graph.Node, fn EdgeFunc) Graph

SubgraphWithNodes returns the directed subgraph with only the listed nodes and edges that match the provided function.

func (Graph) SuccessorEdges

func (g Graph) SuccessorEdges(node graph.Node, fn EdgeFunc, edgeKinds ...string)

SuccessorEdges invokes fn with all of the successor edges of node that have the specified edge kind.

func (Graph) SuccessorNodesByEdgeKind

func (g Graph) SuccessorNodesByEdgeKind(node graph.Node, edgeKinds ...string) []graph.Node

SuccessorNodesByEdgeKind returns all the successor nodes of the given node that can be reached via edges of the provided kinds

func (Graph) SuccessorNodesByNodeAndEdgeKind

func (g Graph) SuccessorNodesByNodeAndEdgeKind(node graph.Node, nodeKind, edgeKind string) []graph.Node

type GraphDescriber

type GraphDescriber interface {
	Name(node graph.Node) string
	Kind(node graph.Node) string
	Object(node graph.Node) interface{}
	EdgeKinds(edge graph.Edge) sets.String
}

type Marker

type Marker struct {
	// Node is the optional node that this message is attached to
	Node graph.Node
	// RelatedNodes is an optional list of other nodes that are involved in this marker.
	RelatedNodes []graph.Node

	// Severity indicates how important this problem is.
	Severity Severity
	// Key is a short string to identify this message
	Key string

	// Message is a human-readable string that describes what is interesting
	Message string
	// Suggestion is a human-readable string that holds advice for resolving this
	// marker.
	Suggestion Suggestion
}

Marker is a struct that describes something interesting on a Node

type MarkerScanner

type MarkerScanner func(g Graph, f Namer) []Marker

MarkerScanner is a function for analyzing a graph and finding interesting things in it

type Markers

type Markers []Marker

func (Markers) BySeverity

func (m Markers) BySeverity(severity Severity) []Marker

func (Markers) FilterByNamespace

func (m Markers) FilterByNamespace(namespace string) Markers

FilterByNamespace returns all the markers that are not associated with missing nodes from other namespaces (other than the provided namespace).

type MutableDirectedEdge

type MutableDirectedEdge interface {
	AddEdge(from, to graph.Node, edgeKind string)
}

type Namer

type Namer interface {
	ResourceName(obj interface{}) string
}
var DefaultNamer Namer = namer{}

type Node

type Node struct {
	simple.Node
	UniqueName
}

func (Node) DOTAttributes

func (n Node) DOTAttributes() []dot.Attribute

DOTAttributes implements an attribute getter for the DOT encoding

type NodeFinder

type NodeFinder interface {
	Find(name UniqueName) graph.Node
}

type NodeFunc

type NodeFunc func(g Interface, n graph.Node) bool

NodeFunc is passed a new graph, a node in the graph, and should return true if the node should be included.

func NodesOfKind

func NodesOfKind(kinds ...string) NodeFunc

NodesOfKind returns a new NodeFunc accepting the provided kinds of nodes If no kinds are specified, the returned NodeFunc will accept all nodes

type NodeInitializerFunc

type NodeInitializerFunc func(Node) graph.Node

type Severity

type Severity string

Severity indicates how important this problem is.

const (
	// InfoSeverity is interesting
	// Currently used in missing probe markers
	InfoSeverity Severity = "info"
	// WarningSeverity is probably wrong, but we aren't certain
	WarningSeverity Severity = "warning"
	// ErrorSeverity is definitely wrong, this won't work
	ErrorSeverity Severity = "error"
)

type Suggestion

type Suggestion string

func (Suggestion) String

func (s Suggestion) String() string

type UniqueName

type UniqueName string

func GetUniqueRuntimeObjectNodeName

func GetUniqueRuntimeObjectNodeName(nodeKind string, obj runtime.Object) UniqueName

func (UniqueName) String

func (n UniqueName) String() string

func (UniqueName) UniqueName

func (n UniqueName) UniqueName() string

type UniqueNameFunc

type UniqueNameFunc func(obj interface{}) UniqueName

type UniqueNodeInitializer

type UniqueNodeInitializer interface {
	FindOrCreate(name UniqueName, fn NodeInitializerFunc) (graph.Node, bool)
}

UniqueNodeInitializer is a graph that allows nodes with a unique name to be added without duplication. If the node is newly added, true will be returned.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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