diff --git a/pkg/restore/restore.go b/pkg/restore/restore.go index 18984c01a..cb6df7309 100644 --- a/pkg/restore/restore.go +++ b/pkg/restore/restore.go @@ -210,6 +210,15 @@ func (kr *kubernetesRestorer) restoreFromDir( // namespace-scoped namespacesPath := path.Join(dir, api.NamespaceScopedDir) + exists, err = kr.fileSystem.DirExists(namespacesPath) + if err != nil { + addArkError(&errors, err) + return warnings, errors + } + if !exists { + return warnings, errors + } + nses, err := kr.fileSystem.ReadDir(namespacesPath) if err != nil { addArkError(&errors, err) diff --git a/pkg/restore/restore_test.go b/pkg/restore/restore_test.go index aeef65b5d..99860061f 100644 --- a/pkg/restore/restore_test.go +++ b/pkg/restore/restore_test.go @@ -91,6 +91,13 @@ func TestRestoreMethod(t *testing.T) { restore: &api.Restore{Spec: api.RestoreSpec{}}, expectedReadDirs: []string{"bak/cluster", "bak/namespaces"}, }, + { + name: "namespaces dir is not read & does not error if it does not exist", + fileSystem: newFakeFileSystem().WithDirectories("bak/cluster"), + baseDir: "bak", + restore: &api.Restore{Spec: api.RestoreSpec{}}, + expectedReadDirs: []string{"bak/cluster"}, + }, { name: "namespacesToRestore having * restores all namespaces", fileSystem: newFakeFileSystem().WithDirectories("bak/cluster", "bak/namespaces/a", "bak/namespaces/b", "bak/namespaces/c"),