Iilun commented on code in PR #708:
URL: https://github.com/apache/pekko-management/pull/708#discussion_r2965664096
##########
lease-kubernetes/src/main/scala/org/apache/pekko/coordination/lease/kubernetes/AbstractKubernetesLease.scala:
##########
@@ -52,12 +89,25 @@ object AbstractKubernetesLease {
/**
* Make a name compatible with DNS 1039 standard: like a single domain name
segment.
* Regex to follow: [a-z]([-a-z0-9]*[a-z0-9])
- * Limit the resulting name to 63 characters
+ * Limit the resulting name to maxLength characters (default 63).
+ * When truncation is necessary and hashLength > 0, the last (hashLength +
1) characters of the
+ * truncated name are replaced by a hyphen followed by a
hashLength-character hash suffix derived
+ * from a SHA-256 digest of the original name (base32-encoded, first
hashLength chars taken).
+ * If hashLength >= maxLength the result consists entirely of the first
maxLength hash characters.
*/
- private def makeDNS1039Compatible(name: String): String = {
+ private[kubernetes] def makeDNS1039Compatible(name: String, maxLength: Int =
63, hashLength: Int = 0): String = {
val normalized =
Normalizer.normalize(name,
Normalizer.Form.NFKD).toLowerCase.replaceAll("[_.]",
"-").replaceAll("[^-a-z0-9]", "")
- trim(truncateTo63Characters(normalized), List('-'))
+ if (normalized.length <= maxLength || hashLength <= 0) {
+ trim(truncateToLength(normalized, maxLength), List('-'))
+ } else if (hashLength >= maxLength) {
Review Comment:
I completely agree, I just meant that someone that sets the length to 253
and hash to 253 would still only get 52 characters output, whereas setting 253
and 52 would get 253 with a suffix of 52, hence why maybe it should suggest
somewhere that setting hash to more than 52 is not what you want
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]