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

Allows explicit include/exclude of namespaces on restores #59

Merged
merged 4 commits into from
Sep 6, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 0 additions & 5 deletions pkg/apis/ark/v1/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ type RestoreSpec struct {
// from.
BackupName string `json:"backupName"`

// NOTE: This is deprecated. IncludedNamespaces and ExcludedNamespaces
// should be used instead
// Namespaces is a slice of namespaces in the Ark backup to restore.
Namespaces []string `json:"namespaces"`

// IncludedNamespaces is a slice of namespace names to include objects
// from. If empty, all namespaces are included.
IncludedNamespaces []string `json:"includedNamespaces"`
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/backup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,11 @@ func cloneBackup(in interface{}) (*api.Backup, error) {
func (controller *backupController) getValidationErrors(itm *api.Backup) []string {
var validationErrors []string

for err := range collections.ValidateIncludesExcludes(itm.Spec.IncludedResources, itm.Spec.ExcludedResources) {
for _, err := range collections.ValidateIncludesExcludes(itm.Spec.IncludedResources, itm.Spec.ExcludedResources) {
Copy link
Member

Choose a reason for hiding this comment

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

@jrnt30 thanks for catching!

validationErrors = append(validationErrors, fmt.Sprintf("Invalid included/excluded resource lists: %v", err))
}

for err := range collections.ValidateIncludesExcludes(itm.Spec.IncludedNamespaces, itm.Spec.ExcludedNamespaces) {
for _, err := range collections.ValidateIncludesExcludes(itm.Spec.IncludedNamespaces, itm.Spec.ExcludedNamespaces) {
validationErrors = append(validationErrors, fmt.Sprintf("Invalid included/excluded namespace lists: %v", err))
}

Expand Down
21 changes: 5 additions & 16 deletions pkg/controller/restore_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,22 +220,15 @@ func (controller *restoreController) processRestore(key string) error {
return err
}

if len(restore.Spec.IncludedNamespaces) == 0 {
restore.Spec.IncludedNamespaces = []string{"*"}
}

// validation
if restore.Status.ValidationErrors = controller.getValidationErrors(restore); len(restore.Status.ValidationErrors) > 0 {
restore.Status.Phase = api.RestorePhaseFailedValidation
} else {
restore.Status.Phase = api.RestorePhaseInProgress

if len(restore.Spec.Namespaces) != 0 {
glog.V(4).Info("the restore.Spec.Namespaces field has been deprecated. Please use the IncludedNamespaces and ExcludedNamespaces feature instead")

restore.Spec.IncludedNamespaces = restore.Spec.Namespaces
restore.Spec.Namespaces = nil
}

if len(restore.Spec.IncludedNamespaces) == 0 {
restore.Spec.IncludedNamespaces = []string{"*"}
}
}

// update status
Expand Down Expand Up @@ -286,11 +279,7 @@ func (controller *restoreController) getValidationErrors(itm *api.Restore) []str
validationErrors = append(validationErrors, "BackupName must be non-empty and correspond to the name of a backup in object storage.")
}

Copy link
Member

Choose a reason for hiding this comment

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

You should validate the the included/excluded namespaces are a valid set of includes/excludes. See backup controller

if len(itm.Spec.Namespaces) > 0 && len(itm.Spec.IncludedNamespaces) > 0 {
validationErrors = append(validationErrors, "Namespaces and IncludedNamespaces can not both be defined on the backup spec.")
}

for err := range collections.ValidateIncludesExcludes(itm.Spec.IncludedNamespaces, itm.Spec.ExcludedNamespaces) {
for _, err := range collections.ValidateIncludesExcludes(itm.Spec.IncludedNamespaces, itm.Spec.ExcludedNamespaces) {
validationErrors = append(validationErrors, fmt.Sprintf("Invalid included/excluded namespace lists: %v", err))
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/controller/restore_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,16 @@ func TestProcessRestore(t *testing.T) {
expectedErr: false,
},
{
name: "restore with both namespaces and includedNamespaces fails validation",
restore: NewTestRestore("foo", "bar", api.RestorePhaseNew).WithBackup("backup-1").WithNamespace("ns-1").WithIncludedNamespace("another-1").Restore,
name: "restore with both namespace in both includedNamespaces and excludedNamespaces fails validation",
restore: NewTestRestore("foo", "bar", api.RestorePhaseNew).WithBackup("backup-1").WithIncludedNamespace("another-1").WithExcludedNamespace("another-1").Restore,
backup: NewTestBackup().WithName("backup-1").Backup,
expectedErr: false,
expectedRestoreUpdates: []*api.Restore{
NewTestRestore("foo", "bar", api.RestorePhaseFailedValidation).
WithBackup("backup-1").
WithNamespace("ns-1").
WithIncludedNamespace("another-1").
WithValidationError("Namespace and ItemNamespaces can not both be defined on the backup spec.").Restore,
WithExcludedNamespace("another-1").
WithValidationError("Invalid included/excluded namespace lists: excludes list cannot contain an item in the includes list: another-1").Restore,
},
},
{
Expand Down
6 changes: 0 additions & 6 deletions pkg/util/test/test_restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@ func NewDefaultTestRestore() *TestRestore {
return NewTestRestore(api.DefaultNamespace, "", api.RestorePhase(""))
}


func (r *TestRestore) WithNamespace(name string) *TestRestore {
r.Spec.Namespaces = append(r.Spec.Namespaces, name)
return r
}

func (r *TestRestore) WithIncludedNamespace(name string) *TestRestore {
r.Spec.IncludedNamespaces = append(r.Spec.IncludedNamespaces, name)
return r
Expand Down