-
Notifications
You must be signed in to change notification settings - Fork 28.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SPARK-27258][K8S]Add the prefix 'spark-' for resourceNamePrefix that starts with number #24188
Conversation
ok to test |
@@ -78,7 +78,10 @@ private[spark] class KubernetesDriverConf( | |||
|
|||
override val resourceNamePrefix: String = { | |||
val custom = if (Utils.isTesting) get(KUBERNETES_DRIVER_POD_NAME_PREFIX) else None | |||
custom.getOrElse(KubernetesConf.getResourceNamePrefix(appName)) | |||
val resourceNamePrefix = custom.getOrElse(KubernetesConf.getResourceNamePrefix(appName)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable name is confusing since this is in override val resourceNamePrefix: String = {}
.
val resourceNamePrefix = custom.getOrElse(KubernetesConf.getResourceNamePrefix(appName)) | ||
// If the first character of resourceNamePrefix is number,add the extra prefix : "spark-". | ||
val prefix = "spark-" + resourceNamePrefix.charAt(0) | ||
resourceNamePrefix.replaceAll("^[0-9]", prefix) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, did you run the test locally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- For example: resourceNamePrefix = 1min-xxx
After execute this code:
val prefix = "spark-" + resourceNamePrefix.charAt(0) resourceNamePrefix.replaceAll("^[0-9]", prefix)
resourceNamePrefix = spark-1min-xxx,which satisfies the regular expression [a-z]([-a-z0-9]*[a-z0-9])?
- For example : resourceNamePrefix = min-xxx
After execute this code:
val prefix = "spark-" + resourceNamePrefix.charAt(0) resourceNamePrefix.replaceAll("^[0-9]", prefix)
resourceNamePrefix = min-xxx,which does not change.
Local testing was done for thisoverride val resourceNamePrefix
only.
Kubernetes integration test starting |
Test build #103880 has finished for PR 24188 at commit
|
Kubernetes integration test status success |
I think we can only update the resourceNamePrefix of service, which may be better. For the class of DriverServiceFeatureStep : 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
}
Update: def isNumber(char: Char) : Boolean = {
char >= '0' && char <= '9'
}
private val preferredServiceName = s"${kubernetesConf.resourceNamePrefix}$DRIVER_SVC_POSTFIX"
private val resolvedServiceName = if (preferredServiceName.length <= MAX_SERVICE_NAME_LENGTH
&& !isNumber(preferredServiceName.charAt(0))) {
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) " +
s"or the first character of $preferredServiceName is number which is not support." +
s" Falling back to use $shorterServiceName as the driver service's name.")
shorterServiceName
} |
val resourceNamePrefix = custom.getOrElse(KubernetesConf.getResourceNamePrefix(appName)) | ||
// If the first character of resourceNamePrefix is number,add the extra prefix : "spark-". | ||
val prefix = "spark-" + resourceNamePrefix.charAt(0) | ||
resourceNamePrefix.replaceAll("^[0-9]", prefix) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just prepend "spark-" if the first character is a digit? if (Character.isDigit(resourceNamePrefix(0)))
But don't you actually need to check if it starts with a-z?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just prepend "spark-" if the first character is a digit?
if (Character.isDigit(resourceNamePrefix(0)))
But don't you actually need to check if it starts with a-z?
Hi, this code does not change the resourceNamePrefix that the first character is not a digit.
1: For example: resourceNamePrefix = 1min-xxx
After execute this code:
val prefix = "spark-" + resourceNamePrefix.charAt(0) resourceNamePrefix.replaceAll("^[0-9]", prefix)
resourceNamePrefix = spark-1min-xxx,
which satisfies the regular expression [a-z]([-a-z0-9]*[a-z0-9])?
2 : For example : resourceNamePrefix = min-xxx
After execute this code:
val prefix = "spark-" + resourceNamePrefix.charAt(0) resourceNamePrefix.replaceAll("^[0-9]", prefix)
resourceNamePrefix = min-xxx,which does not change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know, it's just more complex than it needs to be, and doesn't catch all the cases that would fail the pattern you show above: [a-z]([-a-z0-9]*[a-z0-9])?)
@dongjoon-hyun @srowen |
I'm not sure what your last comment means. This looks even more complex and the code is still incorrect. Example: what about an ID that starts with "Foo"? it isn't allowed by that regex but isn't detected by this code. This should be a 2 line change. |
The last comment means that is the another way used to resolve the PR . In this PR, if the first character of resourceNamePrefix is digit, it will change the value of resourceNamePrefix to add a extra prefix "spark-" for Driver Pod and Service. However, the last comment means :
If preferredServiceName satisfies If these two conditions are not met,we use shorterServiceName. The code in the last comment hasn't been submitted yet. I would like to ask you some advice.Is this better than the way in the PR? |
The useless PR can be closed, I just want to make it convenient for you to have a look. |
What changes were proposed in this pull request?
For SPARK-27258
The value of "spark.app.name" or "--name" starts with number , which causes resourceName does not match regular expression
[a-z]([-a-z0-9]*[a-z0-9])?)
.For example : the appName = "1min-machinereg-yf"
Exception :
Exception in thread "main" io.fabric8.kubernetes.client.KubernetesClientException: Failure executing: POST at: https://xxx:xxx/api/v1/namespaces/xxx/services. Message: Service "1min-machinereg-yf-1544604108931-driver-svc" is invalid: metadata.name: Invalid value: "1min-machinereg-yf-1544604108931-driver-svc": a DNS-1035 label must consist of lower case alphanumeric characters or '-', start with an alphabetic character, and end with an alphanumeric character (e.g. 'my-name', or 'abc-123', regex used for validation is '[a-z]([-a-z0-9]*[a-z0-9])?'). Received status: Status(apiVersion=v1, code=422, details=StatusDetails(causes=[StatusCause(field=metadata.name, message=Invalid value: "1min-machinereg-yf-1544604108931-driver-svc": a DNS-1035 label must consist of lower case alphanumeric characters or '-', start with an alphabetic character, and end with an alphanumeric character (e.g. 'my-name', or 'abc-123', regex used for validation is '[a-z]([-a-z0-9]*[a-z0-9])?'), reason=FieldValueInvalid, additionalProperties={})], group=null, kind=Service, name=1min-machinereg-yf-1544604108931-driver-svc, retryAfterSeconds=null, uid=null, additionalProperties={}).