summaryrefslogtreecommitdiff
path: root/coredump-tool
diff options
context:
space:
mode:
authorlinxin <[email protected]>2023-05-06 16:57:28 +0800
committerlinxin <[email protected]>2023-05-06 16:57:28 +0800
commit85b15cfb84fc4e71d80f12c6f06ec0a6595782d7 (patch)
tree08f4e0b073fb8d845d510f17de21a7f333aece73 /coredump-tool
parentcd4cc4476cc4e0a3448e943dbff613718e7a7bd5 (diff)
增加创建pod后的超时机制
Diffstat (limited to 'coredump-tool')
-rw-r--r--coredump-tool/coredump-tool.go12
1 files 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