-
Notifications
You must be signed in to change notification settings - Fork 905
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: fix GenerateBindingReferenceKey bug #1003
Conversation
cc @XiShanYongYe-Chang We should check if this bugfix would introduce in-compatible effects. That is more important than the bug. |
Ok, I will check it. |
I'm sorry, It's my fault. To prevent version incompatibility when users upgrade Karmada from v0.10.0 to a later version (for example, v.0.11.0), the current fix maybe not be enough. We need to introduce a new group of labels:
to replace the current group of labels:
The current group of labels can be removed in the next version. The two groups of labels both need to be processed, this may be complex. For example, a user creates the |
@JarHMJ , Would you like to fix it in this way? |
@XiShanYongYe-Chang Ok,I see. You means that the label I would like to do this feature. I think this pr should be merged as hotfix, because this leads to some error when deployment has same name in diffrenet namespce. |
I don't mean that the label isn't precise enough. I mean we need another group of labels to indicate correct key.
It's really a bug. I want the old one to stay the same, use a new method to generate the correct key, and then use the new label to replace the old one. For example: diff --git a/pkg/controllers/binding/common.go b/pkg/controllers/binding/common.go
index a7131bcd..52251ae5 100644
--- a/pkg/controllers/binding/common.go
+++ b/pkg/controllers/binding/common.go
@@ -193,8 +193,8 @@ func mergeLabel(workload *unstructured.Unstructured, workNamespace string, bindi
util.MergeLabel(workload, workv1alpha2.WorkNamespaceLabel, workNamespace)
util.MergeLabel(workload, workv1alpha2.WorkNameLabel, names.GenerateWorkName(workload.GetKind(), workload.GetName(), workload.GetNamespace()))
if scope == apiextensionsv1.NamespaceScoped {
- util.MergeLabel(workload, workv1alpha2.ResourceBindingReferenceKey, names.GenerateBindingReferenceKey(binding.GetNamespace(), binding.GetName()))
- workLabel[workv1alpha2.ResourceBindingReferenceKey] = names.GenerateBindingReferenceKey(binding.GetNamespace(), binding.GetName())
+ util.MergeLabel(workload, workv1alpha2.ResourceBindingReferenceHashKey, names.GenerateBindingReferenceHashKey(binding.GetNamespace(), binding.GetName()))
+ workLabel[workv1alpha2.ResourceBindingReferenceHashKey] = names.GenerateBindingReferenceHashKey(binding.GetNamespace(), binding.GetName())
} else {
util.MergeLabel(workload, workv1alpha2.ClusterResourceBindingReferenceKey, names.GenerateBindingReferenceKey("", binding.GetName()))
workLabel[workv1alpha2.ClusterResourceBindingReferenceKey] = names.GenerateBindingReferenceKey("", binding.GetName())
diff --git a/pkg/util/names/names.go b/pkg/util/names/names.go
index 01d5fe13..2511e69b 100644
--- a/pkg/util/names/names.go
+++ b/pkg/util/names/names.go
@@ -71,6 +71,19 @@ func GenerateBindingReferenceKey(namespace, name string) string {
return rand.SafeEncodeString(fmt.Sprint(hash.Sum32()))
}
+// GenerateBindingReferenceHashKey will generate the hash key of binding object with the hash of its namespace and name.
+func GenerateBindingReferenceHashKey(namespace, name string) string {
+ var bindingName string
+ if len(namespace) != 0 {
+ bindingName = namespace + "-" + name
+ } else {
+ bindingName = name
+ }
+ hash := fnv.New32a()
+ hashutil.DeepHashObject(hash, bindingName)
+ return rand.SafeEncodeString(fmt.Sprint(hash.Sum32()))
+} In the next version, we can delete the old logic, so the upgrade can be not affected. |
@XiShanYongYe-Chang 👌I will try to fix in your way |
@JarHMJ Thanks very much. |
55abde1
to
17b791d
Compare
@XiShanYongYe-Chang done. |
@XiShanYongYe-Chang Should I clean up the old code?
But #1006 has done it。 |
Thanks, I will review it ASAP.
This pr can don't care about it. |
I'm thinking about cutting a new bugfix release(v0.10.1) to solve this issue. |
I think we could provide a way for users to fix current rb ReferenceKey, so it can avoid deal the backward compatibility in the controller. steps as follow:
|
Hi @pigletfly How do you think? |
I'd like to take the patch from this PR and take the unit test from #1013. |
@JarHMJ Can you help revert the patch to the first version? something like: diff --git a/pkg/util/names/names.go b/pkg/util/names/names.go
index 01d5fe13..98a0fabc 100644
--- a/pkg/util/names/names.go
+++ b/pkg/util/names/names.go
@@ -61,7 +61,7 @@ func GenerateBindingName(kind, name string) string {
// GenerateBindingReferenceKey will generate the key of binding object with the hash of its namespace and name.
func GenerateBindingReferenceKey(namespace, name string) string {
var bindingName string
- if len(namespace) == 0 {
+ if len(namespace) > 0 {
bindingName = namespace + "-" + name
} else {
bindingName = name |
Signed-off-by: huangminjie <minjie.huang@daocloud.io>
17b791d
to
f30c2af
Compare
@RainbowMango done |
Thanks for your quick response. |
agreed |
OK. Let's do it. |
[APPROVALNOTIFIER] This PR is APPROVED 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: huangminjie minjie.huang@daocloud.io
What type of PR is this?
/kind bug
What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?: