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

Validate namespace in velero backup create command #4057

Conversation

codegold79
Copy link
Contributor

@codegold79 codegold79 commented Aug 21, 2021

Please add a summary of your change

Added validation of namespaces included and excluded when creating Velero backups. The validatation was added both in the client and the server (the backup controller).

Does your change fix a particular issue?

Fixes #2690. In this issue, it was reported that when a forward slash was used in an included namespace for a backup, the backup proceeded instead of gracefully failing with useful information to the user.

Please indicate you've done the following:

@reasonerjt reasonerjt added the kind/release-blocker Must fix issues for the coming release (milestone) label Aug 25, 2021
@reasonerjt reasonerjt added this to the v1.7.0 milestone Aug 25, 2021
@zubron zubron requested a review from reasonerjt August 31, 2021 19:14
Copy link
Contributor

@zubron zubron left a comment

Choose a reason for hiding this comment

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

Thanks, @codegold79 - this is looking really good so far! I just have a couple of suggestions to expand the test coverage and also use the collections.ValidateNamespaceIncludesExcludes function in the CLI to avoid code duplication 👍

pkg/cmd/cli/backup/create.go Outdated Show resolved Hide resolved
Signed-off-by: F. Gold <fgold@vmware.com>
Signed-off-by: F. Gold <fgold@vmware.com>
Signed-off-by: F. Gold <fgold@vmware.com>
Signed-off-by: F. Gold <fgold@vmware.com>
…to read

Signed-off-by: F. Gold <fgold@vmware.com>
Signed-off-by: F. Gold <fgold@vmware.com>
- use one set of namespace validation logic instead of writing two
- remove duplicate namespace validation functions and tests
- add namespace validation tests in includes_excludes_test.go

Signed-off-by: F. Gold <fgold@vmware.com>
@codegold79 codegold79 force-pushed the 2609-validate-namespace-in-velero-backup-create-command branch from e42249b to ec5f0a6 Compare September 1, 2021 00:00
zubron
zubron previously approved these changes Sep 1, 2021
Copy link
Contributor

@zubron zubron left a comment

Choose a reason for hiding this comment

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

Thanks!

pkg/util/collections/includes_excludes.go Outdated Show resolved Hide resolved
Signed-off-by: F. Gold <fgold@vmware.com>
Copy link
Contributor

@zubron zubron left a comment

Choose a reason for hiding this comment

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

Thanks for updating this again, @codegold79! I have one more request to help with the clarity of error messages in the output.

pkg/util/collections/includes_excludes.go Outdated Show resolved Hide resolved
Signed-off-by: F. Gold <fgold@vmware.com>
Copy link
Contributor

@zubron zubron left a comment

Choose a reason for hiding this comment

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

You made those changes quickly 😄 thanks!

@zubron zubron dismissed dsu-igeek’s stale review September 3, 2021 14:35

The requested changes were addressed in 694a64c.

@lautenbde
Copy link

@codegold79 This change breaks pure cluster-scoped resource backups using incl_clusterresources=True with incl_namespaces=[""] which used to be working until Velero 1.6. Is there an alternative for this notation - ideally one that works for previous versions, too? Maybe excl_namespaces="*" ?

danfengliu pushed a commit to danfengliu/velero that referenced this pull request Jan 25, 2022
* Add namespace validation in the client

Signed-off-by: F. Gold <fgold@vmware.com>

* Add namespace validation in the backup controller

Signed-off-by: F. Gold <fgold@vmware.com>

* Add changelog for PR 4057

Signed-off-by: F. Gold <fgold@vmware.com>

* Update Copyright notice

Signed-off-by: F. Gold <fgold@vmware.com>

* Update include_excludes_test.go to follow Go standards and be easier to read

Signed-off-by: F. Gold <fgold@vmware.com>

* Add unit tests for namespace validation functions

Signed-off-by: F. Gold <fgold@vmware.com>

* Make changes per review comments

- use one set of namespace validation logic instead of writing two
- remove duplicate namespace validation functions and tests
- add namespace validation tests in includes_excludes_test.go

Signed-off-by: F. Gold <fgold@vmware.com>

* Return all ns validation err msgs as error list

Signed-off-by: F. Gold <fgold@vmware.com>

* Make error message more clear

Signed-off-by: F. Gold <fgold@vmware.com>
gyaozhou pushed a commit to gyaozhou/velero-read that referenced this pull request May 14, 2022
* Add namespace validation in the client

Signed-off-by: F. Gold <fgold@vmware.com>

* Add namespace validation in the backup controller

Signed-off-by: F. Gold <fgold@vmware.com>

* Add changelog for PR 4057

Signed-off-by: F. Gold <fgold@vmware.com>

* Update Copyright notice

Signed-off-by: F. Gold <fgold@vmware.com>

* Update include_excludes_test.go to follow Go standards and be easier to read

Signed-off-by: F. Gold <fgold@vmware.com>

* Add unit tests for namespace validation functions

Signed-off-by: F. Gold <fgold@vmware.com>

* Make changes per review comments

- use one set of namespace validation logic instead of writing two
- remove duplicate namespace validation functions and tests
- add namespace validation tests in includes_excludes_test.go

Signed-off-by: F. Gold <fgold@vmware.com>

* Return all ns validation err msgs as error list

Signed-off-by: F. Gold <fgold@vmware.com>

* Make error message more clear

Signed-off-by: F. Gold <fgold@vmware.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has-changelog has-unit-tests kind/release-blocker Must fix issues for the coming release (milestone)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Providing '/' in namespace leads to a crash
5 participants