Validation allows empty string namespace

Signed-off-by: F. Gold <fgold@vmware.com>
pull/4250/head
F. Gold 2021-10-28 15:37:00 -07:00
parent 54fa63939a
commit 51307130a2
No known key found for this signature in database
GPG Key ID: DB33E71F09A5BF25
2 changed files with 16 additions and 5 deletions

View File

@ -180,6 +180,12 @@ func ValidateNamespaceIncludesExcludes(includesList, excludesList []string) []er
func validateNamespaceName(ns string) []error {
var errs []error
// Velero interprets empty string as "no namespace", so allow it even though
// it is not a valid Kubernetes name.
if ns == "" {
return nil
}
// Kubernetes does not allow asterisks in namespaces but Velero uses them as
// wildcards. Replace asterisks with an arbitrary letter to pass Kubernetes
// validation.

View File

@ -207,11 +207,6 @@ func TestValidateNamespaceIncludesExcludes(t *testing.T) {
includes: []string{},
wantErr: false,
},
{
name: "empty string is invalid",
includes: []string{""},
wantErr: true,
},
{
name: "asterisk by itself is valid",
includes: []string{"*"},
@ -240,6 +235,16 @@ func TestValidateNamespaceIncludesExcludes(t *testing.T) {
includes: []string{},
wantErr: false,
},
{
name: "empty string includes is valid (includes nothing)",
includes: []string{""},
wantErr: false,
},
{
name: "empty string excludes is valid (excludes nothing)",
excludes: []string{""},
wantErr: false,
},
{
name: "include everything using asterisk is valid",
includes: []string{"*"},