-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Restructure backup format for resource prioritization #132
Conversation
dgoodwin
commented
Oct 12, 2017
•
edited
Loading
edited
Can one of the admins verify this patch? |
7fcd531
to
575db48
Compare
@ncdc I think this is ready to be looked at now. |
@dgoodwin thanks, I'll start reviewing shortly. When we're ready to merge, you'll need to make sure your commit(s) have signoff ( |
ok to test |
pkg/backup/backup.go
Outdated
@@ -473,9 +473,9 @@ func (ib *realItemBackupper) backupItem(ctx *backupContext, item map[string]inte | |||
|
|||
var filePath string | |||
if namespace != "" { | |||
filePath = strings.Join([]string{api.NamespaceScopedDir, namespace, groupResource.String(), name + ".json"}, "/") | |||
filePath = strings.Join([]string{api.ResourcesDir, groupResource.String(), api.NamespaceScopedDir, namespace, name + ".json"}, "/") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filepath.Join
pkg/backup/backup.go
Outdated
} else { | ||
filePath = strings.Join([]string{api.ClusterScopedDir, groupResource.String(), name + ".json"}, "/") | ||
filePath = strings.Join([]string{api.ResourcesDir, groupResource.String(), api.ClusterScopedDir, name + ".json"}, "/") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filepath.Join
pkg/restore/restore.go
Outdated
|
||
nses, err := ctx.fileSystem.ReadDir(namespacesPath) | ||
resourceDirs, err := ctx.fileSystem.ReadDir(resourcesDir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think there's any performance advantage one way or another between reading the resources dir up front like this, and just calling DirExists
on each resource
from ctx.prioritizedResources
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't come up with a theory one way or the other, would have to test but in context of restore my guess would be not significant at this point. (backup might be another story as I assume people might be running that a lot more)
If worthwhile let me know and I'll test next week.
pkg/restore/restore.go
Outdated
if !namespaceFilter.ShouldInclude(ns.Name()) { | ||
ctx.infof("Skipping namespace %s", ns.Name()) | ||
continue | ||
resourcePath := path.Join(resourcesDir, rscDir.Name()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filepath.Join
pkg/restore/restore.go
Outdated
continue | ||
resourcePath := path.Join(resourcesDir, rscDir.Name()) | ||
|
||
clusterSubDir := path.Join(resourcePath, api.ClusterScopedDir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filepath.Join
pkg/restore/restore.go
Outdated
if clusterSubDirExists { | ||
w, e := ctx.restoreResource(resource.String(), "", clusterSubDir) | ||
merge(&warnings, &w) | ||
merge(&errors, &e) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
continue
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Must be no such thing as a resource that could be cluster or namespace scoped. Will add that in.
pkg/restore/restore.go
Outdated
if !nsDir.IsDir() { | ||
continue | ||
} | ||
nsPath := path.Join(nsSubDir, nsDir.Name()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filepath.Join
pkg/restore/restore.go
Outdated
merge(&errors, &e) | ||
} | ||
|
||
nsSubDir := path.Join(resourcePath, api.NamespaceScopedDir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filepath.Join
pkg/restore/restore.go
Outdated
nsName := nsDir.Name() | ||
|
||
// fetch mapped NS name | ||
// TODO: what is a mapped ns name? for renames? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is when you do ark restore create --namespace-mappings foo:bar,hello:goodbye,...
. Any resources in foo
will be restored to bar
instead, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I think we might need to make use of this at some point.
pkg/restore/restore.go
Outdated
} | ||
if _, err := kube.EnsureNamespaceExists(ns, ctx.namespaceClient); err != nil { | ||
addArkError(&errors, err) | ||
return warnings, errors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this continue the nsDirs
loop on line 318 to try additional namespaces?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoah, yeah that's a bad artifact from the refactor, good catch. Changing to continue.
Updated and added signoff. |
One potential point of consideration, should I try to detect and warn about old backup tar.gzs? Probably a case for backup.tar.gz versioning as well here. |
Let's do that in a follow-up, at least the bit about writing some metadata to the backup tarball (and let's make sure we add an issue for that). I'm less concerned right now about detecting the old backup format and bailing out early, although that's probably easy to do, once we add in the metadata. I am in the process of restructuring pkg/backup so it'll be easier if we do this after my exec hooks land. |
Works for me. |
pkg/restore/restore.go
Outdated
exists, err = ctx.fileSystem.DirExists(namespacesPath) | ||
// Make sure the top level "resources" dir exists: | ||
resourcesDir := filepath.Join(dir, api.ResourcesDir) | ||
_, err := ctx.fileSystem.DirExists(resourcesDir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the bool should be checked, since in the normal case, if the dir doesn't exist, this will return (false, nil).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch.
pkg/restore/restore.go
Outdated
addArkError(&errors, err) | ||
return warnings, errors | ||
} | ||
if nsSubDirExists { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: maybe flip this conditional with a continue
to reduce nesting for the main block of logic?
pkg/restore/restore.go
Outdated
continue | ||
} | ||
|
||
nsName := nsDir.Name() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
may as well move this up a few lines and eliminate a few more calls to nsDir.Name()
pkg/restore/restore.go
Outdated
func (ctx *context) restoreNamespace(nsName, nsPath string) (api.RestoreResult, api.RestoreResult) { | ||
// restoreResource restores the specified cluster or namespace scoped resource. If namespace is | ||
// empty we are restoring a cluster level resource, otherwise into the specified namespace. | ||
func (ctx *context) restoreResource(resource string, namespace string, resourcePath string) (api.RestoreResult, api.RestoreResult) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
restoreResource(resource, namespace, resourcePath string)
This doc also needs to be updated |
Previously the directory structure separated resources depending on whether or not they were cluster or namespace scoped. All cluster resources were restored first, then all namespace resources. Priority did not apply across both and you could not order any namespace resources before any cluster resources. This restructure sorts firstly on resource type. resources/serviceaccounts/namespaces/ns1.json resources/nodes/cluster/node1.json This will break old backups as the format is no longer consistent as announced on the Google group. Signed-off-by: Devan Goodwin <dgoodwin@redhat.com>
Comments addressed I think! |
Thanks again @dgoodwin!!! |