Skip to content

Commit 61d9946

Browse files
rvesseMarcelo Vanzin
authored andcommitted
[SPARK-26729][K8S] Make image names under test configurable
## What changes were proposed in this pull request? Allow specifying system properties to customise the image names for the images used in the integration testing. Useful if your CI/CD pipeline or policy requires using a different naming format. This is one part of addressing SPARK-26729, I plan to have a follow up patch that will also make the names configurable when using `docker-image-tool.sh` ## How was this patch tested? Ran integration tests against custom images generated by our CI/CD pipeline that do not follow Spark's existing hardcoded naming conventions using the new system properties to override the image names appropriately: ``` mvn clean integration-test -pl :spark-kubernetes-integration-tests_${SCALA_VERSION} \ -Pkubernetes -Pkubernetes-integration-tests \ -P${SPARK_HADOOP_PROFILE} -Dhadoop.version=${HADOOP_VERSION} \ -Dspark.kubernetes.test.sparkTgz=${TARBALL} \ -Dspark.kubernetes.test.imageTag=${TAG} \ -Dspark.kubernetes.test.imageRepo=${REPO} \ -Dspark.kubernetes.test.namespace=${K8S_NAMESPACE} \ -Dspark.kubernetes.test.kubeConfigContext=${K8S_CONTEXT} \ -Dspark.kubernetes.test.deployMode=${K8S_TEST_DEPLOY_MODE} \ -Dspark.kubernetes.test.jvmImage=apache-spark \ -Dspark.kubernetes.test.pythonImage=apache-spark-py \ -Dspark.kubernetes.test.rImage=apache-spark-r \ -Dtest.include.tags=k8s ... [INFO] --- scalatest-maven-plugin:1.0:test (integration-test) spark-kubernetes-integration-tests_2.12 --- Discovery starting. Discovery completed in 230 milliseconds. Run starting. Expected test count is: 15 KubernetesSuite: - Run SparkPi with no resources - Run SparkPi with a very long application name. - Use SparkLauncher.NO_RESOURCE - Run SparkPi with a master URL without a scheme. - Run SparkPi with an argument. - Run SparkPi with custom labels, annotations, and environment variables. - Run extraJVMOptions check on driver - Run SparkRemoteFileTest using a remote data file - Run SparkPi with env and mount secrets. - Run PySpark on simple pi.py example - Run PySpark with Python2 to test a pyfiles example - Run PySpark with Python3 to test a pyfiles example - Run PySpark with memory customization - Run in client mode. - Start pod creation from template Run completed in 8 minutes, 33 seconds. Total number of tests run: 15 Suites: completed 2, aborted 0 Tests: succeeded 15, failed 0, canceled 0, ignored 0, pending 0 All tests passed. ``` Closes apache#23846 from rvesse/SPARK-26729. Authored-by: Rob Vesse <[email protected]> Signed-off-by: Marcelo Vanzin <[email protected]>
1 parent 93c6d2a commit 61d9946

File tree

5 files changed

+75
-5
lines changed

5 files changed

+75
-5
lines changed

resource-managers/kubernetes/integration-tests/README.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ The main useful options are outlined below.
2828
## Using a different backend
2929

3030
The integration test backend i.e. the K8S cluster used for testing is controlled by the `--deploy-mode` option. By
31-
default this is set to `minikube`, the available backends are their perequisites are as follows.
31+
default this is set to `minikube`, the available backends are their prerequisites are as follows.
3232

3333
### `minikube`
3434

@@ -46,7 +46,7 @@ environment variable appropriately.
4646

4747
### `cloud`
4848

49-
These cloud backend configures the tests to use an arbitrary Kubernetes cluster running in the cloud or otherwise.
49+
The cloud backend configures the tests to use an arbitrary Kubernetes cluster running in the cloud or otherwise.
5050

