@@ -20,8 +20,9 @@ import (
20
20
const (
21
21
// ExposedThroughServiceEdgeKind goes from a PodTemplateSpec or a Pod to Service. The head should make the service's selector.
22
22
ExposedThroughServiceEdgeKind = "ExposedThroughService"
23
- // ManagedByRCEdgeKind goes from Pod to ReplicationController when the Pod satisfies the ReplicationController's label selector
24
- ManagedByRCEdgeKind = "ManagedByRC"
23
+ // ManagedByControllerEdgeKind goes from Pod to ReplicationController when the Pod satisfies the ReplicationController's label selector
24
+ // TODO: rename to ManagedByController, make generic to controller ref
25
+ ManagedByControllerEdgeKind = "ManagedByRC"
25
26
// MountedSecretEdgeKind goes from PodSpec to Secret indicating that is or will be a request to mount a volume with the Secret.
26
27
MountedSecretEdgeKind = "MountedSecret"
27
28
// MountableSecretEdgeKind goes from ServiceAccount to Secret indicating that the SA allows the Secret to be mounted
@@ -91,31 +92,36 @@ func AddAllExposedPodEdges(g osgraph.MutableUniqueGraph) {
91
92
}
92
93
}
93
94
94
- // AddManagedByRCPodEdges ensures that a directed edge exists between an RC and all the pods
95
+ // AddManagedByControllerPodEdges ensures that a directed edge exists between a controller and all the pods
95
96
// in the graph that match the label selector
96
- func AddManagedByRCPodEdges (g osgraph.MutableUniqueGraph , rcNode * kubegraph. ReplicationControllerNode ) {
97
- if rcNode . Spec . Selector == nil {
97
+ func AddManagedByControllerPodEdges (g osgraph.MutableUniqueGraph , to graph. Node , namespace string , selector map [ string ] string ) {
98
+ if selector == nil {
98
99
return
99
100
}
100
- query := labels .SelectorFromSet (rcNode . Spec . Selector )
101
+ query := labels .SelectorFromSet (selector )
101
102
for _ , n := range g .(graph.Graph ).Nodes () {
102
103
switch target := n .(type ) {
103
104
case * kubegraph.PodNode :
104
- if target .Namespace != rcNode . Namespace {
105
+ if target .Namespace != namespace {
105
106
continue
106
107
}
107
108
if query .Matches (labels .Set (target .Labels )) {
108
- g .AddEdge (target , rcNode , ManagedByRCEdgeKind )
109
+ g .AddEdge (target , to , ManagedByControllerEdgeKind )
109
110
}
110
111
}
111
112
}
112
113
}
113
114
114
- // AddAllManagedByRCPodEdges calls AddManagedByRCPodEdges for every ServiceNode in the graph
115
- func AddAllManagedByRCPodEdges (g osgraph.MutableUniqueGraph ) {
115
+ // AddAllManagedByControllerPodEdges calls AddManagedByControllerPodEdges for every node in the graph
116
+ // TODO: should do this through an interface (selects pods)
117
+ func AddAllManagedByControllerPodEdges (g osgraph.MutableUniqueGraph ) {
116
118
for _ , node := range g .(graph.Graph ).Nodes () {
117
- if rcNode , ok := node .(* kubegraph.ReplicationControllerNode ); ok {
118
- AddManagedByRCPodEdges (g , rcNode )
119
+ switch cast := node .(type ) {
120
+ case * kubegraph.ReplicationControllerNode :
121
+ AddManagedByControllerPodEdges (g , cast , cast .Namespace , cast .Spec .Selector )
122
+ case * kubegraph.PetSetNode :
123
+ // TODO: refactor to handle expanded selectors (along with ReplicaSets and Deployments)
124
+ AddManagedByControllerPodEdges (g , cast , cast .Namespace , cast .Spec .Selector .MatchLabels )
119
125
}
120
126
}
121
127
}
0 commit comments