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