diff --git a/pkg/util/collections/includes_excludes.go b/pkg/util/collections/includes_excludes.go index 1f2128c71..231689be0 100644 --- a/pkg/util/collections/includes_excludes.go +++ b/pkg/util/collections/includes_excludes.go @@ -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. diff --git a/pkg/util/collections/includes_excludes_test.go b/pkg/util/collections/includes_excludes_test.go index 0ba885bd2..672a309d2 100644 --- a/pkg/util/collections/includes_excludes_test.go +++ b/pkg/util/collections/includes_excludes_test.go @@ -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{"*"},