From 7257a75f82b10106432d5c700809a28b0230ad79 Mon Sep 17 00:00:00 2001 From: Sanket Patel Date: Sat, 10 Mar 2018 19:28:35 -0600 Subject: [PATCH] Add events to nonRestorableResources and cohabitatingResources Fixes #367 Fixes #368 Signed-off-by: Sanket Patel --- docs/debugging-restores.md | 2 +- pkg/backup/backup.go | 1 + pkg/backup/backup_test.go | 1 + pkg/controller/restore_controller.go | 4 ++-- pkg/controller/restore_controller_test.go | 24 ++++++++++++++++++++++- 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/docs/debugging-restores.md b/docs/debugging-restores.md index 3b8fc1f93..bac4de501 100644 --- a/docs/debugging-restores.md +++ b/docs/debugging-restores.md @@ -34,7 +34,7 @@ Namespaces: Resources: Included: serviceaccounts - Excluded: nodes + Excluded: nodes, events, events.events.k8s.io Cluster-scoped: auto Namespace mappings: diff --git a/pkg/backup/backup.go b/pkg/backup/backup.go index 35dd9053b..0a926985d 100644 --- a/pkg/backup/backup.go +++ b/pkg/backup/backup.go @@ -233,6 +233,7 @@ func (kb *kubernetesBackupper) Backup(backup *api.Backup, backupFile, logFile io cohabitatingResources := map[string]*cohabitatingResource{ "deployments": newCohabitatingResource("deployments", "extensions", "apps"), "networkpolicies": newCohabitatingResource("networkpolicies", "extensions", "networking.k8s.io"), + "events": newCohabitatingResource("events", "", "events.k8s.io"), } resolvedActions, err := resolveActions(actions, kb.discoveryHelper) diff --git a/pkg/backup/backup_test.go b/pkg/backup/backup_test.go index e5b1c16e5..9474576cf 100644 --- a/pkg/backup/backup_test.go +++ b/pkg/backup/backup_test.go @@ -527,6 +527,7 @@ func TestBackup(t *testing.T) { cohabitatingResources := map[string]*cohabitatingResource{ "deployments": newCohabitatingResource("deployments", "extensions", "apps"), "networkpolicies": newCohabitatingResource("networkpolicies", "extensions", "networking.k8s.io"), + "events": newCohabitatingResource("events", "", "events.k8s.io"), } groupBackupperFactory.On("newGroupBackupper", diff --git a/pkg/controller/restore_controller.go b/pkg/controller/restore_controller.go index 02a971715..f7bd3f54b 100644 --- a/pkg/controller/restore_controller.go +++ b/pkg/controller/restore_controller.go @@ -51,7 +51,7 @@ import ( // nonRestorableResources is a blacklist for the restoration process. Any resources // included here are explicitly excluded from the restoration process. -var nonRestorableResources = []string{"nodes"} +var nonRestorableResources = []string{"nodes", "events", "events.events.k8s.io"} type restoreController struct { namespace string @@ -304,7 +304,7 @@ func (controller *restoreController) getValidationErrors(itm *api.Restore) []str includedResources := sets.NewString(itm.Spec.IncludedResources...) for _, nonRestorableResource := range nonRestorableResources { if includedResources.Has(nonRestorableResource) { - validationErrors = append(validationErrors, fmt.Sprintf("%v are a non-restorable resource", nonRestorableResource)) + validationErrors = append(validationErrors, fmt.Sprintf("%v are non-restorable resources", nonRestorableResource)) } } diff --git a/pkg/controller/restore_controller_test.go b/pkg/controller/restore_controller_test.go index c75ab28f0..97c253c56 100644 --- a/pkg/controller/restore_controller_test.go +++ b/pkg/controller/restore_controller_test.go @@ -229,10 +229,32 @@ func TestProcessRestore(t *testing.T) { expectedErr: false, expectedPhase: string(api.RestorePhaseFailedValidation), expectedValidationErrors: []string{ - "nodes are a non-restorable resource", + "nodes are non-restorable resources", "Invalid included/excluded resource lists: excludes list cannot contain an item in the includes list: nodes", }, }, + { + name: "restoration of events is not supported", + restore: NewRestore("foo", "bar", "backup-1", "ns-1", "events", api.RestorePhaseNew).Restore, + backup: arktest.NewTestBackup().WithName("backup-1").Backup, + expectedErr: false, + expectedPhase: string(api.RestorePhaseFailedValidation), + expectedValidationErrors: []string{ + "events are non-restorable resources", + "Invalid included/excluded resource lists: excludes list cannot contain an item in the includes list: events", + }, + }, + { + name: "restoration of events.events.k8s.io is not supported", + restore: NewRestore("foo", "bar", "backup-1", "ns-1", "events.events.k8s.io", api.RestorePhaseNew).Restore, + backup: arktest.NewTestBackup().WithName("backup-1").Backup, + expectedErr: false, + expectedPhase: string(api.RestorePhaseFailedValidation), + expectedValidationErrors: []string{ + "events.events.k8s.io are non-restorable resources", + "Invalid included/excluded resource lists: excludes list cannot contain an item in the includes list: events.events.k8s.io", + }, + }, } for _, test := range tests {