Add Namespaces loging to kuberentes reporter
Namespaces might faild to delete and stuck
on Terminating, causing timeout errors to
tests-suite at AfterSuite.
Logging namespaces cluster object help debugging
these kind of issues.
@@ -95,6 +95,7 @@ func (r *KubernetesReporter) Dump(duration time.Duration) {
since := time.Now().Add(-duration)
r.logEvents(virtCli, since)
+ r.logNamespaces(virtCli)
r.logNodes(virtCli)
r.logPVCs(virtCli)
r.logPVs(virtCli)
@@ -433,6 +434,29 @@ func (r *KubernetesReporter) logSecrets(virtCli kubecli.KubevirtClient) {
fmt.Fprintln(f, string(j))
}
+func (r *KubernetesReporter) logNamespaces(virtCli kubecli.KubevirtClient) {
+ f, err := os.OpenFile(filepath.Join(r.artifactsDir, fmt.Sprintf("%d_namespaces.log", r.failureCount)),
+ os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "failed to open the file: %v\n", err)
+ return
+ }
+ defer f.Close()
+
+ namespaces, err := virtCli.CoreV1().Namespaces().List(metav1.ListOptions{})
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "failed to fetch Namespaces: %v\n", err)
+ return
+ }
+
+ j, err := json.MarshalIndent(namespaces, "", " ")
+ if err != nil {
+ log.DefaultLogger().Reason(err).Errorf("Failed to marshal Namespaces")
+ return
+ }
+ fmt.Fprintln(f, string(j))
+}
+
func (r *KubernetesReporter) logNodes(virtCli kubecli.KubevirtClient) {
f, err := os.OpenFile(filepath.Join(r.artifactsDir, fmt.Sprintf("%d_nodes.log", r.failureCount)),
