From d25aa7d0eace367188e2e54b59516f6837ebfd76 Mon Sep 17 00:00:00 2001 From: Evans Mungai Date: Thu, 7 Nov 2024 14:53:03 -0600 Subject: [PATCH] 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 * fix test fail --------- Signed-off-by: Evans Mungai Co-authored-by: Dexter Yan --- pkg/analyze/collected_contents.go | 4 ++++ pkg/analyze/collected_contents_test.go | 2 +- pkg/supportbundle/parse.go | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/analyze/collected_contents.go b/pkg/analyze/collected_contents.go index 753a6a65c..8d5e8a228 100644 --- a/pkg/analyze/collected_contents.go +++ b/pkg/analyze/collected_contents.go @@ -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") } diff --git a/pkg/analyze/collected_contents_test.go b/pkg/analyze/collected_contents_test.go index c7200b4db..92d09d701 100644 --- a/pkg/analyze/collected_contents_test.go +++ b/pkg/analyze/collected_contents_test.go @@ -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", diff --git a/pkg/supportbundle/parse.go b/pkg/supportbundle/parse.go index e88433510..c755b55c4 100644 --- a/pkg/supportbundle/parse.go +++ b/pkg/supportbundle/parse.go @@ -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") }