-
Notifications
You must be signed in to change notification settings - Fork 893
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
Move binding's namespace/name from work's label to work's annotation #752
Move binding's namespace/name from work's label to work's annotation #752
Conversation
Propoase a util: // HasAnnotation tells if the 'annotation' contains the expected key-value pair.
func HasAnnotation(annotation map[string]string, expectKey string, expectValue string) bool {
if annotation == nil {
return false
}
value, exist := annotation[expectKey]
if !exist {
return false
}
return value == expectValue
} |
Got it. |
3f63536
to
714f897
Compare
/assign @Garrybest @mrlihanbo @GitHubxsy |
pkg/util/annotation.go
Outdated
// GetWorkListByCRBName get works by ClusterResourceBinding name. | ||
func GetWorkListByCRBName(c client.Client, name string) ([]workv1alpha1.Work, error) { | ||
workList := &workv1alpha1.WorkList{} | ||
err := c.List(context.TODO(), workList) |
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.
I'm afraid that it is potentially expensive that we list all RBs every time and range them to filter the matched ones when we have a lot of RBs. What about only moving names to annotations and leave namespace in labels? So we could list work by namespace label first. That will narrow work list.
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.
Sounds good.
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.
But separating namespaces and namespaces can be confusing. How do you think @RainbowMango
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.
Can we have both the label
and annotation
? E.g.
diff --git a/pkg/apis/work/v1alpha1/well_known_labels.go b/pkg/apis/work/v1alpha1/well_known_labels.go
index 9cc3d813..657ad8cc 100644
--- a/pkg/apis/work/v1alpha1/well_known_labels.go
+++ b/pkg/apis/work/v1alpha1/well_known_labels.go
@@ -1,6 +1,15 @@
package v1alpha1
const (
+ // ResourceBindingReferenceKey is the key of ResourceBinding object.
+ // It is usually a unique hash value of ResourceBinding object's name and intended to be added to the Work object.
+ // It will be used to retrieve all Works objects that derived from a specific ResourceBinding object.
+ ResourceBindingReferenceKey = "resourcebinding.karmada.io/key"
+ // ClusterResourceBindingReferenceKey is the key of ClusterResourceBinding object.
+ // It is usually a unique hash value of ClusterResourceBinding object's name and intended to be added to the Work object.
+ // It will be used to retrieve all Works objects that derived by a specific ClusterResourceBinding object.
+ ClusterResourceBindingReferenceKey = "clusterresourcebinding.karmada.io/key"
+
// ResourceBindingNamespaceLabel is added to objects to specify associated ResourceBinding's namespace.
ResourceBindingNamespaceLabel = "resourcebinding.karmada.io/namespace"
The label is used to retrieve Work
by RB/CRB
and the annotation
is used to retrieve RB/CRB
by Work
.
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.
That's greate. How do you think @Garrybest ?
If that's ok, i am going to modify with this command.
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.
So we have both annotations and labels of resourcebinding in work? And the value is a unique hash value? I don't understand why annotations still need to be kept if we keep the labels. Could you give a example?
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.
Good question.
karmada/pkg/controllers/binding/binding_controller.go
Lines 120 to 121 in 1947cf2
resourcebindingNamespace, namespaceExist := labels[workv1alpha1.ResourceBindingNamespaceLabel] | |
resourcebindingName, nameExist := labels[workv1alpha1.ResourceBindingNameLabel] |
The binding controller wants to enqueue Binding
once the relevant Work
is changed, in order to such as, grab status.
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.
OK, let's do it.
714f897
to
8a14b2e
Compare
5c3facf
to
cc9a6da
Compare
Oh I see. The annotation is used to record the namespace and name for finding the relevant RB of a work. And the hash label is used to select all relevant works of a RB quickly. |
/lgtm |
That's true. :) |
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.
Generally LGTM.
But since we missed the PR from v0.9.0, so the comments should be updated.
Delete this logic in the next release to prevent incompatibility when upgrading the current release (`v0.9.0`)
Signed-off-by: changzhen <[email protected]>
cc9a6da
to
cac82db
Compare
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
/approve
[APPROVALNOTIFIER] This PR is APPROVED Approval requirements bypassed by manually added approval. This pull-request has been approved by: RainbowMango 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 |
Signed-off-by: changzhen [email protected]
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
The key of a
label
must be no more than 63 characters. When a binding object is generated, the name format is as follows:${name}-${kind}
, this may cause the length to exceed the limit.The key of a
annotation
has no limits, so i move binding's namespace/name from work's label to work's annotation.Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?: