增加创建pod后的超时机制
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
|||||||
"coredump-tools/types"
|
"coredump-tools/types"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"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
|
// Wait for the Pod to be running and ready
|
||||||
fmt.Printf("Waiting for Pod %q to be ready...\n", podName)
|
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{})
|
result, err := clientset.CoreV1().Pods("default").Get(context.Background(), podName, metav1.GetOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return podName, err
|
return podName, err
|
||||||
}
|
}
|
||||||
status := result.Status
|
status := result.Status
|
||||||
if status.Phase == v1.PodRunning && len(status.ContainerStatuses) > 0 && status.ContainerStatuses[0].Ready {
|
if status.Phase == v1.PodRunning && len(status.ContainerStatuses) > 0 && status.ContainerStatuses[0].Ready {
|
||||||
|
ready = true
|
||||||
break
|
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
|
// Exec into the container
|
||||||
// Create exec request
|
// Create exec request
|
||||||
var cmd []string
|
var cmd []string
|
||||||
|
|||||||
Reference in New Issue
Block a user