Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for empty ns list before checking nslist[0] #5236

Merged
merged 1 commit into from
Sep 5, 2022

Conversation

sseago
Copy link
Collaborator

@sseago sseago commented Aug 19, 2022

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 [email protected]

Thank you for contributing to Velero!

Please add a summary of your change

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.

Does your change fix a particular issue?

Fixes #5235

Please indicate you've done the following:

  • [x ] Accepted the DCO. Commits without the DCO will delay acceptance.
  • [x ] Created a changelog file or added /kind changelog-not-required as a comment on this pull request.
  • Updated the corresponding documentation in site/content/docs/main.

@@ -226,7 +226,7 @@ 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] != "" {
if gr == kuberesource.Namespaces && (len(namespacesToList) == 0 || namespacesToList[0] != "") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be more explicit if it's like gr == kuberesource.Namespaces && len(namespacesToList) > 0 && namespacesToList[0] != "" ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@reasonerjt No, that would introduce incorrect logic. This block should be executed when the resource is "Namespaces" and "we're not backing up the whole cluster". a slice value of [""] is what we're looking for to skip. This means "All namespaces", so we skip the block. If it's an empty slice, this means that the includes minus the excludes leaves us with zero namespaces, meaning this is a less-than-whole-cluster backup, so we run the block. If it's non-empty with values other than "", this is also a less-than-whole-cluster backup and we run the block -- that's why I have the embedded or clause. The alternative suggestion would have us skipping the block and going on where there are no namespaces, which could result in stuff being done that we don't want done here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please update the comment in line 228, to explain the case when the first item is an empty string, the phrase only certain ones makes people think the the block after if should not be executed if the namespaceToList is empty.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 <[email protected]>
@sseago sseago force-pushed the no-namespaces-fix branch from 337359b to 55bf2de Compare August 24, 2022 18:32
@qiuming-best qiuming-best merged commit a5a3df1 into vmware-tanzu:main Sep 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

If namespace includes/excludes evaluates to an empty list, velero server panics on backup
3 participants