5151
The `cloud` backend auto-configures the cluster to use from your K8S config file, this is assumed to be `~/.kube/config`
5252
unless the `KUBECONFIG` environment variable is set to override this location. By default this will use whatever your
@@ -67,6 +67,18 @@ image tag that you have built by other means already, pass the tag to the test s
6767
where if you still want to use images that were built before by the test framework:
6868

6969
dev/dev-run-integration-tests.sh --image-tag $(cat target/imageTag.txt)
70+
71+
### Customising the Image Names
72+
73+
If your image names do not follow the standard Spark naming convention - `spark`, `spark-py` and `spark-r` - then you can customise the names using several options.
74+
75+
If you use the same basic pattern but a different prefix for the name e.g. `apache-spark` you can just set `--base-image-name <base-name>` e.g.
76+
77+
dev/dev-run-integration-tests.sh --base-image-name apache-spark
78+
79+
Alternatively if you use completely custom names then you can set each individually via the `--jvm-image-name <name>`, `--python-image-name <name>` and `--r-image-name <name>` arguments e.g.
80+
81+
dev/dev-run-integration-tests.sh --jvm-image-name jvm-spark --python-image-name pyspark --r-image-name sparkr
7082

7183
## Spark Distribution Under Test
7284

@@ -189,6 +201,27 @@ to the wrapper scripts and using the wrapper scripts will simply set these appro
189201
</td>
190202
<td><code>docker.io/kubespark</code></td>
191203
</tr>
204+
<tr>
205+
<td><code>spark.kubernetes.test.jvmImage</code></td>
206+
<td>
207+
The image name for the JVM based Spark image to test
208+
</td>
209+
<td><code>spark</code></td>
210+
</tr>
211+
<tr>
212+
<td><code>spark.kubernetes.test.pythonImage</code></td>
213+
<td>
214+
The image name for the Python based Spark image to test
215+
</td>
216+
<td><code>spark-py</code></td>
217+
</tr>
218+
<tr>
219+
<td><code>spark.kubernetes.test.rImage</code></td>
220+
<td>
221+
The image name for the R based Spark image to test
222+
</td>
223+
<td><code>spark-r</code></td>
224+
</tr>
192225
<tr>
193226
<td><code>spark.kubernetes.test.namespace</code></td>
194227
<td>

resource-managers/kubernetes/integration-tests/dev/dev-run-integration-tests.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ DEPLOY_MODE="minikube"
2323
IMAGE_REPO="docker.io/kubespark"
2424
SPARK_TGZ="N/A"
2525
IMAGE_TAG="N/A"
26+
BASE_IMAGE_NAME=
27+
JVM_IMAGE_NAME=
28+
PYTHON_IMAGE_NAME=
29+
R_IMAGE_NAME=
2630
SPARK_MASTER=
2731
NAMESPACE=
2832
SERVICE_ACCOUNT=
@@ -79,6 +83,22 @@ while (( "$#" )); do
7983
EXCLUDE_TAGS="$2"
8084
shift
8185
;;
86+
--base-image-name)
87+
BASE_IMAGE_NAME="$2"
88+
shift
89+
;;
90+
--jvm-image-name)
91+
JVM_IMAGE_NAME="$2"
92+
shift
93+
;;
94+
--python-image-name)
95+
PYTHON_IMAGE_NAME="$2"
96+
shift
97+
;;
98+
--r-image-name)
99+
R_IMAGE_NAME="$2"
100+
shift
101+
;;
82102
*)
83103
break
84104
;;
@@ -119,4 +139,15 @@ then
119139
properties=( ${properties[@]} -Dtest.exclude.tags=$EXCLUDE_TAGS )
120140
fi
121141

