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: create conbackups with same name between clusters error #190

Merged
merged 3 commits into from
Sep 8, 2022
Merged

Conversation

Metrora
Copy link
Contributor

@Metrora Metrora commented Sep 5, 2022

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?

None

Additional documentation, usage docs, etc.:


@x893675

Signed-off-by: Liucw <liu.chuwei@99cloud.net>
@kubeclipper-bot kubeclipper-bot added release-note-none kind/bug Categorizes issue or PR as related to a bug. dco-signoff: yes size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 5, 2022
@codecov-commenter
Copy link

Codecov Report

Merging #190 (6a70601) into master (a06452b) will decrease coverage by 0.01%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            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              
Impacted Files Coverage Δ
pkg/apis/core/v1/handler.go 0.33% <0.00%> (-0.01%) ⬇️

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())
Copy link
Collaborator

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 {
Copy link
Collaborator

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>
@x893675
Copy link
Collaborator

x893675 commented Sep 8, 2022

/lgtm
/approve

@kubeclipper-bot kubeclipper-bot added the lgtm Indicates that a PR is ready to be merged. label Sep 8, 2022
@kubeclipper-bot
Copy link
Collaborator

LGTM label has been added.

Git tree hash: d508d0d2c570b883a65b83f22d5a1de284318c92

@kubeclipper-bot
Copy link
Collaborator

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@kubeclipper-bot kubeclipper-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 8, 2022
@kubeclipper-bot kubeclipper-bot merged commit 27da561 into kubeclipper:master Sep 8, 2022
@x893675
Copy link
Collaborator

x893675 commented Sep 8, 2022

/cherrypick release-1.1

@kubeclipper-bot
Copy link
Collaborator

@x893675: new pull request created: #205

In response to this:

/cherrypick release-1.1

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.

@Metrora Metrora deleted the dev branch September 8, 2022 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. release-note-none size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

renamed cronbackup in different cluster report error
4 participants