k8s reporter: Limit node info collection
In order to save time and storage,
collect node info only for nodes which
runs at least one virt-launcher.
@@ -183,7 +183,7 @@ func (r *KubernetesReporter) dumpNamespaces(duration time.Duration, vmiNamespace
r.logSRIOVInfo(virtCli)
- r.logNodeCommands(virtCli, virtHandlerPods)
+ r.logNodeCommands(virtCli, nodesWithVirtLauncher)
r.logVirtLauncherCommands(virtCli, networkPodsDir)
r.logVirtLauncherPrivilegedCommands(virtCli, networkPodsDir, virtHandlerPods)
r.logVMICommands(virtCli, vmiNamespaces)
@@ -508,20 +508,20 @@ func (r *KubernetesReporter) logVirtLauncherCommands(virtCli kubecli.KubevirtCli
}
}
-func (r *KubernetesReporter) logNodeCommands(virtCli kubecli.KubevirtClient, virtHandlerPods *v1.PodList) {
-
- if virtHandlerPods == nil {
- fmt.Fprintf(os.Stderr, "virt-handler pod list is empty, skipping logNodeCommands\n")
- return
- }
-
+func (r *KubernetesReporter) logNodeCommands(virtCli kubecli.KubevirtClient, nodes []string) {
logsdir := filepath.Join(r.artifactsDir, "network", "nodes")
if err := os.MkdirAll(logsdir, 0777); err != nil {
fmt.Fprintf(os.Stderr, failedCreateLogsDirectoryFmt, logsdir, err)
return
}
- for _, pod := range virtHandlerPods.Items {
+ for _, node := range nodes {
+ pod, err := kubecli.NewVirtHandlerClient(virtCli).Namespace(flags.KubeVirtInstallNamespace).ForNode(node).Pod()
+ if err != nil {
+ fmt.Fprintf(os.Stderr, failedGetVirtHandlerPodFmt, node, err)
+ continue
+ }
+
if pod.Status.Phase != "Running" {
fmt.Fprintf(os.Stderr, "skipping node's pod %s, phase is not Running\n", pod.ObjectMeta.Name)
continue
@@ -1100,7 +1100,7 @@ func podHasComputeContainer(pod v1.Pod) bool {
return false
}
-func (r *KubernetesReporter) executeNodeCommands(virtCli kubecli.KubevirtClient, logsdir string, pod v1.Pod) {
+func (r *KubernetesReporter) executeNodeCommands(virtCli kubecli.KubevirtClient, logsdir string, pod *v1.Pod) {
const networkPrefix = "nsenter -t 1 -n -- "
hostPrefix := fmt.Sprintf("%s --mount %s exec -- ", virt_chroot.GetChrootBinaryPath(), virt_chroot.GetChrootMountNamespace())
@@ -1117,7 +1117,7 @@ func (r *KubernetesReporter) executeNodeCommands(virtCli kubecli.KubevirtClient,
{command: "[ -e /dev/vfio ] && ls -lsh -Z -St /dev/vfio", fileNameSuffix: "vfio-devices"},
}
- r.executeContainerCommands(virtCli, logsdir, &pod, virtHandlerName, cmds)
+ r.executeContainerCommands(virtCli, logsdir, pod, virtHandlerName, cmds)
}
func (r *KubernetesReporter) executeVirtLauncherCommands(virtCli kubecli.KubevirtClient, logsdir string, pod v1.Pod) {
