From 85b15cfb84fc4e71d80f12c6f06ec0a6595782d7 Mon Sep 17 00:00:00 2001 From: linxin Date: Sat, 6 May 2023 16:57:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=88=9B=E5=BB=BApod?= =?UTF-8?q?=E5=90=8E=E7=9A=84=E8=B6=85=E6=97=B6=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- coredump-tool/coredump-tool.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/coredump-tool/coredump-tool.go b/coredump-tool/coredump-tool.go index bef8c25..3537601 100644 --- a/coredump-tool/coredump-tool.go +++ b/coredump-tool/coredump-tool.go @@ -5,6 +5,7 @@ import ( "coredump-tools/types" "crypto/rand" "encoding/json" + "errors" "flag" "fmt" "math/big" @@ -197,19 +198,22 @@ func debugInpod(conf *rest.Config, clientset *kubernetes.Clientset, config types // Wait for the Pod to be running and ready fmt.Printf("Waiting for Pod %q to be ready...\n", podName) - for { + ready := false + for i := 0; i < 10; i++ { result, err := clientset.CoreV1().Pods("default").Get(context.Background(), podName, metav1.GetOptions{}) if err != nil { return podName, err } status := result.Status if status.Phase == v1.PodRunning && len(status.ContainerStatuses) > 0 && status.ContainerStatuses[0].Ready { + ready = true break } - time.Sleep(1 * time.Second) + time.Sleep(2 * time.Second) + } + if !ready { + return podName, errors.New("create pod timeout") } - fmt.Printf("Pod %q is ready.\n", podName) - // Exec into the container // Create exec request var cmd []string