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 Jan 3, 2018
1 parent 4233b75 commit 1fb23dd
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions app/api_topologies.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,26 +95,13 @@ 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 {
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 1fb23dd

Please sign in to comment.