zgzzbws commented on code in PR #58730:
URL: https://github.com/apache/spark/pull/58730#discussion_r4056062035


##########
resource-managers/kubernetes/core/src/test/scala/org/apache/spark/deploy/k8s/KubernetesVolumeUtilsSuite.scala:
##########
@@ -257,6 +257,38 @@ class KubernetesVolumeUtilsSuite extends SparkFunSuite {
     assert(e.getMessage.contains("nfs.volumeName.options.server"))
   }
 
+  test("Parses csi volumes correctly") {
+    val sparkConf = new SparkConf(false)
+    sparkConf.set("test.csi.volumeName.mount.path", "/path")
+    sparkConf.set("test.csi.volumeName.mount.readOnly", "true")
+    sparkConf.set("test.csi.volumeName.options.driver", "csi.example.com")
+    sparkConf.set("test.csi.volumeName.options.fsType", "ext4")
+    sparkConf.set("test.csi.volumeName.options.nodePublishSecretName", 
"csi-secret")
+    sparkConf.set("test.csi.volumeName.options.volumeAttributes.foo", "bar")
+    // Only `options.volumeAttributes.*` become CSI volume attributes; any 
other unknown
+    // `options.*` key is ignored rather than swept in as an attribute.
+    sparkConf.set("test.csi.volumeName.options.unknownOption", "ignored")
+
+    val volumeSpec = KubernetesVolumeUtils.parseVolumesWithPrefix(sparkConf, 
"test.").head
+    assert(volumeSpec.volumeName === "volumeName")
+    assert(volumeSpec.mountPath === "/path")
+    assert(volumeSpec.mountReadOnly === true)
+    assert(volumeSpec.volumeConf.asInstanceOf[KubernetesCSIVolumeConf] ===
+      KubernetesCSIVolumeConf("csi.example.com", Map("foo" -> "bar"),
+        fsType = Some("ext4"), nodePublishSecretName = Some("csi-secret")))
+  }
+
+  test("Fails on missing csi driver option") {
+    val sparkConf = new SparkConf(false)
+    sparkConf.set("test.csi.volumeName.mount.path", "/path")
+    sparkConf.set("test.csi.volumeName.options.volumeAttributes.foo", "bar")
+
+    val e = intercept[NoSuchElementException] {
+      KubernetesVolumeUtils.parseVolumesWithPrefix(sparkConf, "test.")
+    }
+    assert(e.getMessage.contains("csi.volumeName.options.driver"))

Review Comment:
   Done. The assertion now checks the full message 
"csi.volumeName.options.driver is required for csi", which is only thrown by 
verifyOptionKey



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to