Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ private[spark] object KubernetesConf {
.replaceAll("\\.", "-")
.replaceAll("[^a-z0-9\\-]", "")
.replaceAll("-+", "-")
.replaceAll("^-", "")
Copy link
Member

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 "-"?

Copy link
Author

@hehuiyuan hehuiyuan Jun 15, 2019

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 "-"?

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-9 is replace.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Contributor

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?

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))) {
Copy link
Contributor

@skonto skonto Jun 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the svc name valid in all cases according to com.google.common.net.InternetDomainName.isValid as mentioned in the other PR? It seems that the svc name which is up to 63 chars and has no dots in it matches a domain label (https://www.ietf.org/rfc/rfc3490.txt) so that method will cover the validation.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the svc name valid in all cases according to com.google.common.net.InternetDomainName.isValid as mentioned in the other PR? As it is now it seems valid according to the spec: https://en.wikipedia.org/wiki/Domain_name.

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
    )

@CheckObjectMeta( regexp = "^[a-z]([-a-z0-9]*[a-z0-9])?$", max = 63 )

Copy link
Contributor

@skonto skonto Jun 11, 2019

Choose a reason for hiding this comment

The 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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the purpose of Character.isLetter here, we've already filtered this down to only allow [a-z0-9]

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.")
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

@skonto skonto Jun 11, 2019

Choose a reason for hiding this comment

The 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 shorterServiceName . Since it may be invalid and not shorter in some cases I would replace shorterServiceName with defaultServiceName. Anyway this is nit.

Copy link
Author

@hehuiyuan hehuiyuan Jun 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh,I got it!

shorterServiceName
}

Expand Down