From 55bf2de15dbdf384ebeb14b5ad7dba2f5c5aed83 Mon Sep 17 00:00:00 2001 From: Scott Seago Date: Fri, 19 Aug 2022 14:50:16 -0400 Subject: [PATCH] Check for empty ns list before checking nslist[0] In determining whether a backup includes all namespaces, item_collector checks for an empty string in the first element of the ns list. If processing includes+excludes results in an empty list, treat this as another case of a not-all-namespaces backup rather than crashing velero. Signed-off-by: Scott Seago --- changelogs/unreleased/5236-sseago | 1 + pkg/backup/item_collector.go | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 changelogs/unreleased/5236-sseago diff --git a/changelogs/unreleased/5236-sseago b/changelogs/unreleased/5236-sseago new file mode 100644 index 0000000000..4d295cce85 --- /dev/null +++ b/changelogs/unreleased/5236-sseago @@ -0,0 +1 @@ +Check for empty ns list before checking nslist[0] diff --git a/pkg/backup/item_collector.go b/pkg/backup/item_collector.go index 5cbc178361..474fbabee3 100644 --- a/pkg/backup/item_collector.go +++ b/pkg/backup/item_collector.go @@ -225,8 +225,11 @@ func (r *itemCollector) getResourceItems(log logrus.FieldLogger, gv schema.Group namespacesToList := getNamespacesToList(r.backupRequest.NamespaceIncludesExcludes) - // Check if we're backing up namespaces, and only certain ones - if gr == kuberesource.Namespaces && namespacesToList[0] != "" { + // Check if we're backing up namespaces for a less-than-full backup. + // We enter this block if resource is Namespaces and the namespae list is either empty or contains + // an explicit namespace list. (We skip this block if the list contains "" since that indicates + // a full-cluster backup + if gr == kuberesource.Namespaces && (len(namespacesToList) == 0 || namespacesToList[0] != "") { resourceClient, err := r.dynamicFactory.ClientForGroupVersionResource(gv, resource, "") if err != nil { log.WithError(err).Error("Error getting dynamic client")