Skip to content

Commit

Permalink
Extract namespaces from report.Namespace
Browse files Browse the repository at this point in the history
This avoids unnecessary loops.
  • Loading branch information
Roberto Bruggemann committed Dec 14, 2017
1 parent 2a2226c commit 1e7a84e
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions app/api_topologies.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,26 +95,14 @@ func updateSwarmFilters(rpt report.Report, topologies []APITopologyDesc) []APITo
}

func updateKubeFilters(rpt report.Report, topologies []APITopologyDesc) []APITopologyDesc {
namespaces := map[string]struct{}{}
// We exclude ReplicaSets since we don't show them anywhere.
for _, t := range []report.Topology{rpt.Pod, rpt.Service, rpt.Deployment, rpt.DaemonSet, rpt.StatefulSet, rpt.CronJob} {
for _, n := range t.Nodes {
if state, ok := n.Latest.Lookup(kubernetes.State); ok && state == kubernetes.StateDeleted {
continue
}
if namespace, ok := n.Latest.Lookup(kubernetes.Namespace); ok {
namespaces[namespace] = struct{}{}
}
}
}
if len(namespaces) == 0 {
// We only want to apply k8s filters when we have k8s-related nodes,
// so if we don't then return early
return topologies
}
ns := []string{}
for namespace := range namespaces {
ns = append(ns, namespace)
for _, n := range rpt.Namespace.Nodes {
name, ok := n.Latest.Lookup(kubernetes.Name)
if !ok {
log.Errorf("Error while fetching the namespace's name: %v", n)
continue
}
ns = append(ns, name)
}
sort.Strings(ns)
topologies = append([]APITopologyDesc{}, topologies...) // Make a copy so we can make changes safely
Expand Down

0 comments on commit 1e7a84e

Please sign in to comment.