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

Method DownloadFileContent

cli/cmd/capture/download.go:287–324  ·  view source on GitHub ↗

DownloadFileContent downloads a capture file from a specific node and returns the content

(ctx context.Context, nodeName, hostPath, fileName, captureName string)

Source from the content-addressed store, hash-verified

285
286// DownloadFileContent downloads a capture file from a specific node and returns the content
287func (ds *DownloadService) DownloadFileContent(ctx context.Context, nodeName, hostPath, fileName, captureName string) ([]byte, error) {
288 node, err := ds.kubeClient.CoreV1().Nodes().Get(ctx, nodeName, metav1.GetOptions{})
289 if err != nil {
290 return nil, errors.Join(ErrGetNodeInfo, err)
291 }
292
293 downloadCmd, err := getDownloadCmd(node, hostPath, fileName)
294 if err != nil {
295 return nil, err
296 }
297
298 fmt.Println("File to be downloaded: ", downloadCmd.SrcFilePath)
299 downloadPod, err := ds.createDownloadPod(ctx, nodeName, hostPath, captureName, downloadCmd)
300 if err != nil {
301 return nil, err
302 }
303
304 // Ensure cleanup
305 defer func() {
306 cleanupErr := ds.kubeClient.CoreV1().Pods(ds.namespace).Delete(ctx, downloadPod.Name, metav1.DeleteOptions{})
307 if cleanupErr != nil {
308 retinacmd.Logger.Warn("Failed to clean up debug pod", zap.String("name", downloadPod.Name), zap.Error(cleanupErr))
309 }
310 }()
311
312 fileExists, err := ds.verifyFileExists(ctx, downloadPod, downloadCmd)
313 if err != nil || !fileExists {
314 return nil, err
315 }
316
317 fmt.Println("Obtaining file...")
318 fileContent, err := ds.executeFileDownload(ctx, downloadPod, downloadCmd)
319 if err != nil {
320 return nil, err
321 }
322
323 return fileContent, nil
324}
325
326func getCapturePods(ctx context.Context, kubeClient kubernetes.Interface, captureName, namespace string) (*corev1.PodList, error) {
327 pods, err := kubeClient.CoreV1().Pods(namespace).List(ctx, metav1.ListOptions{

Callers 2

DownloadFileMethod · 0.95

Calls 8

createDownloadPodMethod · 0.95
verifyFileExistsMethod · 0.95
executeFileDownloadMethod · 0.95
getDownloadCmdFunction · 0.85
DeleteMethod · 0.65
GetMethod · 0.45
StringMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected