From 02a2d79bde66feaf152ead4974da6a735a009a79 Mon Sep 17 00:00:00 2001 From: Kenichi Omichi Date: Wed, 28 Aug 2019 23:03:43 +0000 Subject: [PATCH 1/2] Reduce indents of DumpAllNamespaceInfo() During cleanup of DumpAllNamespaceInfo(), the code was a little unreadable. This reduces the indents for the code readability. --- test/e2e/framework/util.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/test/e2e/framework/util.go b/test/e2e/framework/util.go index b825aae8d4c..356b41cf591 100644 --- a/test/e2e/framework/util.go +++ b/test/e2e/framework/util.go @@ -1769,14 +1769,15 @@ func DumpAllNamespaceInfo(c clientset.Interface, namespace string) { // 2. there are so many of them that working with them are mostly impossible // So we dump them only if the cluster is relatively small. maxNodesForDump := TestContext.MaxNodesToGather - if nodes, err := c.CoreV1().Nodes().List(metav1.ListOptions{}); err == nil { - if len(nodes.Items) <= maxNodesForDump { - dumpAllNodeInfo(c) - } else { - e2elog.Logf("skipping dumping cluster info - cluster too large") - } - } else { + nodes, err := c.CoreV1().Nodes().List(metav1.ListOptions{}) + if err != nil { e2elog.Logf("unable to fetch node list: %v", err) + return + } + if len(nodes.Items) <= maxNodesForDump { + dumpAllNodeInfo(c) + } else { + e2elog.Logf("skipping dumping cluster info - cluster too large") } } From da85510bd3329809507a3272d5394d8bd1fc8ede Mon Sep 17 00:00:00 2001 From: Kenichi Omichi Date: Wed, 28 Aug 2019 23:08:44 +0000 Subject: [PATCH 2/2] Reduce redundant Nodes().List() call dumpAllNodeInfo() called Nodes().List() internally, but the function is called from DumpAllNamespaceInfo() only and DumpAllNamespaceInfo() calls Nodes().List() before calling dumpAllNodeInfo(). So this makes the result of Nodes().List() being passed to dumpAllNodeInfo() then reduce a call of Nodes().List(). --- test/e2e/framework/util.go | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/test/e2e/framework/util.go b/test/e2e/framework/util.go index 356b41cf591..a84be9a4ac3 100644 --- a/test/e2e/framework/util.go +++ b/test/e2e/framework/util.go @@ -1775,7 +1775,7 @@ func DumpAllNamespaceInfo(c clientset.Interface, namespace string) { return } if len(nodes.Items) <= maxNodesForDump { - dumpAllNodeInfo(c) + dumpAllNodeInfo(c, nodes) } else { e2elog.Logf("skipping dumping cluster info - cluster too large") } @@ -1794,13 +1794,7 @@ func (o byFirstTimestamp) Less(i, j int) bool { return o[i].FirstTimestamp.Before(&o[j].FirstTimestamp) } -func dumpAllNodeInfo(c clientset.Interface) { - // It should be OK to list unschedulable Nodes here. - nodes, err := c.CoreV1().Nodes().List(metav1.ListOptions{}) - if err != nil { - e2elog.Logf("unable to fetch node list: %v", err) - return - } +func dumpAllNodeInfo(c clientset.Interface, nodes *v1.NodeList) { names := make([]string, len(nodes.Items)) for ix := range nodes.Items { names[ix] = nodes.Items[ix].Name