Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

render/pod: Remove unused options and incorrect code #2673

Merged
merged 2 commits into from
Jul 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions render/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
// ECSTaskRenderer is a Renderer for Amazon ECS tasks.
var ECSTaskRenderer = ConditionalRenderer(renderECSTopologies,
renderParents(
report.Container, []string{report.ECSTask}, NoParentsPseudo, UnmanagedID, nil,
report.Container, []string{report.ECSTask}, UnmanagedID,
MakeFilter(
IsRunning,
ContainerWithImageNameRenderer,
Expand All @@ -18,7 +18,7 @@ var ECSTaskRenderer = ConditionalRenderer(renderECSTopologies,
// ECSServiceRenderer is a Renderer for Amazon ECS services.
var ECSServiceRenderer = ConditionalRenderer(renderECSTopologies,
renderParents(
report.ECSTask, []string{report.ECSService}, NoParentsDrop, "", nil,
report.ECSTask, []string{report.ECSService}, "",
ECSTaskRenderer,
),
)
Expand Down
81 changes: 15 additions & 66 deletions render/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@ func isPauseContainer(n report.Node) bool {
return ok && kubernetes.IsPauseImageName(image)
}

type noParentsActionEnum int

// Constants for specifying noParentsAction in Map2Parent
const (
NoParentsPseudo noParentsActionEnum = iota
NoParentsDrop
NoParentsKeep
)

// PodRenderer is a Renderer which produces a renderable kubernetes
// graph by merging the container graph and the pods topology.
var PodRenderer = ConditionalRenderer(renderKubernetesTopologies,
Expand All @@ -47,7 +38,7 @@ var PodRenderer = ConditionalRenderer(renderKubernetesTopologies,
MakeMap(
PropagateSingleMetrics(report.Container),
MakeMap(
Map2Parent([]string{report.Pod}, NoParentsPseudo, UnmanagedID, nil),
Map2Parent([]string{report.Pod}, UnmanagedID),
MakeFilter(
ComposeFilterFuncs(
IsRunning,
Expand All @@ -67,7 +58,7 @@ var PodRenderer = ConditionalRenderer(renderKubernetesTopologies,
// graph by merging the pods graph and the services topology.
var PodServiceRenderer = ConditionalRenderer(renderKubernetesTopologies,
renderParents(
report.Pod, []string{report.Service}, NoParentsDrop, "", nil,
report.Pod, []string{report.Service}, "",
PodRenderer,
),
)
Expand All @@ -78,18 +69,15 @@ var PodServiceRenderer = ConditionalRenderer(renderKubernetesTopologies,
// have connections to each other.
var KubeControllerRenderer = ConditionalRenderer(renderKubernetesTopologies,
renderParents(
report.Pod, []string{report.Deployment, report.DaemonSet},
NoParentsPseudo, UnmanagedID, makePodsChildren,
report.Pod, []string{report.Deployment, report.DaemonSet}, UnmanagedID,
PodRenderer,
),
)

// renderParents produces a 'standard' renderer for mapping from some child topology to some parent topologies,
// by taking a child renderer, mapping to parents, propagating single metrics, and joining with full parent topology.
// Most options are as per Map2Parent.
func renderParents(childTopology string, parentTopologies []string, noParentsAction noParentsActionEnum,
noParentsPseudoID string, modifyMappedNode func(parent, original report.Node) report.Node,
childRenderer Renderer) Renderer {
// Other options are as per Map2Parent.
func renderParents(childTopology string, parentTopologies []string, noParentsPseudoID string, childRenderer Renderer) Renderer {
selectors := make([]Renderer, len(parentTopologies))
for i, topology := range parentTopologies {
selectors[i] = TopologySelector(topology)
Expand All @@ -99,7 +87,7 @@ func renderParents(childTopology string, parentTopologies []string, noParentsAct
MakeMap(
PropagateSingleMetrics(childTopology),
MakeMap(
Map2Parent(parentTopologies, noParentsAction, noParentsPseudoID, modifyMappedNode),
Map2Parent(parentTopologies, noParentsPseudoID),
childRenderer,
),
),
Expand Down Expand Up @@ -135,26 +123,6 @@ func (s selectPodsWithDeployments) Stats(rpt report.Report, _ Decorator) Stats {
return Stats{}
}

// When mapping from pods to deployments, complete the two-way relation by making the
// mapped-from pod a child of the mapped-to deployment, and remove any replica set children.
// This is needed because pods were originally mapped to deployments via an intermediate replica set
// which we need to remove.
func makePodsChildren(parent, original report.Node) report.Node {
children := parent.Children
// Gather all the replica sets...
replicaSetIDs := []string{}
children.ForEach(func(n report.Node) {
if n.Topology == report.ReplicaSet {
replicaSetIDs = append(replicaSetIDs, n.ID)
}
})
// ...and delete them.
children = children.Delete(replicaSetIDs...)
// Then add in the mapped-from pod.
children = children.Add(original)
return parent.WithChildren(children)
}

// MapPod2IP maps pod nodes to their IP address. This allows pods to
// be joined directly with the endpoint topology.
func MapPod2IP(m report.Node) []string {
Expand All @@ -176,21 +144,13 @@ func MapPod2IP(m report.Node) []string {
func Map2Parent(
// The topology IDs to look for parents in
topologies []string,
// Choose what to do in the case of nodes with no parents. One of:
// NoParentsPseudo: Map them to a common pseudo node id with prefix noParentsPseudoID
// NoParentsDrop: Map them to no node.
// NoParentsKeep: Map them to themselves, preserving them in the new graph.
noParentsAction noParentsActionEnum,
// The ID prefix of the pseudo node to use for nodes without any parents in the group
// if noParentsAction == Pseudo, eg. UnmanagedID
// Either the ID prefix of the pseudo node to use for nodes without
// any parents in the group, eg. UnmanagedID, or "" to drop nodes without any parents.
noParentsPseudoID string,
// Optional (can be nil) function to modify any parent nodes,
// eg. to copy over details from the original node.
modifyMappedNode func(parent, original report.Node) report.Node,
) MapFunc {
return func(n report.Node, _ report.Networks) report.Nodes {
// Uncontained becomes Unmanaged/whatever if noParentsAction == Pseudo
if noParentsAction == NoParentsPseudo && strings.HasPrefix(n.ID, UncontainedIDPrefix) {
// Uncontained becomes Unmanaged/whatever if noParentsPseudoID is set
if noParentsPseudoID != "" && strings.HasPrefix(n.ID, UncontainedIDPrefix) {
id := MakePseudoNodeID(noParentsPseudoID, report.ExtractHostID(n))
node := NewDerivedPseudoNode(id, n)
return report.Nodes{id: node}
Expand All @@ -208,27 +168,16 @@ func Map2Parent(
for _, id := range groupIDs {
node := NewDerivedNode(id, n).WithTopology(topology)
node.Counters = node.Counters.Add(n.Topology, 1)
if modifyMappedNode != nil {
node = modifyMappedNode(node, n)
}
result[id] = node
}
}
}

if len(result) == 0 {
switch noParentsAction {
case NoParentsPseudo:
// Map to pseudo node
id := MakePseudoNodeID(UnmanagedID, report.ExtractHostID(n))
node := NewDerivedPseudoNode(id, n)
result[id] = node
case NoParentsKeep:
// Pass n to output unmodified
result[n.ID] = n
case NoParentsDrop:
// Do nothing, we will return an empty result
}
if len(result) == 0 && noParentsPseudoID != "" {
// Map to pseudo node
id := MakePseudoNodeID(UnmanagedID, report.ExtractHostID(n))
node := NewDerivedPseudoNode(id, n)
result[id] = node
}

return result
Expand Down
2 changes: 1 addition & 1 deletion render/swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
// SwarmServiceRenderer is a Renderer for Docker Swarm services
var SwarmServiceRenderer = ConditionalRenderer(renderSwarmTopologies,
renderParents(
report.Container, []string{report.SwarmService}, NoParentsPseudo, UnmanagedID, nil,
report.Container, []string{report.SwarmService}, UnmanagedID,
MakeFilter(
IsRunning,
ContainerWithImageNameRenderer,
Expand Down