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

Restructure backup format for resource prioritization #132

Merged
merged 1 commit into from
Oct 17, 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
50 changes: 31 additions & 19 deletions docs/output-file-format.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,38 @@ Note that this file includes detailed info about your volume snapshots in the `s
When unzipped, a typical backup directory (e.g. `backup1234.tar.gz`) looks like the following:

```
cluster/
resources/
persistentvolumes/
pv01.json
...
namespaces/
namespace1/
configmaps/
myconfigmap.json
cluster/
pv01.json
...
pods
mypod.json
...
jobs
awesome-job.json
...
deployments
cool-deployment.json
...
...
namespace2/
...
configmaps/
namespaces/
namespace1/
myconfigmap.json
...
namespace2/
...
pods/
namespaces/
namespace1/
mypod.json
...
namespace2/
...
jobs/
namespaces/
namespace1/
awesome-job.json
...
namespace2/
...
deployments/
namespaces/
namespace1/
cool-deployment.json
...
namespace2/
...
...
```
4 changes: 4 additions & 0 deletions pkg/apis/ark/v1/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ const (
// the Ark server and API objects.
DefaultNamespace = "heptio-ark"

// ResourcesDir is a top-level directory expected in backups which contains sub-directories
// for each resource type in the backup.
ResourcesDir = "resources"

// RestoreLabelKey is the label key that's applied to all resources that
// are created during a restore. This is applied for ease of identification
// of restored resources. The value will be the restore's name.
Expand Down
5 changes: 3 additions & 2 deletions pkg/backup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"encoding/json"
"fmt"
"io"
"path/filepath"
"strings"
"time"

Expand Down Expand Up @@ -473,9 +474,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 = filepath.Join(api.ResourcesDir, groupResource.String(), api.NamespaceScopedDir, namespace, name+".json")
} else {
filePath = strings.Join([]string{api.ClusterScopedDir, groupResource.String(), name + ".json"}, "/")
filePath = filepath.Join(api.ResourcesDir, groupResource.String(), api.ClusterScopedDir, name+".json")
}

itemBytes, err := json.Marshal(item)
Expand Down
24 changes: 12 additions & 12 deletions pkg/backup/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,14 +439,14 @@ func TestBackupMethod(t *testing.T) {
require.NoError(t, err)

expectedFiles := sets.NewString(
"namespaces/a/configmaps/configMap1.json",
"namespaces/b/configmaps/configMap2.json",
"namespaces/a/roles.rbac.authorization.k8s.io/role1.json",
"resources/configmaps/namespaces/a/configMap1.json",
"resources/configmaps/namespaces/b/configMap2.json",
"resources/roles.rbac.authorization.k8s.io/namespaces/a/role1.json",
// CSRs are not expected because they're unrelated cluster-scoped resources
)

expectedData := map[string]string{
"namespaces/a/configmaps/configMap1.json": `
"resources/configmaps/namespaces/a/configMap1.json": `
{
"apiVersion": "v1",
"kind": "ConfigMap",
Expand All @@ -458,7 +458,7 @@ func TestBackupMethod(t *testing.T) {
"a": "b"
}
}`,
"namespaces/b/configmaps/configMap2.json": `
"resources/configmaps/namespaces/b/configMap2.json": `
{
"apiVersion": "v1",
"kind": "ConfigMap",
Expand All @@ -471,7 +471,7 @@ func TestBackupMethod(t *testing.T) {
}
}
`,
"namespaces/a/roles.rbac.authorization.k8s.io/role1.json": `
"resources/roles.rbac.authorization.k8s.io/namespaces/a/role1.json": `
{
"apiVersion": "rbac.authorization.k8s.io/v1beta1",
"kind": "Role",
Expand Down Expand Up @@ -1114,29 +1114,29 @@ func TestBackupItem(t *testing.T) {
namespaceIncludesExcludes: collections.NewIncludesExcludes().Includes("foo"),
expectError: false,
expectExcluded: false,
expectedTarHeaderName: "namespaces/foo/resource.group/bar.json",
expectedTarHeaderName: "resources/resource.group/namespaces/foo/bar.json",
},
{
name: "* namespace include",
item: `{"metadata":{"namespace":"foo","name":"bar"}}`,
namespaceIncludesExcludes: collections.NewIncludesExcludes().Includes("*"),
expectError: false,
expectExcluded: false,
expectedTarHeaderName: "namespaces/foo/resource.group/bar.json",
expectedTarHeaderName: "resources/resource.group/namespaces/foo/bar.json",
},
{
name: "cluster-scoped",
item: `{"metadata":{"name":"bar"}}`,
expectError: false,
expectExcluded: false,
expectedTarHeaderName: "cluster/resource.group/bar.json",
expectedTarHeaderName: "resources/resource.group/cluster/bar.json",
},
{
name: "make sure status is deleted",
item: `{"metadata":{"name":"bar"},"spec":{"color":"green"},"status":{"foo":"bar"}}`,
expectError: false,
expectExcluded: false,
expectedTarHeaderName: "cluster/resource.group/bar.json",
expectedTarHeaderName: "resources/resource.group/cluster/bar.json",
},
{
name: "tar header write error",
Expand All @@ -1156,7 +1156,7 @@ func TestBackupItem(t *testing.T) {
item: `{"metadata":{"name":"bar"}}`,
expectError: false,
expectExcluded: false,
expectedTarHeaderName: "cluster/resource.group/bar.json",
expectedTarHeaderName: "resources/resource.group/cluster/bar.json",
customAction: true,
expectedActionID: "bar",
},
Expand All @@ -1166,7 +1166,7 @@ func TestBackupItem(t *testing.T) {
item: `{"metadata":{"namespace": "myns", "name":"bar"}}`,
expectError: false,
expectExcluded: false,
expectedTarHeaderName: "namespaces/myns/resource.group/bar.json",
expectedTarHeaderName: "resources/resource.group/namespaces/myns/bar.json",
customAction: true,
expectedActionID: "myns/bar",
},
Expand Down
Loading