-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Conversation
…amespaces Signed-off-by: allenxu404 <[email protected]>
pkg/controller/backup_controller.go
Outdated
@@ -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" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
pkg/controller/backup_controller.go
Outdated
// 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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Signed-off-by: allenxu404 <[email protected]>
Codecov Report
@@ 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
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thank you for contributing to Velero!
Please add a summary of your change
Does your change fix a particular issue?
Fixes #2413
Please indicate you've done the following:
/kind changelog-not-required
as a comment on this pull request.site/content/docs/main
.