openkruise / kruise

Automated management of large-scale applications on Kubernetes (incubating project under CNCF)
https://openkruise.io
Other
4.5k stars 749 forks source link

[feature request] Make CloneSet and StatefulSet Support the generateName setting #1627

Open iambocai opened 2 months ago

iambocai commented 2 months ago

What would you like to be added:

To make CloneSet and StatefulSet support the GenerateName setting.

Why is this needed:

Currently, CloneSet rigidly uses {workloadName}-{randomID} when generating pod.Name. There is a risk here as workload names can be up to 253 bytes long, while pod names are limited to 63 bytes. Therefore, if the user-defined workload name exceeds 57 bytes, the resulting pod name will exceed the limit and become unusable. The general solution to this problem is to specify GenerateName, but our current implementation of CloneSet does not support this feature. This leaves users facing such issues with no option but to shorten the workload name, which compromises readability and is not a good solution from a management standpoint. Therefore, I hope that support for the GenerateName setting can be incorporated.

https://github.com/openkruise/kruise/blob/a836e90578067d0c44372bc3be116cc3d06babed/pkg/controller/cloneset/core/cloneset_core.go#L98

The requirements for StatefulSet would be similar.

Radeity commented 1 month ago

Hi @furykerry , I can work on this issue, can you assign me?

furykerry commented 1 month ago

/assign @Radeity

Radeity commented 1 month ago

Hi @iambocai , I've tested this issue, actually, the limit is not pod name, but the length of label name & label value.

For this issue, there's already a feature gate to handle it, you can set CloneSetShortHash to true, and then you can use longer cs name.

Related code logic: https://github.com/openkruise/kruise/blob/89d9558dd511a96c7ed1a01ca7fdfe2eec5c3324/pkg/controller/cloneset/utils/cloneset_utils.go#L71-L79

Thus, it seems like no need to make any changes to codes. cc @furykerry

furykerry commented 1 month ago

@Radeity although short cloneset hash can be helpful to break the name length limit, it is still beneficial to support generateName field which is a more common way to handle this problem

Radeity commented 1 month ago

Hi @furykerry , thanks for your reply. If I understand correctly, in this feat, we should support to use CloneSet/StatefulSet's GenerateName as the prefix of their children's pod name, and keep suffix of pod name unchanged (like availableID in CloneSet, ordinal of StatefulSet)?

furykerry commented 1 month ago

yes, just replace the prefix with generateName if available