142+
BASE_IMAGE_NAME=${BASE_IMAGE_NAME:-spark}
143+
JVM_IMAGE_NAME=${JVM_IMAGE_NAME:-${BASE_IMAGE_NAME}}
144+
PYTHON_IMAGE_NAME=${PYTHON_IMAGE_NAME:-${BASE_IMAGE_NAME}-py}
145+
R_IMAGE_NAME=${R_IMAGE_NAME:-${R_IMAGE_NAME}-r}
146+
147+
properties+=(
148+
-Dspark.kubernetes.test.jvmImage=$JVM_IMAGE_NAME
149+
-Dspark.kubernetes.test.pythonImage=$PYTHON_IMAGE_NAME
150+
-Dspark.kubernetes.test.rImage=$R_IMAGE_NAME
151+
)
152+
122153
$TEST_ROOT_DIR/build/mvn integration-test -f $TEST_ROOT_DIR/pom.xml -pl resource-managers/kubernetes/integration-tests -am -Pscala-$SCALA_VERSION -Pkubernetes -Pkubernetes-integration-tests ${properties[@]}

resource-managers/kubernetes/integration-tests/pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,9 @@
148148
<spark.kubernetes.test.master>${spark.kubernetes.test.master}</spark.kubernetes.test.master>
149149
<spark.kubernetes.test.namespace>${spark.kubernetes.test.namespace}</spark.kubernetes.test.namespace>
150150
<spark.kubernetes.test.serviceAccountName>${spark.kubernetes.test.serviceAccountName}</spark.kubernetes.test.serviceAccountName>
151+
<spark.kubernetes.test.jvmImage>${spark.kubernetes.test.jvmImage}</spark.kubernetes.test.jvmImage>
152+
<spark.kubernetes.test.pythonImage>${spark.kubernetes.test.pythonImage}</spark.kubernetes.test.pythonImage>
153+
<spark.kubernetes.test.rImage>${spark.kubernetes.test.rImage}</spark.kubernetes.test.rImage>
151154
</systemProperties>
152155
<tagsToExclude>${test.exclude.tags}</tagsToExclude>
153156
<tagsToInclude>${test.include.tags}</tagsToInclude>

resource-managers/kubernetes/integration-tests/src/test/scala/org/apache/spark/deploy/k8s/integrationtest/KubernetesSuite.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ class KubernetesSuite extends SparkFunSuite
116116
sparkHomeDir = Paths.get(sparkDirProp)
117117
require(sparkHomeDir.toFile.isDirectory,
118118
s"No directory found for spark home specified at $sparkHomeDir.")
119-
image = testImageRef("spark")
120-
pyImage = testImageRef("spark-py")
121-
rImage = testImageRef("spark-r")
119+
image = testImageRef(sys.props.getOrElse(CONFIG_KEY_IMAGE_JVM, "spark"))
120+
pyImage = testImageRef(sys.props.getOrElse(CONFIG_KEY_IMAGE_PYTHON, "spark-py"))
121+
rImage = testImageRef(sys.props.getOrElse(CONFIG_KEY_IMAGE_R, "spark-r"))
122122

123123
val scalaVersion = scala.util.Properties.versionNumberString
124124
.split("\\.")

resource-managers/kubernetes/integration-tests/src/test/scala/org/apache/spark/deploy/k8s/integrationtest/TestConstants.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ object TestConstants {
2626
val CONFIG_KEY_KUBE_MASTER_URL = "spark.kubernetes.test.master"
2727
val CONFIG_KEY_KUBE_NAMESPACE = "spark.kubernetes.test.namespace"
2828
val CONFIG_KEY_KUBE_SVC_ACCOUNT = "spark.kubernetes.test.serviceAccountName"
29+
val CONFIG_KEY_IMAGE_JVM = "spark.kubernetes.test.jvmImage"
30+
val CONFIG_KEY_IMAGE_PYTHON = "spark.kubernetes.test.pythonImage"
31+
val CONFIG_KEY_IMAGE_R = "spark.kubernetes.test.rImage"
2932
val CONFIG_KEY_IMAGE_TAG = "spark.kubernetes.test.imageTag"
3033
val CONFIG_KEY_IMAGE_TAG_FILE = "spark.kubernetes.test.imageTagFile"
3134
val CONFIG_KEY_IMAGE_REPO = "spark.kubernetes.test.imageRepo"

0 commit comments

Comments
 (0)