fix(controller): handle long rule names in bootstrap annotation keys#224
fix(controller): handle long rule names in bootstrap annotation keys#224vishnukothakapu wants to merge 1 commit into
Conversation
✅ Deploy Preview for node-readiness-controller canceled.
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: vishnukothakapu The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Welcome @vishnukothakapu! |
|
Hi @vishnukothakapu. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Regular contributors should join the org to skip this step. Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
538cca4 to
d42de51
Compare
|
Thanks for catching this. My only thoughts on this is that it takes away the human observability on this when a bootsrap-rule is done. :/ |
| // 20 (prefix) + 32 (hash) = 52 characters. | ||
| namePart = hex.EncodeToString(hash[:16]) | ||
| } | ||
| return fmt.Sprintf("%s%s", bootstrapAnnotationPrefix, namePart) |
There was a problem hiding this comment.
should we go with a hybrid approach something like below
availableSpace := maxK8sAnnotationNameLen - len(bootstrapAnnotationPrefix)
const hashLen = 8
humanPartLen := availableSpace - hashLen - 1
hashBytes := sha256.Sum256([]byte(ruleName))
shortHash := hex.EncodeToString(hashBytes[:])[:hashLen]
namePart := fmt.Sprintf("%s-%s", ruleName[:humanPartLen], shortHash)
return fmt.Sprintf("%s%s", bootstrapAnnotationPrefix, namePart)this way we keep the ruleName
There was a problem hiding this comment.
we have a lot of options to handle this. I added some different approach as well. We could discuss further over the meeting, feel free to join if you are available, @vishnukothakapu
|
The annotation restrictions are Hashing the rule name is one option, couple of alternatives to consider:
We need to evaluate the pros/cons on the implementation. @vishnukothakapu Do you want to evaluate the alternatives and propose a plan here? |
Good point. I agree the full hash reduces readability during debugging. I’ll explore the hybrid approach with a readable prefix + short hash and compare it with the other alternatives discussed.
Thanks @ajaysundark , these are good points. I’ll evaluate the tradeoffs between the current hashing approach, the hybrid readable-prefix approach, and the single annotation JSON payload design, then propose a direction based on readability, implementation complexity, and backward compatibility. |
|
/assign @vishnukothakapu |
|
Hi @AvineshTripathi & @ajaysundark, |
…using hybrid approach
87864cf to
261f03d
Compare
Could you clarify your thoughts further on this? What are the downsides of using a json payload. This is also how kubectl saves last applied configurations in objects today - ref: https://kubernetes.io/docs/tasks/manage-kubernetes-objects/declarative-config/#how-to-create-objects @AvineshTripathi / @Karthik-K-N I think fixing this short-term with a hash based approach for length immunity doesnt feel right. A more reliable long term solution would be to maintain the rule-status inside a JSON payload to track individual rule evaluation data. It would also address concerns such as #247 |
Description
This PR fixes a bug where NodeReadinessRule resources with long names (longer than 43 characters) caused the controller to fail when patching Node annotations. Kubernetes strictly limits the name part of an annotation key to 63 characters. Since our key pattern was
readiness.k8s.io/bootstrap-completed-<rule-name>, long rule names resulted in invalid keys.I introduced a helper function
getBootstrapAnnotationKeythat deterministically hashes the rule name using MD5 when it exceeds the length limit, ensuring the final key is always valid.Related Issue
Fixes #223
Type of Change
/kind bug
Testing
Checklist
make testpassesmake lintpassesDoes this PR introduce a user-facing change?
NONE