-
Notifications
You must be signed in to change notification settings - Fork 40
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: create conbackups with same name between clusters error #190
Conversation
Signed-off-by: Liucw <liu.chuwei@99cloud.net>
Codecov Report
@@ Coverage Diff @@
## master #190 +/- ##
==========================================
- Coverage 13.00% 12.99% -0.02%
==========================================
Files 105 105
Lines 16021 16037 +16
==========================================
Hits 2084 2084
- Misses 13686 13702 +16
Partials 251 251
|
pkg/apis/core/v1/handler.go
Outdated
restplus.HandleInternalError(response, request, err) | ||
return | ||
} | ||
_ = response.WriteHeaderAndEntity(http.StatusOK, createdCB) | ||
} | ||
|
||
func (h *handler) checkCronBackupExist(ctx context.Context, name, cluster string) (bool, error) { | ||
cronBackups, err := h.clusterOperator.ListCronBackups(ctx, query.New()) |
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.
use cronBackupFuzzyFilter instead
Signed-off-by: Liucw <liu.chuwei@99cloud.net>
@@ -641,12 +641,15 @@ func (c *clusterOperator) cronBackupFuzzyFilter(obj runtime.Object, q *query.Que | |||
return nil | |||
} | |||
objs := make([]runtime.Object, 0, len(cronBackups.Items)) | |||
for index, backup := range cronBackups.Items { | |||
for index, cronBackup := range cronBackups.Items { |
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.
your code should like this
func backupCustomFilter(b v1.CronBackup, key, value string) bool {
switch key {
case "cluster":
// ...
}
return true
}
func (c *clusterOperator) cronBackupFuzzyFilter(obj runtime.Object, q *query.Query) []runtime.Object {
cronBackups, ok := obj.(*v1.CronBackupList)
if !ok {
return nil
}
objs := make([]runtime.Object, 0, len(cronBackups.Items))
for index, backup := range cronBackups.Items {
selected := true
for k, v := range q.FuzzySearch {
if !models.ObjectMetaFilter(backup.ObjectMeta, k, v) {
selected = false
}
if !backupCustomFilter(backup, k, v) {
selected = false
}
}
if selected {
objs = append(objs, &cronBackups.Items[index])
}
}
return objs
}
Signed-off-by: Liucw <liu.chuwei@99cloud.net>
/lgtm |
LGTM label has been added. Git tree hash: d508d0d2c570b883a65b83f22d5a1de284318c92
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Metrora, x893675 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/cherrypick release-1.1 |
@x893675: new pull request created: #205 In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Signed-off-by: Liucw liu.chuwei@99cloud.net
What type of PR is this?
/kind bug
What this PR does / why we need it:
Duplicate cron backup with same name for different clusters will report an error.
Which issue(s) this PR fixes:
Fixes #187
Special notes for reviewers:
Does this PR introduced a user-facing change?
Additional documentation, usage docs, etc.:
@x893675