From b50a046370e84c6f603e414cdb831cba1488a2c1 Mon Sep 17 00:00:00 2001 From: Justin Nauman Date: Tue, 29 Aug 2017 21:14:21 -0500 Subject: [PATCH] Additional Validation on Include/Exclude - Adding in additional test to ensure *Namespaces attributes don't directly conflict logically with one another - Additional PR changes around naming/typos Signed-off-by: Justin Nauman --- pkg/apis/ark/v1/restore.go | 2 +- pkg/cmd/cli/restore/create.go | 4 ++-- pkg/controller/restore_controller.go | 7 ++++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pkg/apis/ark/v1/restore.go b/pkg/apis/ark/v1/restore.go index 148ec8381..2e4aa8fd1 100644 --- a/pkg/apis/ark/v1/restore.go +++ b/pkg/apis/ark/v1/restore.go @@ -34,7 +34,7 @@ type RestoreSpec struct { IncludedNamespaces []string `json:"includedNamespaces"` // ExcludedNamespaces contains a list of namespaces that are not - // included in the backup. + // included in the restore. ExcludedNamespaces []string `json:"excludedNamespaces"` // NamespaceMapping is a map of source namespace names diff --git a/pkg/cmd/cli/restore/create.go b/pkg/cmd/cli/restore/create.go index 266e61978..2a0df90d6 100644 --- a/pkg/cmd/cli/restore/create.go +++ b/pkg/cmd/cli/restore/create.go @@ -73,8 +73,8 @@ func NewCreateOptions() *CreateOptions { } func (o *CreateOptions) BindFlags(flags *pflag.FlagSet) { - flags.Var(&o.IncludeNamespaces, "include-namespaces", "namespaces to include in the backup (use '*' for all namespaces)") - flags.Var(&o.ExcludeNamespaces, "exclude-namespaces", "namespaces to exclude from the backup") + flags.Var(&o.IncludeNamespaces, "include-namespaces", "namespaces to include in the restore (use '*' for all namespaces)") + flags.Var(&o.ExcludeNamespaces, "exclude-namespaces", "namespaces to exclude from the restore") flags.Var(&o.NamespaceMappings, "namespace-mappings", "namespace mappings from name in the backup to desired restored name in the form src1:dst1,src2:dst2,...") flags.Var(&o.Labels, "labels", "labels to apply to the restore") flags.VarP(&o.Selector, "selector", "l", "only restore resources matching this label selector") diff --git a/pkg/controller/restore_controller.go b/pkg/controller/restore_controller.go index a380d944f..73f089db3 100644 --- a/pkg/controller/restore_controller.go +++ b/pkg/controller/restore_controller.go @@ -39,6 +39,7 @@ import ( informers "github.com/heptio/ark/pkg/generated/informers/externalversions/ark/v1" listers "github.com/heptio/ark/pkg/generated/listers/ark/v1" "github.com/heptio/ark/pkg/restore" + "github.com/heptio/ark/pkg/util/collections" ) type restoreController struct { @@ -286,7 +287,11 @@ func (controller *restoreController) getValidationErrors(itm *api.Restore) []str } if len(itm.Spec.Namespaces) > 0 && len(itm.Spec.IncludedNamespaces) > 0 { - validationErrors = append(validationErrors, "Namespace and ItemNamespaces can not both be defined on the backup spec.") + 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) { + validationErrors = append(validationErrors, fmt.Sprintf("Invalid included/excluded namespace lists: %v", err)) } if !controller.pvProviderExists && itm.Spec.RestorePVs != nil && *itm.Spec.RestorePVs {