-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-27258][K8S]Deal with the k8s resource names that don't match their own regular expression #24839
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]Deal with the k8s resource names that don't match their own regular expression #24839
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,14 +39,15 @@ private[spark] class DriverServiceFeatureStep( | |
| "managed via a Kubernetes service.") | ||
|
|
||
| private val preferredServiceName = s"${kubernetesConf.resourceNamePrefix}$DRIVER_SVC_POSTFIX" | ||
| private val resolvedServiceName = if (preferredServiceName.length <= MAX_SERVICE_NAME_LENGTH) { | ||
| private val resolvedServiceName = if (preferredServiceName.length <= MAX_SERVICE_NAME_LENGTH | ||
| && Character.isLetter(preferredServiceName.charAt(0))) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the svc name valid in all cases according to
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Now, fabric8 API has some limitations, public class Service implements HasMetadata {
@NotNull
@JsonProperty("apiVersion")
private String apiVersion = "v1";
@NotNull
@JsonProperty("kind")
private String kind = "Service";
@JsonProperty("metadata")
@Valid
@CheckObjectMeta(
regexp = "^[a-z]([-a-z0-9]*[a-z0-9])?$",
max = 63
)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I saw that when digging into it. It should be ok from what I read: https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/ "Assume a Service named foo in the Kubernetes namespace bar. A Pod running in namespace bar can look up this service by simply doing a DNS query for foo. A Pod running in namespace quux can look up this service by doing a DNS query for foo.bar." so it matches the domain label, that is why there are these limitations. @liyinan926 can you verify this?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand the purpose of |
||
| 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.") | ||
| s"too long (must be <= $MAX_SERVICE_NAME_LENGTH characters) or is not a valid service name." + | ||
| s"Falling back to use $shorterServiceName as the driver service's name.") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it should be falling back to some default name. It is not necessarily the shorter if the preferred is invalid.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is only a method for dealing with the invalid service name. If the name is invalid and we don't deal with it, the job only has a driver pod.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am referring to the warning message could be made more specific and also the name of the variable
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh,I got it! |
||
| shorterServiceName | ||
| } | ||
|
|
||
|
|
||
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.
Is this still needed then, if you're simply validating and replacing the name if it starts with "-"?
Uh oh!
There was an error while loading. Please reload this page.
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.
The '^-' is used for all kubernetes resources. If the resource name starts with "-",we replace it with
"",which can run normally .The service name that starts with
0-9is replace.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.
?
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.
If we need to match the fabric8 regex bellow, shouldn't this be
.replaceAll("^[^a-z]", "")to replace any leading/first non alpha character?