diff --git a/test/e2e/e2e.go b/test/e2e/e2e.go index bfc5372b986..8e29e35de16 100644 --- a/test/e2e/e2e.go +++ b/test/e2e/e2e.go @@ -160,8 +160,24 @@ var _ = ginkgo.SynchronizedBeforeSuite(func() []byte { // Dump the output of the nethealth containers only once per run if framework.TestContext.DumpLogsOnFailure { - framework.Logf("Dumping network health container logs from all nodes") - framework.LogContainersInPodsWithLabels(c, metav1.NamespaceSystem, framework.ImagePullerLabels, "nethealth", framework.Logf) + logFunc := framework.Logf + if framework.TestContext.ReportDir != "" { + filePath := path.Join(framework.TestContext.ReportDir, "nethealth.txt") + file, err := os.Create(filePath) + if err != nil { + framework.Logf("Failed to create a file with network health data %v: %v\nPrinting to stdout", filePath, err) + } else { + defer file.Close() + if err = file.Chmod(0644); err != nil { + framework.Logf("Failed to chmod to 644 of %v: %v", filePath, err) + } + logFunc = framework.GetLogToFileFunc(file) + framework.Logf("Dumping network health container logs from all nodes to file %v", filePath) + } + } else { + framework.Logf("Dumping network health container logs from all nodes...") + } + framework.LogContainersInPodsWithLabels(c, metav1.NamespaceSystem, framework.ImagePullerLabels, "nethealth", logFunc) } // Reference common test to make the import valid. diff --git a/test/e2e/framework/framework.go b/test/e2e/framework/framework.go index 08e8dcf5f67..26a49b7d466 100644 --- a/test/e2e/framework/framework.go +++ b/test/e2e/framework/framework.go @@ -17,10 +17,12 @@ limitations under the License. package framework import ( + "bufio" "bytes" "encoding/json" "fmt" "io/ioutil" + "os" "path" "reflect" "strings" @@ -284,8 +286,25 @@ func (f *Framework) AfterEach() { if !f.SkipNamespaceCreation { DumpAllNamespaceInfo(f.ClientSet, f.Namespace.Name) } - By(fmt.Sprintf("Dumping a list of prepulled images on each node")) - LogContainersInPodsWithLabels(f.ClientSet, metav1.NamespaceSystem, ImagePullerLabels, "image-puller", Logf) + + logFunc := Logf + if TestContext.ReportDir != "" { + filePath := path.Join(TestContext.ReportDir, "image-puller.txt") + file, err := os.Create(filePath) + if err != nil { + By(fmt.Sprintf("Failed to create a file with image-puller data %v: %v\nPrinting to stdout", filePath, err)) + } else { + By(fmt.Sprintf("Dumping a list of prepulled images on each node to file %v", filePath)) + defer file.Close() + if err = file.Chmod(0644); err != nil { + Logf("Failed to chmod to 644 of %v: %v", filePath, err) + } + logFunc = GetLogToFileFunc(file) + } + } else { + By("Dumping a list of prepulled images on each node...") + } + LogContainersInPodsWithLabels(f.ClientSet, metav1.NamespaceSystem, ImagePullerLabels, "image-puller", logFunc) } summaries := make([]TestDataSummary, 0) @@ -848,3 +867,15 @@ func (cl *ClusterVerification) ForEach(podFunc func(v1.Pod)) error { return err } + +// GetLogToFileFunc is a convenience function that returns a function that have the same interface as +// Logf, but writes to a specified file. +func GetLogToFileFunc(file *os.File) func(format string, args ...interface{}) { + return func(format string, args ...interface{}) { + writer := bufio.NewWriter(file) + if _, err := fmt.Fprintf(writer, format, args...); err != nil { + Logf("Failed to write file %v with test performance data: %v", file.Name(), err) + } + writer.Flush() + } +} diff --git a/test/e2e/framework/metrics_util.go b/test/e2e/framework/metrics_util.go index 3424042f3c9..61655c554ca 100644 --- a/test/e2e/framework/metrics_util.go +++ b/test/e2e/framework/metrics_util.go @@ -33,6 +33,7 @@ import ( "k8s.io/kubernetes/pkg/client/clientset_generated/clientset" "k8s.io/kubernetes/pkg/master/ports" "k8s.io/kubernetes/pkg/metrics" + "k8s.io/kubernetes/pkg/util/system" "github.com/prometheus/common/expfmt" "github.com/prometheus/common/model" @@ -339,7 +340,7 @@ func getSchedulingLatency(c clientset.Interface) (SchedulingLatency, error) { var data string var masterRegistered = false for _, node := range nodes.Items { - if strings.HasSuffix(node.Name, "master") { + if system.IsMasterNode(node.Name) { masterRegistered = true } }