-
Notifications
You must be signed in to change notification settings - Fork 910
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
Generate work name by hash code #509
Conversation
is this backwards compatible ? |
I don't think so. |
The ComputeHash func is used by kubernetes default controller-manager. |
Sorry for let this sit so long. I'll get back to it soon. |
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.
Thanks for doing this.
I'm thinking if we can use a pattern like: "name-[hash-value]".
If the whole work name is a hash value, it may be hard to check the work for debugging.
[edit]
I'm thinking if we can use a pattern like: "name-".
This will still have a limitation about the name length. (not really fixes #463, but we can iterate later)
import ( | ||
"hash" | ||
|
||
"github.com/davecgh/go-spew/spew" |
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.
My concern is the dependency because it seems has been abandoned.
I'm wondering if we can implement a DeepHashObject
by ourselves with its alternatives, such as https://github.com/kr/pretty.
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.
It makes sense. Let me take a look.
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.
By the way, the k/k is going to deprecate the go-spew
, but we can't wait for that. Let's try to implement it by ourselves.
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.
pkg/util/names/names.go
Outdated
var workName string | ||
if len(namespace) == 0 { | ||
return strings.ToLower(name + "-" + kind) | ||
workName = strings.ToLower(name + "-" + kind) | ||
} else { | ||
workName = strings.ToLower(namespace + "-" + name + "-" + kind) | ||
} | ||
return strings.ToLower(namespace + "-" + name + "-" + kind) | ||
hash := fnv.New32a() | ||
hashutil.DeepHashObject(hash, workName) | ||
return rand.SafeEncodeString(fmt.Sprint(hash.Sum32())) |
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.
What's the work
name look like with this patch? Can you give an 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.
For example, the work name default-b0d72d2a-modelpool
's generated name is 774fd95bcf
. It is a uint32
hash code and safely encoded. The origin uint32 hash code is 3309851679
.
The name could be like |
Yes, exactly. |
Now the work name is just like |
LGTM. Are you going to tidy to commits? |
Signed-off-by: Garrybest <[email protected]>
Signed-off-by: Garrybest <[email protected]>
Done, thanks for reminding. @RainbowMango |
/lgtm |
[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: Garrybest [email protected]
What type of PR is this?
/kind bug
What this PR does / why we need it:
Generate work name by MD5 hash of its namespace, kind and name in order to limit the name less than 63 characters. Consider that the mcs-controller has used work name and namespace as a label selector to selecte the associated endpoint, so it is not appropriate to move this label into annotations.
karmada/pkg/controllers/mcs/endpointslice_controller.go
Lines 42 to 45 in 514b5e6
Which issue(s) this PR fixes:
Fixes #463
Special notes for your reviewer:
Does this PR introduce a user-facing change?: