Skip to content

Commit 36c0476

Browse files
committed
E2E: Cleanup writeToFile
Signed-off-by: Lennart Jern <[email protected]>
1 parent 1857215 commit 36c0476

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

test/e2e/logcollector.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,10 @@ func FetchClusterLogs(clusterProxy framework.ClusterProxy, outputPath string) er
265265

266266
machineName := pod.Spec.NodeName
267267
podDir := filepath.Join(baseDir, "machines", machineName, namespace.Name, pod.Name)
268-
writeToFile([]byte(podDescription), "stdout_describe.log", podDir)
268+
err = writeToFile([]byte(podDescription), "stdout_describe.log", podDir)
269+
if err != nil {
270+
return fmt.Errorf("couldn't write to file: %v", err)
271+
}
269272

270273
// Get containers of the Pod
271274
for _, container := range pod.Spec.Containers {
@@ -307,25 +310,29 @@ func CollectContainerLogs(ctx context.Context, namespace string, podName string,
307310
}
308311
podStr := buf.String()
309312

310-
writeToFile([]byte(podStr), "stdout.log", outputPath)
313+
err = writeToFile([]byte(podStr), "stdout.log", outputPath)
314+
if err != nil {
315+
return fmt.Errorf("couldn't write to file: %v", err)
316+
}
311317

312318
return nil
313319
}
314320

315321
// writeToFile writes content to a file,
316322
// creating any missing directories in the path.
317-
func writeToFile(content []byte, fileName string, filePath string) {
323+
func writeToFile(content []byte, fileName string, filePath string) error {
318324
// Create any missing directories in the path
319325
err := os.MkdirAll(filePath, 0775)
320326
if err != nil {
321-
Logf("couldn't create directory: %v", err)
327+
return fmt.Errorf("couldn't create directory: %v", err)
322328
}
323329
// Write content to file
324330
file := filepath.Join(filePath, fileName)
325331
err = os.WriteFile(file, content, 0600)
326332
if err != nil {
327-
Logf("couldn't write to file: %v", err)
333+
return fmt.Errorf("couldn't write to file: %v", err)
328334
}
335+
return nil
329336
}
330337

331338
// crdIsInList checks if a CustomResourceDefinition is in the provided list of
@@ -370,7 +377,10 @@ func DumpGVR(ctx context.Context, dynamicClient *dynamic.DynamicClient, gvr sche
370377
if err != nil {
371378
return fmt.Errorf("could not marshal content: %v", err)
372379
}
373-
writeToFile(content, fileName, filePath)
380+
err = writeToFile(content, fileName, filePath)
381+
if err != nil {
382+
return fmt.Errorf("couldn't write to file: %v", err)
383+
}
374384
}
375385
return nil
376386
}

0 commit comments

Comments
 (0)