forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
edges.go
56 lines (47 loc) · 2.34 KB
/
edges.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package graph
import (
"github.com/gonum/graph"
osgraph "github.com/openshift/origin/pkg/api/graph"
imageapi "github.com/openshift/origin/pkg/image/api"
imagegraph "github.com/openshift/origin/pkg/image/graph/nodes"
)
const (
// ReferencedImageStreamGraphEdgeKind is an edge that goes from an ImageStreamTag node back to an ImageStream
ReferencedImageStreamGraphEdgeKind = "ReferencedImageStreamGraphEdge"
// ReferencedImageStreamImageGraphEdgeKind is an edge that goes from an ImageStreamImage node back to an ImageStream
ReferencedImageStreamImageGraphEdgeKind = "ReferencedImageStreamImageGraphEdgeKind"
)
// AddImageStreamTagRefEdge ensures that a directed edge exists between an IST Node and the IS it references
func AddImageStreamTagRefEdge(g osgraph.MutableUniqueGraph, node *imagegraph.ImageStreamTagNode) {
isName, _, _ := imageapi.SplitImageStreamTag(node.Name)
imageStream := &imageapi.ImageStream{}
imageStream.Namespace = node.Namespace
imageStream.Name = isName
imageStreamNode := imagegraph.FindOrCreateSyntheticImageStreamNode(g, imageStream)
g.AddEdge(node, imageStreamNode, ReferencedImageStreamGraphEdgeKind)
}
// AddImageStreamImageRefEdge ensures that a directed edge exists between an ImageStreamImage Node and the IS it references
func AddImageStreamImageRefEdge(g osgraph.MutableUniqueGraph, node *imagegraph.ImageStreamImageNode) {
dockImgRef, _ := imageapi.ParseDockerImageReference(node.Name)
imageStream := &imageapi.ImageStream{}
imageStream.Namespace = node.Namespace
imageStream.Name = dockImgRef.Name
imageStreamNode := imagegraph.FindOrCreateSyntheticImageStreamNode(g, imageStream)
g.AddEdge(node, imageStreamNode, ReferencedImageStreamImageGraphEdgeKind)
}
// AddAllImageStreamRefEdges calls AddImageStreamRefEdge for every ImageStreamTagNode in the graph
func AddAllImageStreamRefEdges(g osgraph.MutableUniqueGraph) {
for _, node := range g.(graph.Graph).Nodes() {
if istNode, ok := node.(*imagegraph.ImageStreamTagNode); ok {
AddImageStreamTagRefEdge(g, istNode)
}
}
}
// AddAllImageStreamImageRefEdges calls AddImageStreamImageRefEdge for every ImageStreamImageNode in the graph
func AddAllImageStreamImageRefEdges(g osgraph.MutableUniqueGraph) {
for _, node := range g.(graph.Graph).Nodes() {
if isimageNode, ok := node.(*imagegraph.ImageStreamImageNode); ok {
AddImageStreamImageRefEdge(g, isimageNode)
}
}
}