Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix restore namespace remapping bug #179

Merged
merged 1 commit into from
Nov 2, 2017
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion pkg/restore/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ func (ctx *context) restoreFromDir(dir string) (api.RestoreResult, api.RestoreRe
continue
}

w, e := ctx.restoreResource(resource.String(), nsName, nsPath)
w, e := ctx.restoreResource(resource.String(), mappedNsName, nsPath)
merge(&warnings, &w)
merge(&errs, &e)
}
Expand Down
47 changes: 47 additions & 0 deletions pkg/restore/restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,53 @@ func TestRestorePriority(t *testing.T) {
}
}

func TestNamespaceRemapping(t *testing.T) {
var (
baseDir = "bak"
restore = &api.Restore{Spec: api.RestoreSpec{IncludedNamespaces: []string{"*"}, NamespaceMapping: map[string]string{"ns-1": "ns-2"}}}
prioritizedResources = []schema.GroupResource{{Resource: "configmaps"}}
labelSelector = labels.NewSelector()
fileSystem = newFakeFileSystem().WithFile("bak/resources/configmaps/namespaces/ns-1/cm-1.json", newTestConfigMap().WithNamespace("ns-1").ToJSON())
expectedNS = "ns-2"
expectedObjs = toUnstructured(newTestConfigMap().WithNamespace("ns-2").WithArkLabel("").ConfigMap)
)

resourceClient := &FakeDynamicClient{}
for i := range expectedObjs {
resourceClient.On("Create", &expectedObjs[i]).Return(&expectedObjs[i], nil)
}

dynamicFactory := &FakeDynamicFactory{}
resource := metav1.APIResource{Name: "configmaps", Namespaced: true}
gv := schema.GroupVersion{Group: "", Version: "v1"}
dynamicFactory.On("ClientForGroupVersionResource", gv, resource, expectedNS).Return(resourceClient, nil)

log, _ := testlogger.NewNullLogger()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

arktest.NewLogger(), move it down to line 326 directly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

context.logger is a *logrus.Logger, not a *logrus.LogEntry -- you want me to change it to a FieldLogger as part of this PR?


ctx := &context{
dynamicFactory: dynamicFactory,
fileSystem: fileSystem,
selector: labelSelector,
namespaceClient: &fakeNamespaceClient{},
prioritizedResources: prioritizedResources,
restore: restore,
backup: &api.Backup{},
logger: log,
}

warnings, errors := ctx.restoreFromDir(baseDir)

assert.Empty(t, warnings.Ark)
assert.Empty(t, warnings.Cluster)
assert.Empty(t, warnings.Namespaces)
assert.Empty(t, errors.Ark)
assert.Empty(t, errors.Cluster)
assert.Empty(t, errors.Namespaces)

dynamicFactory.AssertExpectations(t)
resourceClient.AssertExpectations(t)
}

func TestRestoreResourceForNamespace(t *testing.T) {
var (
trueVal = true
Expand Down