markusthoemmes commented on a change in pull request #3961: Add length of podName checking code for K8s URL: https://github.com/apache/incubator-openwhisk/pull/3961#discussion_r209192008
########## File path: core/invoker/src/main/scala/whisk/core/containerpool/kubernetes/KubernetesContainer.scala ########## @@ -63,7 +63,9 @@ object KubernetesContainer { log: Logging): Future[KubernetesContainer] = { implicit val tid = transid - val podName = name.replace("_", "-").replaceAll("[()]", "").toLowerCase() + // Kubernetes naming rule allows maximum length of 63 character. + val origName = name.replace("_", "-").replaceAll("[()]", "").toLowerCase() + val podName = if (origName.length() > 63) origName.substring(0, 63) else origName Review comment: You can use `String`s `take` method to make this more succinct, like: ```scala val podName = name.replace("_", "-").replaceAll("[()]", "").toLowerCase.take(63) ``` This also works for Strings smaller than 63, as proven by this repl session: ``` @ val test = "a" * 100 test: String = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" @ test.take(63) res1: String = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" @ val test2 = "a" * 20 test2: String = "aaaaaaaaaaaaaaaaaaaa" @ test2.take(63) res3: String = "aaaaaaaaaaaaaaaaaaaa" ``` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services