MCPcopy
hub / github.com/microsoft/retina / createDownloadPod

Method createDownloadPod

cli/cmd/capture/download.go:355–400  ·  view source on GitHub ↗

createDownloadPod creates a pod for downloading files from the host

(ctx context.Context, nodeName, hostPath, captureName string, downloadCmd *DownloadCmd)

Source from the content-addressed store, hash-verified

353
354// createDownloadPod creates a pod for downloading files from the host
355func (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
403func (ds *DownloadService) waitForPodReady(ctx context.Context, podName string) (*corev1.Pod, error) {

Callers 2

DownloadFileContentMethod · 0.95

Calls 3

waitForPodReadyMethod · 0.95
StringMethod · 0.45
CreateMethod · 0.45

Tested by 1