forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
nodes.go
127 lines (106 loc) · 3.95 KB
/
nodes.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
121
122
123
124
125
126
127
package nodes
import (
"github.com/gonum/graph"
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
osgraph "github.com/openshift/origin/pkg/api/graph"
)
func EnsurePodNode(g osgraph.MutableUniqueGraph, pod *kapi.Pod) *PodNode {
podNodeName := PodNodeName(pod)
podNode := osgraph.EnsureUnique(g,
podNodeName,
func(node osgraph.Node) graph.Node {
return &PodNode{node, pod}
},
).(*PodNode)
podSpecNode := EnsurePodSpecNode(g, &pod.Spec, podNodeName)
g.AddEdge(podNode, podSpecNode, osgraph.ContainsEdgeKind)
return podNode
}
func EnsurePodSpecNode(g osgraph.MutableUniqueGraph, podSpec *kapi.PodSpec, ownerName osgraph.UniqueName) *PodSpecNode {
return osgraph.EnsureUnique(g,
PodSpecNodeName(podSpec, ownerName),
func(node osgraph.Node) graph.Node {
return &PodSpecNode{node, podSpec, ownerName}
},
).(*PodSpecNode)
}
// EnsureServiceNode adds the provided service to the graph if it does not already exist.
func EnsureServiceNode(g osgraph.MutableUniqueGraph, svc *kapi.Service) *ServiceNode {
return osgraph.EnsureUnique(g,
ServiceNodeName(svc),
func(node osgraph.Node) graph.Node {
return &ServiceNode{node, svc}
},
).(*ServiceNode)
}
func EnsureServiceAccountNode(g osgraph.MutableUniqueGraph, o *kapi.ServiceAccount) *ServiceAccountNode {
return osgraph.EnsureUnique(g,
ServiceAccountNodeName(o),
func(node osgraph.Node) graph.Node {
return &ServiceAccountNode{node, o, true}
},
).(*ServiceAccountNode)
}
func FindOrCreateSyntheticServiceAccountNode(g osgraph.MutableUniqueGraph, o *kapi.ServiceAccount) *ServiceAccountNode {
return osgraph.EnsureUnique(g,
ServiceAccountNodeName(o),
func(node osgraph.Node) graph.Node {
return &ServiceAccountNode{node, o, false}
},
).(*ServiceAccountNode)
}
func EnsureSecretNode(g osgraph.MutableUniqueGraph, o *kapi.Secret) *SecretNode {
return osgraph.EnsureUnique(g,
SecretNodeName(o),
func(node osgraph.Node) graph.Node {
return &SecretNode{node, o, true}
},
).(*SecretNode)
}
func FindOrCreateSyntheticSecretNode(g osgraph.MutableUniqueGraph, o *kapi.Secret) *SecretNode {
return osgraph.EnsureUnique(g,
SecretNodeName(o),
func(node osgraph.Node) graph.Node {
return &SecretNode{node, o, false}
},
).(*SecretNode)
}
// EnsureReplicationControllerNode adds a graph node for the ReplicationController if it does not already exist.
func EnsureReplicationControllerNode(g osgraph.MutableUniqueGraph, rc *kapi.ReplicationController) *ReplicationControllerNode {
rcNodeName := ReplicationControllerNodeName(rc)
rcNode := osgraph.EnsureUnique(g,
rcNodeName,
func(node osgraph.Node) graph.Node {
return &ReplicationControllerNode{node, rc}
},
).(*ReplicationControllerNode)
rcSpecNode := EnsureReplicationControllerSpecNode(g, &rc.Spec, rcNodeName)
g.AddEdge(rcNode, rcSpecNode, osgraph.ContainsEdgeKind)
return rcNode
}
func EnsureReplicationControllerSpecNode(g osgraph.MutableUniqueGraph, rcSpec *kapi.ReplicationControllerSpec, ownerName osgraph.UniqueName) *ReplicationControllerSpecNode {
rcSpecName := ReplicationControllerSpecNodeName(rcSpec, ownerName)
rcSpecNode := osgraph.EnsureUnique(g,
rcSpecName,
func(node osgraph.Node) graph.Node {
return &ReplicationControllerSpecNode{node, rcSpec, ownerName}
},
).(*ReplicationControllerSpecNode)
if rcSpec.Template != nil {
ptSpecNode := EnsurePodTemplateSpecNode(g, rcSpec.Template, rcSpecName)
g.AddEdge(rcSpecNode, ptSpecNode, osgraph.ContainsEdgeKind)
}
return rcSpecNode
}
func EnsurePodTemplateSpecNode(g osgraph.MutableUniqueGraph, ptSpec *kapi.PodTemplateSpec, ownerName osgraph.UniqueName) *PodTemplateSpecNode {
ptSpecName := PodTemplateSpecNodeName(ptSpec, ownerName)
ptSpecNode := osgraph.EnsureUnique(g,
ptSpecName,
func(node osgraph.Node) graph.Node {
return &PodTemplateSpecNode{node, ptSpec, ownerName}
},
).(*PodTemplateSpecNode)
podSpecNode := EnsurePodSpecNode(g, &ptSpec.Spec, ptSpecName)
g.AddEdge(ptSpecNode, podSpecNode, osgraph.ContainsEdgeKind)
return ptSpecNode
}