Skip to content

Latest commit

 

History

History
438 lines (349 loc) · 18 KB

README.md

File metadata and controls

438 lines (349 loc) · 18 KB
layout global
title Spark on Kubernetes Integration Tests

Running the Kubernetes Integration Tests

The simplest way to run the integration tests is to install and run Minikube, then run the following from this directory:

./dev/dev-run-integration-tests.sh

To run tests with a specific Java version instead of Java 25, use --java-image-tag to specify the base image accordingly.

./dev/dev-run-integration-tests.sh --java-image-tag 21-jre

To run tests with a custom docker image, use --docker-file to specify the Dockerfile. Note that if both --docker-file and --java-image-tag are used, --docker-file is preferred, and the custom Dockerfile need to include a Java installation by itself.

./dev/dev-run-integration-tests.sh --docker-file ../docker/src/main/dockerfiles/spark/Dockerfile

The minimum tested version of Minikube is 1.38.0. The kube-dns addon must be enabled. Minikube should run with a minimum of 4 CPUs and 6G of memory:

minikube start --cpus 4 --memory 6144

You can download Minikube here.

Integration test customization

Configuration of the integration test runtime is done through passing different arguments to the test script. The main useful options are outlined below.

Using a different backend

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

minikube

Uses the local minikube cluster, this requires that minikube 1.38.0 or greater be installed and that it be allocated at least 4 CPUs and 6GB memory (some users have reported success with as few as 3 CPUs and 4GB memory). The tests will check if minikube is started and abort early if it isn't currently running.

rancher-desktop

Rancher Desktop is an open-source (Apache 2.0 license) project that brings Kubernetes and container management to the desktop. It runs on Windows, macOS and Linux. The rancher-desktop backend configures the tests to use it.

docker-desktop

Since July 2018 Docker for Desktop provide an optional Kubernetes cluster that can be enabled as described in this blog post. Assuming this is enabled using this backend will auto-configure itself from the docker-desktop context that Docker creates in your ~/.kube/config file. If your config file is in a different location you should set the KUBECONFIG environment variable appropriately.

cloud

The cloud backend configures the tests to use an arbitrary Kubernetes cluster running in the cloud or otherwise.

The cloud backend auto-configures the cluster to use from your K8S config file, this is assumed to be ~/.kube/config unless the KUBECONFIG environment variable is set to override this location. By default this will use whatever your current context is in the config file, to use an alternative context from your config file you can specify the --context <context> flag with the desired context.

You can optionally use a different K8S master URL than the one your K8S config file specified, this should be supplied via the --spark-master <master-url> flag.

Re-using Docker Images

By default, the test framework will build new Docker images on every test execution. A unique image tag is generated, and it is written to file at target/imageTag.txt. To reuse the images built in a previous run, or to use a Docker image tag that you have built by other means already, pass the tag to the test script:

./dev/dev-run-integration-tests.sh --image-tag <tag>

where if you still want to use images that were built before by the test framework:

./dev/dev-run-integration-tests.sh --image-tag $(cat target/imageTag.txt)

The Docker image repository is customised via the --image-repo <repo> flag, this is the repository that contains the images when a specific image tag is set, or to which freshly built images are pushed. The default is docker.io/kubespark.

Customising the Image Names

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.

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.

./dev/dev-run-integration-tests.sh --base-image-name apache-spark

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.

./dev/dev-run-integration-tests.sh --jvm-image-name jvm-spark --python-image-name pyspark --r-image-name sparkr

Spark Distribution Under Test

By default, when neither --spark-tgz nor --image-tag is specified, the Docker images are built directly from the current source tree, so no extra option is needed.

Alternatively, the Spark code to test can be handed to the integration test system via a tarball:

  • --spark-tgz <path-to-tgz> - set <path-to-tgz> to point to a tarball containing the Spark distribution to test.

This Tarball should be created by first running dev/make-distribution.sh passing the --tgz flag and -Pkubernetes as one of the options to ensure that Kubernetes support is included in the distribution. For more details on building a runnable distribution please see the Building Spark documentation.

Customizing the Namespace and Service Account

If no namespace is specified then a temporary namespace will be created and deleted during the test run. Similarly if no service account is specified then the default service account for the namespace will be used.

Using the --namespace <namespace> flag sets <namespace> to the namespace in which the tests should be run. If this is supplied then the tests assume this namespace exists in the K8S cluster and will not attempt to create it.
Additionally this namespace must have an appropriately authorized service account which can be customised via the --service-account flag.

