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

fix issue#2413: treat namespaces with exclude label as excludedNamespaces #5178

Merged
merged 2 commits into from
Aug 8, 2022

Conversation

allenxu404
Copy link
Contributor

Thank you for contributing to Velero!

Please add a summary of your change

  • add namespaces with label velero.io/exclude-from-backup=true into request.Spec.ExcludedNamespaces, in this way, adding the label velero.io/exclude-from-backup=true to a namespace would be equivalent to setting spec.ExcludedNamespaces

Does your change fix a particular issue?

Fixes #2413

Please indicate you've done the following:

  • Accepted the DCO. Commits without the DCO will delay acceptance.
  • 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.

@allenxu404 allenxu404 marked this pull request as draft August 4, 2022 10:21
@allenxu404 allenxu404 changed the title fix issue#2413: treat namespaces with exlude label as excludedNamespaces fix issue#2413: treat namespaces with exclude label as excludedNamespaces Aug 4, 2022
@allenxu404 allenxu404 marked this pull request as ready for review August 4, 2022 12:33
blackpiglet
blackpiglet previously approved these changes Aug 5, 2022
@@ -436,6 +436,15 @@ func (c *backupController) prepareBackupRequest(backup *velerov1api.Backup) *pkg
request.Annotations[velerov1api.SourceClusterK8sMajorVersionAnnotation] = c.discoveryHelper.ServerVersion().Major
request.Annotations[velerov1api.SourceClusterK8sMinorVersionAnnotation] = c.discoveryHelper.ServerVersion().Minor

// Add namespaces with label velero.io/exclude-from-backup=true into request.Spec.ExcludedNamespaces
// Essentially, adding the label velero.io/exclude-from-backup=true to a namespace would be equivalent to setting spec.ExcludedNamespaces
namespaces, excludeLabel := corev1api.NamespaceList{}, "velero.io/exclude-from-backup"
Copy link
Contributor

Choose a reason for hiding this comment

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

This is trivial but it seems we don't need excludeLabel as a variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would it be better if I move excludeLabel to pkg/controller/constants.go as a const or simply define it as const on the top of the code?

// Add namespaces with label velero.io/exclude-from-backup=true into request.Spec.ExcludedNamespaces
// Essentially, adding the label velero.io/exclude-from-backup=true to a namespace would be equivalent to setting spec.ExcludedNamespaces
namespaces, excludeLabel := corev1api.NamespaceList{}, "velero.io/exclude-from-backup"
if err := c.kbClient.List(context.Background(), &namespaces, kbclient.MatchingLabels{excludeLabel: "true"}); err == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not a validation error strictly speaking but I don't think it's right to eat the error.
Would there be a problem if we set it into request.Status.ValidationErrors and make it fail early and explicitly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems it's better to append the potential err into request.Status.ValidationErrors with explicit err message.

@codecov-commenter
Copy link

Codecov Report

Merging #5178 (e5d828a) into main (52fd18e) will increase coverage by 0.40%.
The diff coverage is 40.00%.

@@            Coverage Diff             @@
##             main    #5178      +/-   ##
==========================================
+ Coverage   41.20%   41.60%   +0.40%     
==========================================
  Files         212      215       +3     
  Lines       18666    18628      -38     
==========================================
+ Hits         7692     7751      +59     
+ Misses      10399    10299     -100     
- Partials      575      578       +3     
Impacted Files Coverage Δ
pkg/controller/backup_controller.go 48.24% <40.00%> (-0.28%) ⬇️
pkg/restic/common.go 30.00% <0.00%> (-35.86%) ⬇️
pkg/builder/container_builder.go 33.78% <0.00%> (-4.10%) ⬇️
pkg/util/kube/utils.go 73.79% <0.00%> (-1.59%) ⬇️
internal/hook/item_hook_handler.go 87.92% <0.00%> (-1.48%) ⬇️
pkg/controller/restore_controller.go 65.07% <0.00%> (-1.44%) ⬇️
pkg/cmd/server/server.go 6.50% <0.00%> (ø)
pkg/plugin/framework/server.go 0.00% <0.00%> (ø)
pkg/repository/config/config.go 95.91% <0.00%> (ø)
... and 18 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Contributor

@reasonerjt reasonerjt left a comment

Choose a reason for hiding this comment

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

LGTM

@blackpiglet blackpiglet merged commit 201c43d into vmware-tanzu:main Aug 8, 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.

Namespace with label velero.io/exclude-from-backup=true should exclude all resources within from backing up
4 participants