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

feat: refactor Karmada resource labels #3899

Closed
wants to merge 1 commit into from

Conversation

jwcesign
Copy link
Member

@jwcesign jwcesign commented Aug 4, 2023

What type of PR is this?
/kind feature

What this PR does / why we need it:
Please referring to #4000

Which issue(s) this PR fixes:
Fixes #4000

Special notes for your reviewer:
In PR:#4007, we add the owner information into the annotation.
This PR just use the annotation and the uid label for the handling logic.

Does this PR introduce a user-facing change?:

Do not include the owner information label in the resource labels. This information is already present in the resource annotations.

@jwcesign jwcesign marked this pull request as draft August 4, 2023 08:23
@karmada-bot karmada-bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 4, 2023
@RainbowMango
Copy link
Member

Hi @jwcesign Just a reminder, this PR has conflicts, and it'd better to solve the conflicts first.

@wu0407
Copy link
Contributor

wu0407 commented Aug 15, 2023

has any progress?

@jwcesign
Copy link
Member Author

jwcesign commented Aug 16, 2023

Hi @wu0407, I will complete it by the end of this week. Once it's done, I'll notify you for your review.

@karmada-bot karmada-bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 16, 2023
@jwcesign jwcesign force-pushed the change-label branch 9 times, most recently from 01a32cb to 083e59d Compare August 22, 2023 09:33
@RainbowMango
Copy link
Member

@jwcesign Could you please summarize the whole solution and point out what should be included in this PR(or v1.7)?
It's hard for people who didn't attend the community meeting to understand and review.

@RainbowMango RainbowMango added this to the v1.8 milestone Aug 29, 2023
@jwcesign jwcesign force-pushed the change-label branch 5 times, most recently from aa9b1e2 to 56057ca Compare September 7, 2023 03:08
objectCopy := object.DeepCopy()
objectCopy.SetLabels(objLabels)
objectCopy.SetAnnotations(objectAnnotations)
util.MergeAnnotation(objectCopy, policyv1alpha1.PropagationPolicyNamespaceAnnotation, policy.Namespace)
Copy link
Member

Choose a reason for hiding this comment

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

could you extend util.MergeAnnotation and util.MergeLabel? they are not efficient, every annotation and label need to get object's and set. they should looks like this:

// MergeAnnotations adds annotations for the given object, keep the value unchanged if key exist.
func MergeAnnotations(obj *unstructured.Unstructured, annos map[string]string) {
	objectAnnotation := obj.GetAnnotations()
	if objectAnnotation == nil {
		objectAnnotation = make(map[string]string, len(annos))
	}

	for annotationKey, annotationValue := range annos {
		if _, exist := objectAnnotation[annotationKey]; !exist {
			objectAnnotation[annotationKey] = annotationValue
		}
	}
	obj.SetAnnotations(objectAnnotation)
}

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we can do it in another PR

Copy link
Member

@whitewindmills whitewindmills 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 your hard work 😊. this is a huge review effort, maybe we need more reviews.

Copy link
Member

@XiShanYongYe-Chang XiShanYongYe-Chang left a comment

Choose a reason for hiding this comment

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

Still on reviewing.

pkg/apis/work/v1alpha2/well_known_constants.go Outdated Show resolved Hide resolved
pkg/util/helper/binding.go Outdated Show resolved Hide resolved
workList, err := GetWorksByLabelsSet(c, ls)
if err != nil {
return nil, err
}

Copy link
Member

Choose a reason for hiding this comment

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

Feel free to remove this part of the logic in the method, as using uid should ensure global uniqueness now.
Ask @chaunceyjiang to help make sure again.

pkg/util/helper/work.go Outdated Show resolved Hide resolved
pkg/controllers/unifiedauth/unified_auth_controller.go Outdated Show resolved Hide resolved
pkg/controllers/federatedhpa/federatedhpa_controller.go Outdated Show resolved Hide resolved
pkg/controllers/namespace/namespace_sync_controller.go Outdated Show resolved Hide resolved
test/e2e/framework/clusterpropagationpolicy.go Outdated Show resolved Hide resolved
test/e2e/framework/propagationpolicy.go Outdated Show resolved Hide resolved
pkg/util/helper/binding.go Outdated Show resolved Hide resolved
@jwcesign
Copy link
Member Author

@chaunceyjiang
Copy link
Member

chaunceyjiang commented Sep 15, 2023

Before starting the review, I have a question to ask:
Is the generation of UUID stable? If only using the default algorithm of ETCD, then after backing up Karmada, this UUID cannot be guaranteed to be the same after recovery. (use velero)

If Karmada has been restored and the UUID has changed, can Karmada still work properly?

@jwcesign @RainbowMango @XiShanYongYe-Chang @whitewindmills

@jwcesign
Copy link
Member Author

jwcesign commented Sep 15, 2023

If Karmada has been restored and the UUID has changed, can Karmada still work properly?

I will check it, in my opinion, I think the uid label should be updated(We can get the information from annotation and update it correctly, once it has changed)

@RainbowMango
Copy link
Member

Is the generation of UUID stable? If only using the default algorithm of ETCD, then after backing up Karmada, this UUID cannot be guaranteed to be the same after recovery. (use velero)

Good question!
I think the UUID(.metadata.uid) is stored in ETCD, after restoring, all objects probably use the previous uuid. But if restoring the object by applying again, then the UUID would change to a new one.

@chaunceyjiang
Copy link
Member

But if restoring the object by applying again, then the UUID would change to a new one.

Yes, if we delete the work object through uuid, will the work object never be deleted when uuid changes? @jwcesign @RainbowMango

@jwcesign
Copy link
Member Author

jwcesign commented Oct 7, 2023

Hi, @chaunceyjiang
If using velero, I think users should only backup Workload template(like deployment)/CPP/PP/CR/CRD, so If the detector can see the uid is changed, and update it(easy to implement), then all the resource labels next(rb/crb/work/workload in member clusters) will be correct, because they will be recreated.

So, this means, velero only should back up the top-level resources, not back up the derived resources(like work, rb).

If you back up the derived resources, like work, the old work will never be deleted(The label selector can't find the work now).

What do you think?

@karmada-bot karmada-bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Oct 18, 2023
Signed-off-by: jwcesign <jwcesign@gmail.com>
@karmada-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please ask for approval from xishanyongye-chang after the PR has been reviewed.

The full list of commands accepted by this bot can be found 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

@karmada-bot karmada-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Nov 30, 2023
@jwcesign
Copy link
Member Author

/close

Track in the issue

@jwcesign jwcesign closed this Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

feature: moving Karmada resource key information from labels to annotations
8 participants