refactor: dedup pod group summary functions

This commit is contained in:
Matthias Radestock
2016-09-09 15:41:49 +01:00
parent 39be421141
commit 7f7766425e

View File

@@ -65,9 +65,9 @@ func MakeNodeSummary(r report.Report, n report.Node) (NodeSummary, bool) {
report.Container: containerNodeSummary,
report.ContainerImage: containerImageNodeSummary,
report.Pod: podNodeSummary,
report.Service: serviceNodeSummary,
report.Deployment: deploymentNodeSummary,
report.ReplicaSet: replicaSetNodeSummary,
report.Service: podGroupNodeSummary,
report.Deployment: podGroupNodeSummary,
report.ReplicaSet: podGroupNodeSummary,
report.Host: hostNodeSummary,
}
if renderer, ok := renderers[n.Topology]; ok {
@@ -225,42 +225,11 @@ func podNodeSummary(base NodeSummary, n report.Node) (NodeSummary, bool) {
return base, true
}
func serviceNodeSummary(base NodeSummary, n report.Node) (NodeSummary, bool) {
base = addKubernetesLabelAndRank(base, n)
base.Stack = true
// Services are always just a group of pods, so there's no counting multiple
// services which might be grouped together.
if p, ok := n.Counters.Lookup(report.Pod); ok {
if p == 1 {
base.LabelMinor = fmt.Sprintf("%d pod", p)
} else {
base.LabelMinor = fmt.Sprintf("%d pods", p)
}
}
return base, true
}
func deploymentNodeSummary(base NodeSummary, n report.Node) (NodeSummary, bool) {
base = addKubernetesLabelAndRank(base, n)
base.Stack = true
if p, ok := n.Counters.Lookup(report.Pod); ok {
if p == 1 {
base.LabelMinor = fmt.Sprintf("%d pod", p)
} else {
base.LabelMinor = fmt.Sprintf("%d pods", p)
}
}
return base, true
}
func replicaSetNodeSummary(base NodeSummary, n report.Node) (NodeSummary, bool) {
func podGroupNodeSummary(base NodeSummary, n report.Node) (NodeSummary, bool) {
base = addKubernetesLabelAndRank(base, n)
base.Stack = true
// NB: pods are the highest aggregation level for which we display counts.
if p, ok := n.Counters.Lookup(report.Pod); ok {
if p == 1 {
base.LabelMinor = fmt.Sprintf("%d pod", p)