From 7f7766425ee3b2b78112565a668de21178f12eb0 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Fri, 9 Sep 2016 15:41:49 +0100 Subject: [PATCH] refactor: dedup pod group summary functions --- render/detailed/summary.go | 41 +++++--------------------------------- 1 file changed, 5 insertions(+), 36 deletions(-) diff --git a/render/detailed/summary.go b/render/detailed/summary.go index 5ce60bf33..e326b0b98 100644 --- a/render/detailed/summary.go +++ b/render/detailed/summary.go @@ -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)