DownloadFileContent downloads a capture file from a specific node and returns the content
(ctx context.Context, nodeName, hostPath, fileName, captureName string)
| 285 | |
| 286 | // DownloadFileContent downloads a capture file from a specific node and returns the content |
| 287 | func (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 | |
| 326 | func getCapturePods(ctx context.Context, kubeClient kubernetes.Interface, captureName, namespace string) (*corev1.PodList, error) { |
| 327 | pods, err := kubeClient.CoreV1().Pods(namespace).List(ctx, metav1.ListOptions{ |
no test coverage detected