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-25647][k8s] Add spark streaming compatibility suite for kubernetes. #22639
Changes from all commits
d2230fc
29a8e2e
729e5a9
c63c54e
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 |
---|---|---|
@@ -0,0 +1,214 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.spark.deploy.k8s.integrationtest | ||
|
||
import java.net._ | ||
|
||
import scala.collection.JavaConverters._ | ||
import scala.concurrent.ExecutionContext.Implicits.global | ||
import scala.concurrent.Future | ||
|
||
import org.scalatest.concurrent.{Eventually, PatienceConfiguration} | ||
import org.scalatest.time.{Minutes, Span} | ||
|
||
import org.apache.spark.deploy.k8s.integrationtest.KubernetesSuite._ | ||
import org.apache.spark.deploy.k8s.integrationtest.TestConstants._ | ||
import org.apache.spark.internal.Logging | ||
import org.apache.spark.util | ||
|
||
private[spark] trait StreamingCompatibilitySuite { | ||
|
||
k8sSuite: KubernetesSuite => | ||
|
||
import StreamingCompatibilitySuite._ | ||
|
||
test("Run spark streaming in client mode.", k8sTestTag) { | ||
val (host, port, serverSocket) = startSocketServer() | ||
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. We could use a custom source as an alternative for feeding the stream. Re-using existing code is also nice. 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. Please correct my understanding, a custom source has to either live in examples, or a separate image has to be published with the class path of the custom source. 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 more inclined to add in the examples. Just an alternative option. |
||
val driverService = driverServiceSetup | ||
try { | ||
setupSparkStreamingPod(driverService.getMetadata.getName) | ||
.addToArgs("streaming.NetworkWordCount") | ||
.addToArgs(host, port.toString) | ||
.endContainer() | ||
.endSpec() | ||
.done() | ||
Eventually.eventually(TIMEOUT, INTERVAL) { | ||
assert(getRunLog.contains("spark-streaming-kube"), "The application did not complete.") | ||
} | ||
} finally { | ||
// Have to delete the service manually since it doesn't have an owner reference | ||
kubernetesTestComponents | ||
.kubernetesClient | ||
.services() | ||
.inNamespace(kubernetesTestComponents.namespace) | ||
.delete(driverService) | ||
serverSocket.close() | ||
} | ||
} | ||
|
||
test("Run spark streaming in cluster mode.", k8sTestTag) { | ||
val (host, port, serverSocket) = startSocketServer() | ||
try { | ||
runSparkJVMCheckAndVerifyCompletion( | ||
mainClass = "org.apache.spark.examples.streaming.NetworkWordCount", | ||
appArgs = Array[String](host, port.toString), | ||
expectedJVMValue = Seq("spark-streaming-kube")) | ||
} finally { | ||
serverSocket.close() | ||
} | ||
} | ||
|
||
test("Run spark structured streaming in cluster mode.", k8sTestTag) { | ||
val (host, port, serverSocket) = startSocketServer() | ||
try { | ||
runSparkJVMCheckAndVerifyCompletion( | ||
mainClass = "org.apache.spark.examples.sql.streaming.StructuredNetworkWordCount", | ||
appArgs = Array[String](host, port.toString), | ||
expectedJVMValue = Seq("spark-streaming-kube")) | ||
} finally { | ||
serverSocket.close() | ||
} | ||
} | ||
|
||
test("Run spark structured streaming in client mode.", k8sTestTag) { | ||
val (host, port, serverSocket) = startSocketServer() | ||
val driverService = driverServiceSetup | ||
try { | ||
setupSparkStreamingPod(driverService.getMetadata.getName) | ||
.addToArgs("sql.streaming.StructuredNetworkWordCount") | ||
.addToArgs(host, port.toString) | ||
.endContainer() | ||
.endSpec() | ||
.done() | ||
|
||
val TIMEOUT = PatienceConfiguration.Timeout(Span(3, Minutes)) | ||
Eventually.eventually(TIMEOUT, INTERVAL) { | ||
assert(getRunLog.contains("spark-streaming-kube"), | ||
"The application did not complete.") | ||
} | ||
} | ||
finally { | ||
// Have to delete the service manually since it doesn't have an owner reference | ||
kubernetesTestComponents | ||
.kubernetesClient | ||
.services() | ||
.inNamespace(kubernetesTestComponents.namespace) | ||
.delete(driverService) | ||
serverSocket.close() | ||
} | ||
} | ||
|
||
private def getRunLog: String = kubernetesTestComponents.kubernetesClient | ||
.pods() | ||
.withName(driverPodName) | ||
.getLog | ||
|
||
private def setupSparkStreamingPod(driverServiceName: String) = { | ||
val labels = Map("spark-app-selector" -> driverPodName) | ||
testBackend | ||
.getKubernetesClient | ||
.pods() | ||
.inNamespace(kubernetesTestComponents.namespace) | ||
.createNew() | ||
.withNewMetadata() | ||
.withName(driverPodName) | ||
.withLabels(labels.asJava) | ||
.endMetadata() | ||
.withNewSpec() | ||
.withServiceAccountName(kubernetesTestComponents.serviceAccountName) | ||
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. The flakiness of the tests seems to be in relation to this service account. Investigate the necessary rbac.yml that would need to be set to ensure that these failures don't come up? 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. The same is used in "run in client mode" test. 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 not sure, what is causing it. Do you have any clue? 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 believe this was solved in the Client mode tests, despite the addition of the 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 have run these tests on my own setup of minikube, and I am unable to reproduce the failure that occurred on jenkins. It is possible that is related to how minikube is setup on jenkins. |
||
.addNewContainer() | ||
.withName("spark-example") | ||
.withImage(image) | ||
.withImagePullPolicy("IfNotPresent") | ||
.withCommand("/opt/spark/bin/run-example") | ||
.addToArgs("--master", s"k8s://https://kubernetes.default.svc") | ||
.addToArgs("--deploy-mode", "client") | ||
.addToArgs("--conf", s"spark.kubernetes.container.image=$image") | ||
.addToArgs("--conf", | ||
s"spark.kubernetes.namespace=${kubernetesTestComponents.namespace}") | ||
.addToArgs("--conf", "spark.kubernetes.authenticate.oauthTokenFile=" + | ||
"/var/run/secrets/kubernetes.io/serviceaccount/token") | ||
.addToArgs("--conf", "spark.kubernetes.authenticate.caCertFile=" + | ||
"/var/run/secrets/kubernetes.io/serviceaccount/ca.crt") | ||
.addToArgs("--conf", s"spark.kubernetes.driver.pod.name=$driverPodName") | ||
.addToArgs("--conf", "spark.executor.memory=500m") | ||
.addToArgs("--conf", "spark.executor.cores=2") | ||
.addToArgs("--conf", "spark.executor.instances=1") | ||
.addToArgs("--conf", | ||
s"spark.driver.host=$driverServiceName.${kubernetesTestComponents.namespace}.svc") | ||
.addToArgs("--conf", s"spark.driver.port=$driverPort") | ||
.addToArgs("--conf", s"spark.driver.blockManager.port=$blockManagerPort") | ||
} | ||
|
||
private def driverServiceSetup = { | ||
val labels = Map("spark-app-selector" -> driverPodName) | ||
testBackend | ||
.getKubernetesClient | ||
.services() | ||
.inNamespace(kubernetesTestComponents.namespace) | ||
.createNew() | ||
.withNewMetadata() | ||
.withName(s"$driverPodName-svc") | ||
.endMetadata() | ||
.withNewSpec() | ||
.withClusterIP("None") | ||
.withSelector(labels.asJava) | ||
.addNewPort() | ||
.withName("driver-port") | ||
.withPort(driverPort) | ||
.withNewTargetPort(driverPort) | ||
.endPort() | ||
.addNewPort() | ||
.withName("block-manager") | ||
.withPort(blockManagerPort) | ||
.withNewTargetPort(blockManagerPort) | ||
.endPort() | ||
.endSpec() | ||
.done() | ||
} | ||
} | ||
|
||
object StreamingCompatibilitySuite extends Logging { | ||
|
||
private def startSocketServer( | ||
hostname: String = util.Utils.localHostName(), port: Int = 0) = { | ||
val hostAddress: String = InetAddress.getByName(hostname).getHostAddress | ||
val serverSocket = new ServerSocket() | ||
serverSocket.bind(new InetSocketAddress(hostAddress, 0)) | ||
val host = serverSocket.getInetAddress.getHostAddress | ||
val port = serverSocket.getLocalPort | ||
logInfo(s"Started test server socket at $host:$port") | ||
Future { | ||
while (!serverSocket.isClosed) { | ||
val socket: Socket = serverSocket.accept() | ||
logInfo(s"Received connection on $socket") | ||
for (i <- 1 to 10 ) { | ||
if (socket.isConnected && !serverSocket.isClosed) { | ||
socket.getOutputStream.write("spark-streaming-kube test.\n".getBytes("UTF-8")) | ||
socket.getOutputStream.flush() | ||
Thread.sleep(100) | ||
} | ||
} | ||
socket.close() | ||
} | ||
} | ||
(host, port, serverSocket) | ||
} | ||
|
||
|
||
} |
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.
Space separated single argument or, multiple different argument. If we do
.mkString(" ")
then, it takes multi arguments as space separated single argument.