forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
edges.go
120 lines (104 loc) · 3.99 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package graph
import (
"github.com/gonum/graph"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kapi "k8s.io/kubernetes/pkg/api"
osgraph "github.com/openshift/origin/pkg/api/graph"
kubeedges "github.com/openshift/origin/pkg/api/kubegraph"
kubegraph "github.com/openshift/origin/pkg/api/kubegraph/nodes"
deployapi "github.com/openshift/origin/pkg/deploy/api"
deploygraph "github.com/openshift/origin/pkg/deploy/graph/nodes"
imageapi "github.com/openshift/origin/pkg/image/api"
imagegraph "github.com/openshift/origin/pkg/image/graph/nodes"
)
const (
// TriggersDeploymentEdgeKind points from DeploymentConfigs to ImageStreamTags that trigger the deployment
TriggersDeploymentEdgeKind = "TriggersDeployment"
// UsedInDeploymentEdgeKind points from DeploymentConfigs to DockerImageReferences that are used in the deployment
UsedInDeploymentEdgeKind = "UsedInDeployment"
// DeploymentEdgeKind points from DeploymentConfigs to the ReplicationControllers that are fulfilling the deployment
DeploymentEdgeKind = "Deployment"
// VolumeClaimEdgeKind goes from DeploymentConfigs to PersistentVolumeClaims indicating a request for persistent storage.
VolumeClaimEdgeKind = "VolumeClaim"
)
// 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 {
podTemplate := node.DeploymentConfig.Spec.Template
if podTemplate == nil {
return node
}
deployapi.EachTemplateImage(
&podTemplate.Spec,
deployapi.DeploymentConfigHasTrigger(node.DeploymentConfig),
func(image deployapi.TemplateImage, err error) {
if err != nil {
return
}
if image.From != nil {
if len(image.From.Name) == 0 {
return
}
name, tag, _ := imageapi.SplitImageStreamTag(image.From.Name)
in := imagegraph.FindOrCreateSyntheticImageStreamTagNode(g, imagegraph.MakeImageStreamTagObjectMeta(image.From.Namespace, name, tag))
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 rcNode.ReplicationController.Namespace != node.DeploymentConfig.Namespace {
continue
}
if BelongsToDeploymentConfig(node.DeploymentConfig, rcNode.ReplicationController) {
g.AddEdge(node, rcNode, DeploymentEdgeKind)
g.AddEdge(rcNode, node, kubeedges.ManagedByControllerEdgeKind)
}
}
}
return node
}
func AddAllDeploymentEdges(g osgraph.MutableUniqueGraph) {
for _, node := range g.(graph.Graph).Nodes() {
if dcNode, ok := node.(*deploygraph.DeploymentConfigNode); ok {
AddDeploymentEdges(g, dcNode)
}
}
}
func AddVolumeClaimEdges(g osgraph.Graph, dcNode *deploygraph.DeploymentConfigNode) {
for _, volume := range dcNode.DeploymentConfig.Spec.Template.Spec.Volumes {
source := volume.VolumeSource
if source.PersistentVolumeClaim == nil {
continue
}
syntheticClaim := &kapi.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
Name: source.PersistentVolumeClaim.ClaimName,
Namespace: dcNode.DeploymentConfig.Namespace,
},
}
pvcNode := kubegraph.FindOrCreateSyntheticPVCNode(g, syntheticClaim)
// TODO: Consider direction
g.AddEdge(dcNode, pvcNode, VolumeClaimEdgeKind)
}
}
func AddAllVolumeClaimEdges(g osgraph.Graph) {
for _, node := range g.Nodes() {
if dcNode, ok := node.(*deploygraph.DeploymentConfigNode); ok {
AddVolumeClaimEdges(g, dcNode)
}
}
}