Iilun commented on code in PR #708:
URL: https://github.com/apache/pekko-management/pull/708#discussion_r2965562003
##########
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:
This works, but maybe it should be written somewhere that setting the value
of `hashLength` to more than 52 is useless as SHA256 hash has a fixed length
that is represented by 52 characters in base32
--
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]