The --service-account <service account name> flag sets <service account name> to the name of the Kubernetes service account to use in the namespace specified by the --namespace flag. The service account is expected to have permissions to get, list, watch, and create pods. For clusters with RBAC turned on, it's important that the right permissions are granted to the service account in the namespace through an appropriate role and role binding. A reference RBAC configuration is provided in dev/spark-rbac.yaml.

Selecting the Tests to Run

The tests are tagged, and the set of tests to run can be controlled via the following flags:

  • --include-tags <tags> - comma separated list of tags to include in addition to the always included k8s tag.
  • --exclude-tags <tags> - comma separated list of tags to exclude.
  • --default-exclude-tags <tags> - overrides the default list of excluded tags, which is org.apache.spark.deploy.k8s.integrationtest.YuniKornTag. Pass an empty string to clear the default exclusions, e.g. to run the YuniKorn tests.

Customising the Build

  • --java-version <version> - Java version to build Spark and the tests with. The default is 21.
  • --hadoop-profile <profile> - Hadoop Maven profile to build with. The default is hadoop-3.
  • --skip-building-dependencies - skip rebuilding the modules the integration tests depend on (drops Maven's -am flag). Useful for iterating when the current tree is already built.

Running the Test Directly

If you prefer to run just the integration tests directly, then you can customise the behaviour via passing system properties to Maven. For example:

mvn integration-test -am -pl :spark-kubernetes-integration-tests_2.13 \
                        -Pkubernetes -Pkubernetes-integration-tests \
                        -Phadoop-3 -Dhadoop.version=3.5.0 \
                        -Dspark.kubernetes.test.sparkTgz=spark-5.0.0-SNAPSHOT-bin-example.tgz \
                        -Dspark.kubernetes.test.imageTag=sometag \
                        -Dspark.kubernetes.test.imageRepo=docker.io/somerepo \
                        -Dspark.kubernetes.test.namespace=spark-int-tests \
                        -Dspark.kubernetes.test.deployMode=docker-desktop \
                        -Dtest.include.tags=k8s

Available Maven Properties

The following are the available Maven properties that can be passed. For the most part these correspond to flags passed to the wrapper scripts and using the wrapper scripts will simply set these appropriately behind the scenes.

Property Description Default
spark.kubernetes.test.sparkTgz A runnable Spark distribution to test.
spark.kubernetes.test.unpackSparkDir The directory where the runnable Spark distribution will be unpacked. ${project.build.directory}/spark-dist-unpacked
spark.kubernetes.test.deployMode The integration test backend to use. Acceptable values are minikube, docker-desktop, rancher-desktop and cloud. minikube
spark.kubernetes.test.kubeConfigContext When using the cloud backend specifies the context from the users K8S config file that should be used as the target cluster for integration testing. If not set and using the cloud backend then your current context will be used.
spark.kubernetes.test.master When using the cloud backend must be specified to indicate the K8S master URL to communicate with.
spark.kubernetes.test.imageTag A specific image tag to use, when set assumes images with those tags are already built and available in the specified image repository. When set to N/A (the default) fresh images will be built. N/A
spark.kubernetes.test.javaImageTag A specific Eclipse Temurin OpenJDK base image tag to use, when set uses it instead of 25. N/A
spark.kubernetes.test.imageTagFile A file containing the image tag to use, if no specific image tag is set then fresh images will be built with a generated tag and that tag written to this file. ${project.build.directory}/imageTag.txt
spark.kubernetes.test.imageRepo The Docker image repository that contains the images to be used if a specific image tag is set or to which the images will be pushed to if fresh images are being built. docker.io/kubespark
spark.kubernetes.test.jvmImage The image name for the JVM based Spark image to test spark
spark.kubernetes.test.pythonImage The image name for the Python based Spark image to test spark-py
spark.kubernetes.test.rImage The image name for the R based Spark image to test spark-r
spark.kubernetes.test.dockerFile The path to the custom Dockerfile Dockerfile
spark.kubernetes.test.namespace A specific Kubernetes namespace to run the tests in. If specified then the tests assume that this namespace already exists. When not specified a temporary namespace for the tests will be created and deleted as part of the test run.
spark.kubernetes.test.serviceAccountName A specific Kubernetes service account to use for running the tests. If not specified then the namespaces default service account will be used and that must have sufficient permissions or the tests will fail.
spark.kubernetes.test.driverRequestCores Set cpu resource for each driver pod in test, this is currently only for test on cpu resource limited cluster, it's not recommended for other scenarios.
spark.kubernetes.test.executorRequestCores Set cpu resource for each executor pod in test, this is currently only for test on cpu resource limited cluster, it's not recommended for other scenarios.
spark.kubernetes.test.volcanoMaxConcurrencyJobNum Set maximum number for concurrency jobs, It helps developers setting suitable resources according to test env in volcano test.
test.include.tags Comma separated list of test tags to include, e.g. k8s, minikube, local, r, volcano.
test.exclude.tags Comma separated list of test tags to exclude.
test.default.exclude.tags The default list of excluded test tags. Set to an empty string to clear the default exclusions, e.g. to run the YuniKorn tests. org.apache.spark.deploy.k8s.integrationtest.YuniKornTag

Running the Kubernetes Integration Tests with SBT

You can use SBT in the same way to build image and run all K8s integration tests except Minikube-only ones.

build/sbt -Psparkr -Pkubernetes -Pkubernetes-integration-tests \
    -Dtest.exclude.tags=minikube \
    -Dspark.kubernetes.test.deployMode=docker-desktop \
    -Dspark.kubernetes.test.imageTag=2027-01-01 \
    'kubernetes-integration-tests/test'

The following is an example to rerun tests with the pre-built image.

build/sbt -Psparkr -Pkubernetes -Pkubernetes-integration-tests \
    -Dtest.exclude.tags=minikube \
    -Dspark.kubernetes.test.deployMode=docker-desktop \
    -Dspark.kubernetes.test.imageTag=2027-01-01 \
    'kubernetes-integration-tests/runIts'

In addition, you can run a single test selectively.

build/sbt -Psparkr -Pkubernetes -Pkubernetes-integration-tests \
    -Dspark.kubernetes.test.deployMode=docker-desktop \
    -Dspark.kubernetes.test.imageTag=2027-01-01 \
    'kubernetes-integration-tests/testOnly -- -z "Run SparkPi with a very long application name"'

You can also specify your specific dockerfile to build JVM/Python/R based image to test.

build/sbt -Psparkr -Pkubernetes -Pkubernetes-integration-tests \
    -Dtest.exclude.tags=minikube \
    -Dspark.kubernetes.test.deployMode=docker-desktop \
    -Dspark.kubernetes.test.imageTag=2027-01-01 \
    -Dspark.kubernetes.test.dockerFile=/path/to/Dockerfile \
    -Dspark.kubernetes.test.pyDockerFile=/path/to/py/Dockerfile \
    -Dspark.kubernetes.test.rDockerFile=/path/to/r/Dockerfile \
    'kubernetes-integration-tests/test'

Running the Volcano Integration Tests

Requirements

  • A minimum of 6 CPUs and 9G of memory is required to complete all Volcano test cases.
  • Volcano v1.14.2.

Installation

kubectl apply -f https://raw.githubusercontent.com/volcano-sh/volcano/v1.14.2/installer/volcano-development.yaml

Run tests

You can specify -Pvolcano to enable volcano module to run all Kubernetes and Volcano tests

build/sbt -Pvolcano -Pkubernetes -Pkubernetes-integration-tests \
    -Dtest.exclude.tags=minikube \
    -Dspark.kubernetes.test.deployMode=docker-desktop \
    'kubernetes-integration-tests/test'

You can also specify volcano tag to only run Volcano test:

build/sbt -Pvolcano -Pkubernetes -Pkubernetes-integration-tests \
    -Dtest.include.tags=volcano \
    -Dtest.exclude.tags=minikube \
    -Dspark.kubernetes.test.deployMode=docker-desktop \
    'kubernetes-integration-tests/test'

Cleanup Volcano

kubectl delete -f https://raw.githubusercontent.com/volcano-sh/volcano/v1.14.2/installer/volcano-development.yaml

Running the YuniKorn Integration Tests

YuniKornSuite runs the Kubernetes integration tests with the Apache YuniKorn scheduler instead of the default scheduler. The suite is tagged with YuniKornTag which is excluded by default via test.default.exclude.tags.

Requirements

  • Apache YuniKorn 1.9.0.

Installation

helm repo add yunikorn https://apache.github.io/yunikorn-release
helm repo update
helm install yunikorn yunikorn/yunikorn --namespace yunikorn --version 1.9.0 \
    --create-namespace --set embedAdmissionController=false

Run tests

Clear the default excluded tags to enable the YuniKorn tests:

build/sbt -Pkubernetes -Pkubernetes-integration-tests \
    -Dtest.exclude.tags=minikube \
    -Dtest.default.exclude.tags= \
    -Dspark.kubernetes.test.deployMode=docker-desktop \
    'kubernetes-integration-tests/testOnly *YuniKornSuite'

Cleanup YuniKorn

helm uninstall yunikorn --namespace yunikorn