forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
edges.go
77 lines (65 loc) · 2.26 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package graph
import (
"github.com/gonum/graph"
osgraph "github.com/openshift/origin/pkg/api/graph"
kubegraph "github.com/openshift/origin/pkg/api/kubegraph/nodes"
deploygraph "github.com/openshift/origin/pkg/deploy/graph/nodes"
imagegraph "github.com/openshift/origin/pkg/image/graph/nodes"
)
const (
TriggersDeploymentEdgeKind = "TriggersDeployment"
UsedInDeploymentEdgeKind = "UsedInDeployment"
DeploymentEdgeKind = "Deployment"
)
// AddTriggerEdges creates edges that point to named Docker image repositories for each image used in the deployment.
func AddTriggerEdges(g osgraph.MutableUniqueGraph, node *deploygraph.DeploymentConfigNode) *deploygraph.DeploymentConfigNode {
rcTemplate := node.DeploymentConfig.Template.ControllerTemplate.Template
if rcTemplate == nil {
return node
}
EachTemplateImage(
&rcTemplate.Spec,
DeploymentConfigHasTrigger(node.DeploymentConfig),
func(image TemplateImage, err error) {
if err != nil {
return
}
if image.From != nil {
if len(image.From.Name) == 0 {
return
}
in := imagegraph.FindOrCreateSyntheticImageStreamTagNode(g, imagegraph.MakeImageStreamTagObjectMeta(image.From.Namespace, image.From.Name, image.FromTag))
g.AddEdge(in, node, TriggersDeploymentEdgeKind)
return
}
tag := image.Ref.Tag
image.Ref.Tag = ""
in := imagegraph.EnsureDockerRepositoryNode(g, image.Ref.String(), tag)
g.AddEdge(in, node, UsedInDeploymentEdgeKind)
})
return node
}
func AddAllTriggerEdges(g osgraph.MutableUniqueGraph) {
for _, node := range g.(graph.Graph).Nodes() {
if dcNode, ok := node.(*deploygraph.DeploymentConfigNode); ok {
AddTriggerEdges(g, dcNode)
}
}
}
func AddDeploymentEdges(g osgraph.MutableUniqueGraph, node *deploygraph.DeploymentConfigNode) *deploygraph.DeploymentConfigNode {
for _, n := range g.(graph.Graph).Nodes() {
if rcNode, ok := n.(*kubegraph.ReplicationControllerNode); ok {
if BelongsToDeploymentConfig(node.DeploymentConfig, rcNode.ReplicationController) {
g.AddEdge(node, rcNode, DeploymentEdgeKind)
}
}
}
return node
}
func AddAllDeploymentEdges(g osgraph.MutableUniqueGraph) {
for _, node := range g.(graph.Graph).Nodes() {
if dcNode, ok := node.(*deploygraph.DeploymentConfigNode); ok {
AddDeploymentEdges(g, dcNode)
}
}
}