Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion internal/utils/fetch_and_save.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ func FetchAndSaveData(namespace string, k8sResources []string, dirPath, version
}

if k8sType == "pods" {
err := os.MkdirAll(filepath.Join(dirPath, "logs"), os.ModePerm)
if err != nil {
return fmt.Errorf("error creating directory: %v", err)
}
for _, resource := range k8sResources.JSON["items"].([]interface{}) {
resourceMap := resource.(map[string]interface{})
podName := resourceMap["metadata"].(map[string]interface{})["name"].(string)
Expand All @@ -69,7 +73,7 @@ func FetchAndSaveData(namespace string, k8sResources []string, dirPath, version
continue
}

logFileName := filepath.Join(dirPath, k8sType, fmt.Sprintf("%s_%s.log", podName, containerMap["name"].(string)))
logFileName := filepath.Join(dirPath, "logs", fmt.Sprintf("%s_%s.log", podName, containerMap["name"].(string)))
err = os.WriteFile(logFileName, []byte(log), os.ModePerm)
if err != nil {
return fmt.Errorf("error writing log file: %v", err)
Expand Down