[SPARK-33063][K8S] Improve error message for insufficient K8s volume confs#29941
[SPARK-33063][K8S] Improve error message for insufficient K8s volume confs#29941Gschiavon wants to merge 2 commits intoapache:masterfrom
Conversation
|
ok to test |
|
Thank you for your contribution, @Gschiavon . |
|
Test build #129391 has finished for PR 29941 at commit
|
|
Kubernetes integration test starting |
|
Kubernetes integration test status success |
| import org.apache.spark.SparkConf | ||
| import org.apache.spark.deploy.k8s.Config._ | ||
|
|
||
|
|
There was a problem hiding this comment.
Could you remove this addition? The existing one line looks okay to me. (https://github.com/databricks/scala-style-guide#blank-lines-vertical-whitespace)
Use one or two blank line(s) to separate class or object definitions.
There was a problem hiding this comment.
yes! just waiting for the checks to pass. Removing now
| val sparkConf = new SparkConf(false) | ||
| sparkConf.set("test.persistentVolumeClaim.volumeName.mount.path", "/path") | ||
| sparkConf.set("test.persistentVolumeClaim.volumeName.mount.readOnly", "true") | ||
| sparkConf.set("test.persistentVolumeClaim.volumeName.options.clamName", "claimeName") |
There was a problem hiding this comment.
Although I understand your intention to use clamName as a typo, it would be great if you use more explicit test case. This is easily misleading the reviewer. Please remove this line completely. That is more clear.
There was a problem hiding this comment.
I agree! I did it to follow the "style" of the other tests, but I'll remove it.
| .fold( | ||
| _ => throw new NoSuchElementException(s"When using $KUBERNETES_VOLUMES_HOSTPATH_TYPE " + | ||
| "Kubernetes volumes, it is necessary to define " + | ||
| s"$KUBERNETES_VOLUMES_HOSTPATH_TYPE.volumeName.$KUBERNETES_VOLUMES_OPTIONS_PATH_KEY" + |
There was a problem hiding this comment.
Can we use pathKey instead of this $KUBERNETES_VOLUMES_HOSTPATH_TYPE.volumeName.$KUBERNETES_VOLUMES_OPTIONS_PATH_KEY?
There was a problem hiding this comment.
I didnt use path key because it includes the volume name given by the user and I wasn't sure about this.
I've added it.
There was a problem hiding this comment.
@Gschiavon . This PR has some repeated pattern to provide an informative error message. I'd like to recommend you to have a helper function.
private def verifyOptionKey(options: Map[String, String], key: String, msg: String): Unit = {
if (!options.isDefinedAt(key)) {
throw new NoSuchElementException(key + s"is required for $msg")
}
} private def parseVolumeSpecificConf(
options: Map[String, String],
volumeType: String,
@@ -67,6 +73,7 @@ private[spark] object KubernetesVolumeUtils {
volumeType match {
case KUBERNETES_VOLUMES_HOSTPATH_TYPE =>
val pathKey = s"$volumeType.$volumeName.$KUBERNETES_VOLUMES_OPTIONS_PATH_KEY"
+ verifyOptionKey(options, pathKey, KUBERNETES_VOLUMES_HOSTPATH_TYPE)
KubernetesHostPathVolumeConf(options(pathKey))
case KUBERNETES_VOLUMES_PVC_TYPE =>
@@ -74,6 +81,7 @@ private[spark] object KubernetesVolumeUtils {
val storageClassKey =
s"$volumeType.$volumeName.$KUBERNETES_VOLUMES_OPTIONS_CLAIM_STORAGE_CLASS_KEY"
val sizeLimitKey = s"$volumeType.$volumeName.$KUBERNETES_VOLUMES_OPTIONS_SIZE_LIMIT_KEY"
+ verifyOptionKey(options, claimNameKey, KUBERNETES_VOLUMES_PVC_TYPE)
KubernetesPVCVolumeConf(
options(claimNameKey),
options.get(storageClassKey),
@@ -87,6 +95,8 @@ private[spark] object KubernetesVolumeUtils {
case KUBERNETES_VOLUMES_NFS_TYPE =>
val pathKey = s"$volumeType.$volumeName.$KUBERNETES_VOLUMES_OPTIONS_PATH_KEY"
val serverKey = s"$volumeType.$volumeName.$KUBERNETES_VOLUMES_OPTIONS_SERVER_KEY"
+ verifyOptionKey(options, pathKey, KUBERNETES_VOLUMES_NFS_TYPE)
+ verifyOptionKey(options, serverKey, KUBERNETES_VOLUMES_NFS_TYPE)
KubernetesNFSVolumeConf(
options(pathKey),
options(serverKey))|
Test build #129398 has finished for PR 29941 at commit
|
|
Kubernetes integration test starting |
|
Kubernetes integration test status success |
There was a problem hiding this comment.
+1, LGTM. Thank you so much, @Gschiavon .
Merged to master.
|
Thank you, @Gschiavon . SPARK-33063 is assigned to you. |
|
Thanks @dongjoon-hyun ! |
What changes were proposed in this pull request?
Provide error handling when creating kubernetes volumes. Right now they keys are expected to be there and if not it fails with a
key not founderror, but not knowing why do you need thatkey.Also I renamed some tests that didn't indicate the kind of kubernetes volume
Why are the changes needed?
Easier for the users to understand why
spark-submitcommand is failing if not providing they right kubernetes volumes properties.Does this PR introduce any user-facing change?
No
How was this patch tested?
It was tested with the current tests plus added one more.
Jira ticket