From 7b5f284d57af9e8b6869f1d9d1598336d774ea2a Mon Sep 17 00:00:00 2001 From: aerosouund Date: Fri, 18 Oct 2024 13:58:06 +0300 Subject: [PATCH] print pod logs for debugging Signed-off-by: aerosouund --- cluster-provision/gocli/opts/multus/multus.go | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/cluster-provision/gocli/opts/multus/multus.go b/cluster-provision/gocli/opts/multus/multus.go index acf6956fa3..806baa6b3f 100644 --- a/cluster-provision/gocli/opts/multus/multus.go +++ b/cluster-provision/gocli/opts/multus/multus.go @@ -4,6 +4,8 @@ import ( "bytes" _ "embed" "fmt" + "strings" + "time" "github.com/sirupsen/logrus" k8s "kubevirt.io/kubevirtci/cluster-provision/gocli/pkg/k8s" @@ -41,8 +43,36 @@ func (o *multusOpt) Exec() error { return fmt.Errorf("error applying manifest %s", err) } } - if err := o.sshClient.Command("kubectl --kubeconfig=/etc/kubernetes/admin.conf rollout status -n kube-system ds/kube-multus-ds --timeout=200s"); err != nil { - return err + var rolloutComplete bool + go func() { + err := o.sshClient.Command("kubectl --kubeconfig=/etc/kubernetes/admin.conf rollout status -n kube-system ds/kube-multus-ds --timeout=200s") + if err != nil { + fmt.Println("Rollout status failed:", err) + } + rolloutComplete = true + }() + + for { + if rolloutComplete { + break + } + cmd := "kubectl --kubeconfig=/etc/kubernetes/admin.conf get pods -n kube-system -l name=kube-multus-ds -o jsonpath='{.items[*].metadata.name}'" + pods, err := o.sshClient.CommandWithNoStdOut(cmd) + if err != nil { + fmt.Println("Failed to get pods:", err) + return err + } + + fmt.Println("Pods in kube-multus-ds DaemonSet:", pods) + for _, pod := range strings.Split(pods, " ") { + logCmd := fmt.Sprintf("kubectl --kubeconfig=/etc/kubernetes/admin.conf logs -n kube-system %s --tail=30", pod) + err := o.sshClient.Command(logCmd) + if err != nil { + fmt.Println("Failed to get logs for pod", pod, ":", err) + continue + } + } + time.Sleep(10 * time.Second) } return nil }