waitForPodReady waits for the pod to be in running state
(ctx context.Context, podName string)
| 401 | |
| 402 | // waitForPodReady waits for the pod to be in running state |
| 403 | func (ds *DownloadService) waitForPodReady(ctx context.Context, podName string) (*corev1.Pod, error) { |
| 404 | timeout := time.After(30 * time.Second) |
| 405 | ticker := time.NewTicker(1 * time.Second) |
| 406 | defer ticker.Stop() |
| 407 | |
| 408 | for { |
| 409 | select { |
| 410 | case <-timeout: |
| 411 | return nil, fmt.Errorf("timeout waiting for download pod to become ready: %w", ErrFailedToCreateDownloadPod) |
| 412 | case <-ticker.C: |
| 413 | pod, err := ds.kubeClient.CoreV1().Pods(ds.namespace).Get(ctx, podName, metav1.GetOptions{}) |
| 414 | if err != nil { |
| 415 | return nil, errors.Join(ErrGetDownloadPod, err) |
| 416 | } |
| 417 | if pod.Status.Phase == corev1.PodRunning { |
| 418 | return pod, nil |
| 419 | } |
| 420 | if pod.Status.Phase == corev1.PodFailed { |
| 421 | return nil, fmt.Errorf("download pod failed to spin up successfully: %w", ErrFailedToCreateDownloadPod) |
| 422 | } |
| 423 | } |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | // verifyFileExists checks if the target file exists and is accessible |
| 428 | func (ds *DownloadService) verifyFileExists(ctx context.Context, pod *corev1.Pod, downloadCmd *DownloadCmd) (bool, error) { |