fix: Do not fail analysis if node list does not exist (#1678)

* fix: Do not error if node list does not exist

Signed-off-by: Evans Mungai <evans@replicated.com>

* fix test fail

---------

Signed-off-by: Evans Mungai <evans@replicated.com>
Co-authored-by: Dexter Yan <yanshaocong@gmail.com>
This commit is contained in:
Evans Mungai
2024-11-08 09:53:03 +13:00
committed by GitHub
co-authored by Dexter Yan
parent 77c9968ff6
commit d25aa7d0ea
3 changed files with 6 additions and 2 deletions
+4
View File
@@ -6,6 +6,7 @@ import (
"github.com/pkg/errors"
"github.com/replicatedhq/troubleshoot/pkg/constants"
"github.com/replicatedhq/troubleshoot/pkg/types"
)
type collectedContent struct {
@@ -33,6 +34,9 @@ func retrieveCollectedContents(
// Local data not available, move to remote collection
nodeListContents, err := getCollectedFileContents(constants.NODE_LIST_FILE)
if err != nil {
if _, ok := err.(*types.NotFoundError); ok {
return collectedContents, nil
}
return nil, errors.Wrap(err, "failed to get node list")
}
+1 -1
View File
@@ -78,7 +78,7 @@ func TestRetrieveCollectedContents(t *testing.T) {
remoteNodeBaseDir: "remoteBaseDir",
remoteFileName: "remoteFileName",
expectedResult: nil,
expectedError: "failed to get node list",
expectedError: "",
},
{
name: "fail to retrieve content for one of the nodes",
+1 -1
View File
@@ -103,7 +103,7 @@ func getPodDetailsFromFiles(files map[string][]byte, podNamespace string, podNam
// GetFilesContents will return the file contents for filenames matching the filenames parameter.
func GetFilesContents(bundleArchive string, filenames []string) (map[string][]byte, error) {
bundleDir, err := ioutil.TempDir("", "troubleshoot")
bundleDir, err := os.MkdirTemp("", "troubleshoot")
if err != nil {
return nil, errors.Wrap(err, "failed to create tmp dir")
}