skonto edited a comment on issue #24219: [SPARK-27258][K8S]Deal with the k8s 
resource names that don't match their own regular expression 
URL: https://github.com/apache/spark/pull/24219#issuecomment-492152585
 
 
   `isValidName()` method uses `"[a-z0-9]([-a-z0-9]*[a-z0-9])?"` which is in 
compliance with the[ k8s 
codebase](https://github.com/kubernetes/kubernetes/blob/6902f3112d98eb6bd0894886ff9cd3fbd03a7f79/staging/src/k8s.io/apimachinery/pkg/util/validation/validation.go#L110)
 for DNS-1123 labels and works for service names also check the length and 
could be used as a final check.
    For example:
   ```
     private val preferredServiceName = 
s"${kubernetesConf.resourceNamePrefix}$DRIVER_SVC_POSTFIX"
     private val resolvedServiceName = if (preferredServiceName.length <= 
MAX_SERVICE_NAME_LENGTH) {
       preferredServiceName
     } else {
       val randomServiceId = KubernetesUtils.uniqueID(clock = clock)
       val shorterServiceName = s"spark-$randomServiceId$DRIVER_SVC_POSTFIX"
       logWarning(s"Driver's hostname would preferably be 
$preferredServiceName, but this is " +
         s"too long (must be <= $MAX_SERVICE_NAME_LENGTH characters). Falling 
back to use " +
         s"$shorterServiceName as the driver service's name.")
       shorterServiceName
     }
   ```
   This code can be refactored so that you call just a method that does the 
work for you and sanitizes the final whole thing.
   
   Sanitize does not fix the dash issue as a first character I agree, btw this 
happened before because of 
[truncation](https://github.com/apache/spark/pull/23781), but the sanitize 
method could be improved or re-use the logic for the executor pod names 
[here](https://github.com/apache/spark/blob/master/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/features/BasicExecutorFeatureStep.scala#L87).
   So I think its not just dash that needs to be removed from the beginning of 
the name.
   

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to