@@ -184,7 +184,7 @@ func FetchManifests(clusterProxy framework.ClusterProxy, outputPath string) erro
184184 }
185185 }
186186 }
187- fmt . Printf ("Successfully collected manifests for cluster %s." , clusterProxy .GetName ())
187+ Logf ("Successfully collected manifests for cluster %s." , clusterProxy .GetName ())
188188 return nil
189189}
190190
@@ -244,7 +244,7 @@ func FetchClusterLogs(clusterProxy framework.ClusterProxy, outputPath string) er
244244 // Get all pods in the namespace
245245 pods , err := clientset .CoreV1 ().Pods (namespace .Name ).List (ctx , metav1.ListOptions {})
246246 if err != nil {
247- fmt . Printf ("couldn't list pods in namespace %s: %v" , namespace .Name , err )
247+ Logf ("couldn't list pods in namespace %s: %v" , namespace .Name , err )
248248 continue
249249 }
250250 for _ , pod := range pods .Items {
@@ -259,13 +259,16 @@ func FetchClusterLogs(clusterProxy framework.ClusterProxy, outputPath string) er
259259 }
260260 podDescription , err := podDescriber .Describe (namespace .Name , pod .Name , describerSettings )
261261 if err != nil {
262- fmt . Printf ("couldn't describe pod %s in namespace %s: %v" , pod .Name , namespace .Name , err )
262+ Logf ("couldn't describe pod %s in namespace %s: %v" , pod .Name , namespace .Name , err )
263263 continue
264264 }
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 {
@@ -274,13 +277,13 @@ func FetchClusterLogs(clusterProxy framework.ClusterProxy, outputPath string) er
274277
275278 err := CollectContainerLogs (ctx , namespace .Name , pod .Name , container .Name , clientset , containerDir )
276279 if err != nil {
277- fmt . Printf ("Error %v." , err )
280+ Logf ("Error %v." , err )
278281 continue
279282 }
280283 }
281284 }
282285 }
283- fmt . Printf ("Successfully collected logs for cluster %s." , clusterProxy .GetName ())
286+ Logf ("Successfully collected logs for cluster %s." , clusterProxy .GetName ())
284287 return nil
285288}
286289
@@ -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- fmt .Printf ("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- fmt .Printf ("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