createDownloadPod creates a pod for downloading files from the host
(ctx context.Context, nodeName, hostPath, captureName string, downloadCmd *DownloadCmd)
| 353 | |
| 354 | // createDownloadPod creates a pod for downloading files from the host |
| 355 | func (ds *DownloadService) createDownloadPod(ctx context.Context, nodeName, hostPath, captureName string, downloadCmd *DownloadCmd) (*corev1.Pod, error) { |
| 356 | podName := captureName + "-download-" + rand.String(5) |
| 357 | |
| 358 | podSpec := &corev1.Pod{ |
| 359 | ObjectMeta: metav1.ObjectMeta{ |
| 360 | Name: podName, |
| 361 | Namespace: ds.namespace, |
| 362 | Labels: captureUtils.GetDownloadLabelsFromCaptureName(captureName), |
| 363 | }, |
| 364 | Spec: corev1.PodSpec{ |
| 365 | NodeName: nodeName, |
| 366 | Containers: []corev1.Container{ |
| 367 | { |
| 368 | Name: captureConstants.DownloadContainerName, |
| 369 | Image: downloadCmd.ContainerImage, |
| 370 | Command: downloadCmd.KeepAliveCommand, |
| 371 | VolumeMounts: []corev1.VolumeMount{ |
| 372 | { |
| 373 | Name: "host-mount", |
| 374 | MountPath: downloadCmd.MountPath, |
| 375 | }, |
| 376 | }, |
| 377 | }, |
| 378 | }, |
| 379 | RestartPolicy: corev1.RestartPolicyNever, |
| 380 | Volumes: []corev1.Volume{ |
| 381 | { |
| 382 | Name: "host-mount", |
| 383 | VolumeSource: corev1.VolumeSource{ |
| 384 | HostPath: &corev1.HostPathVolumeSource{ |
| 385 | Path: hostPath, |
| 386 | }, |
| 387 | }, |
| 388 | }, |
| 389 | }, |
| 390 | }, |
| 391 | } |
| 392 | |
| 393 | fmt.Printf("Creating download pod: %s\n", podName) |
| 394 | _, err := ds.kubeClient.CoreV1().Pods(ds.namespace).Create(ctx, podSpec, metav1.CreateOptions{}) |
| 395 | if err != nil { |
| 396 | return nil, errors.Join(ErrCreateDownloadPod, err) |
| 397 | } |
| 398 | |
| 399 | return ds.waitForPodReady(ctx, podName) |
| 400 | } |
| 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) { |