fix: correctly wait for the pod to be ready

This commit is contained in:
Jose Diaz-Gonzalez
2024-11-03 20:29:11 -05:00
parent 62125c5b72
commit adffab13d9
2 changed files with 9 additions and 8 deletions

View File

@@ -52,7 +52,7 @@ type EnterPodInput struct {
SelectedPod v1.Pod SelectedPod v1.Pod
// WaitTimeout is the timeout to wait for the pod to be ready // WaitTimeout is the timeout to wait for the pod to be ready
WaitTimeout int WaitTimeout float64
} }
// Node contains information about a node // Node contains information about a node
@@ -110,7 +110,7 @@ type WaitForPodBySelectorRunningInput struct {
Namespace string Namespace string
LabelSelector string LabelSelector string
PodName string PodName string
Timeout int Timeout float64
Waiter func(ctx context.Context, clientset KubernetesClient, podName, namespace string) wait.ConditionWithContextFunc Waiter func(ctx context.Context, clientset KubernetesClient, podName, namespace string) wait.ConditionWithContextFunc
} }
@@ -374,8 +374,8 @@ func enterPod(ctx context.Context, input EnterPodInput) error {
labelSelector = append(labelSelector, fmt.Sprintf("%s=%s", k, v)) labelSelector = append(labelSelector, fmt.Sprintf("%s=%s", k, v))
} }
if input.WaitTimeout > 0 { if input.WaitTimeout == 0 {
input.WaitTimeout = 5 input.WaitTimeout = 10
} }
err := waitForPodBySelectorRunning(ctx, WaitForPodBySelectorRunningInput{ err := waitForPodBySelectorRunning(ctx, WaitForPodBySelectorRunningInput{
@@ -1694,14 +1694,14 @@ func waitForPodBySelectorRunning(ctx context.Context, input WaitForPodBySelector
RetryCount: 3, RetryCount: 3,
}) })
if err != nil { if err != nil {
return fmt.Errorf("Error waiting for pod to exist: %w", err) return err
} }
if len(pods) == 0 { if len(pods) == 0 {
return fmt.Errorf("no pods in %s with selector %s", input.Namespace, input.LabelSelector) return fmt.Errorf("no pods in %s with selector %s", input.Namespace, input.LabelSelector)
} }
timeout := time.Duration(input.Timeout) * time.Second timeout := time.Duration(input.Timeout * float64(time.Second))
for _, pod := range pods { for _, pod := range pods {
if input.PodName != "" && pod.Name != input.PodName { if input.PodName != "" && pod.Name != input.PodName {
break break
@@ -1709,7 +1709,7 @@ func waitForPodBySelectorRunning(ctx context.Context, input WaitForPodBySelector
if err := wait.PollUntilContextTimeout(ctx, time.Second, timeout, false, input.Waiter(ctx, input.Clientset, pod.Name, pod.Namespace)); err != nil { if err := wait.PollUntilContextTimeout(ctx, time.Second, timeout, false, input.Waiter(ctx, input.Clientset, pod.Name, pod.Namespace)); err != nil {
print("\n") print("\n")
return fmt.Errorf("Error waiting for pod to be ready: %w", err) return err
} }
} }
print("\n") print("\n")

View File

@@ -1190,7 +1190,7 @@ func TriggerSchedulerRun(scheduler string, appName string, envCount int, args []
Clientset: clientset, Clientset: clientset,
Namespace: namespace, Namespace: namespace,
LabelSelector: batchJobSelector, LabelSelector: batchJobSelector,
Timeout: 300, Timeout: 10,
Waiter: isPodReady, Waiter: isPodReady,
}) })
if err != nil { if err != nil {
@@ -1254,6 +1254,7 @@ func TriggerSchedulerRun(scheduler string, appName string, envCount int, args []
Command: command, Command: command,
Entrypoint: entrypoint, Entrypoint: entrypoint,
SelectedPod: selectedPod, SelectedPod: selectedPod,
WaitTimeout: 10,
}) })
default: default:
return fmt.Errorf("Unable to attach as the pod is in an unknown state: %s", selectedPod.Status.Phase) return fmt.Errorf("Unable to attach as the pod is in an unknown state: %s", selectedPod.Status.Phase)