From 51307130a2e6dc6da2365f522ebbf2a6da831a29 Mon Sep 17 00:00:00 2001 From: "F. Gold" Date: Thu, 28 Oct 2021 15:37:00 -0700 Subject: [PATCH] Validation allows empty string namespace Signed-off-by: F. Gold --- pkg/util/collections/includes_excludes.go | 6 ++++++ pkg/util/collections/includes_excludes_test.go | 15 ++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) 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{"*"},