mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-09-03 22:57:04 +00:00
Validate namespace in velero backup create command (#4057)
* Add namespace validation in the client Signed-off-by: F. Gold <fgold@vmware.com> * Add namespace validation in the backup controller Signed-off-by: F. Gold <fgold@vmware.com> * Add changelog for PR 4057 Signed-off-by: F. Gold <fgold@vmware.com> * Update Copyright notice Signed-off-by: F. Gold <fgold@vmware.com> * Update include_excludes_test.go to follow Go standards and be easier to read Signed-off-by: F. Gold <fgold@vmware.com> * Add unit tests for namespace validation functions Signed-off-by: F. Gold <fgold@vmware.com> * Make changes per review comments - use one set of namespace validation logic instead of writing two - remove duplicate namespace validation functions and tests - add namespace validation tests in includes_excludes_test.go Signed-off-by: F. Gold <fgold@vmware.com> * Return all ns validation err msgs as error list Signed-off-by: F. Gold <fgold@vmware.com> * Make error message more clear Signed-off-by: F. Gold <fgold@vmware.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2020 the Velero contributors.
|
||||
Copyright The Velero Contributors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -27,6 +27,7 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/pflag"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
kubeerrs "k8s.io/apimachinery/pkg/util/errors"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
|
||||
velerov1api "github.com/vmware-tanzu/velero/pkg/apis/velero/v1"
|
||||
@@ -37,6 +38,7 @@ import (
|
||||
"github.com/vmware-tanzu/velero/pkg/cmd/util/output"
|
||||
veleroclient "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned"
|
||||
v1 "github.com/vmware-tanzu/velero/pkg/generated/informers/externalversions/velero/v1"
|
||||
"github.com/vmware-tanzu/velero/pkg/util/collections"
|
||||
)
|
||||
|
||||
const DefaultBackupTTL time.Duration = 30 * 24 * time.Hour
|
||||
@@ -162,6 +164,11 @@ func (o *CreateOptions) Validate(c *cobra.Command, args []string, f client.Facto
|
||||
return fmt.Errorf("A backup name is required, unless you are creating based on a schedule.")
|
||||
}
|
||||
|
||||
errs := collections.ValidateNamespaceIncludesExcludes(o.IncludeNamespaces, o.ExcludeNamespaces)
|
||||
if len(errs) > 0 {
|
||||
return kubeerrs.NewAggregate(errs)
|
||||
}
|
||||
|
||||
if o.StorageLocation != "" {
|
||||
location := &velerov1api.BackupStorageLocation{}
|
||||
if err := client.Get(context.Background(), kbclient.ObjectKey{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2020 the Velero contributors.
|
||||
Copyright The Velero Contributors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
Reference in New Issue
Block a user