check for namespaces/ dir before reading it

Signed-off-by: Steve Kriss <steve@heptio.com>
pull/38/head
Steve Kriss 2017-08-11 14:05:06 -07:00
parent 35b865dfcf
commit 49809b0a59
2 changed files with 16 additions and 0 deletions

View File

@ -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)

View File

@ -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"),