Spark test scenarios

This article collects practical test scenarios for validating Spark in the MLOps environment. It covers successful execution from S3, failure caused by missing cluster resources, notebook-based execution, failure caused by a missing JAR file on S3, failure caused by an incorrect or missing secret, and failure caused by an invalid Spark main class.

Overview

These scenarios are intended to verify both normal and failing Spark behavior in a controlled way.

They help confirm that:

  • Spark applications can run from a JAR file stored on S3.

  • Spark notebooks can read from and write to S3.

  • secret-based S3 access is configured correctly.

  • the environment reports missing resources clearly.

  • missing files on S3 are reported correctly.

  • configuration errors inside the Spark job are visible in the driver logs.

Important notes

The serviceAccount must be set to default-editor in these scenarios.

Also note that some scenarios use the secret name kfp-openstack-s3-creds. Before starting, verify which secret actually exists in your namespace:

kubectl get secret -n <namespace>

If kfp-openstack-s3-creds does not exist, but a different secret such as s3-creds is present, replace every occurrence of kfp-openstack-s3-creds in the manifests with that actual secret name.

Scenario 1. Successful execution of a Spark job from example.jar on S3

This scenario verifies that a Spark job can run successfully from a JAR file stored on S3.

Prerequisites

Before starting, make sure that:

  • a MLOps Studio notebook is running in the same namespace as the Spark Operator,

  • the kfp-openstack-s3-creds secret exists,

  • the file spark-jobs/example.jar exists in the kfp-s3 bucket.

  1. Open the MLOps Studio notebook in the correct namespace.

  2. Create a file named s3_app.yaml with the following content:

apiVersion: "sparkoperator.k8s.io/v1beta2"
kind: SparkApplication
metadata:
  name: s3-spark-job
  namespace: kubeflow-user-example-com
spec:
  type: Java
  mode: cluster
  image: "spark:3.5.7"
  mainApplicationFile: "s3a://kfp-s3/spark-jobs/example.jar"
  mainClass: "org.apache.spark.examples.SparkPi"
  hadoopConf:
    "fs.s3a.impl": "org.apache.hadoop.fs.s3a.S3AFileSystem"
    "fs.s3a.endpoint": "https://s3.waw4-1.cloudferro.com"
  sparkConf:
    "spark.driver.extraClassPath": "/opt/spark/custom-jars/*"
    "spark.executor.extraClassPath": "/opt/spark/custom-jars/*"
    "spark.hadoop.fs.s3a.impl": "org.apache.hadoop.fs.s3a.S3AFileSystem"
    "spark.driver.recoveryMode": "FILESYSTEM"
    "spark.driver.recoveryDirectory": "s3a://kfp-s3/spark-recovery"
  sparkUIOptions:
    serviceType: ClusterIP
    ingressAnnotations:
      kubernetes.io/ingress.class: istio
  volumes:
    - name: jar-volume
      emptyDir: {}
  restartPolicy:
    type: OnFailure
    onFailureRetries: 3
    onFailureRetryInterval: 15
  driver:
    cores: 1
    serviceAccount: default-editor
    memory: "512m"
    initContainers:
      - name: download-jars
        image: curlimages/curl
        command: ["/bin/sh", "-c"]
        args:
          - |
            curl -L -o /data/hadoop-aws-3.3.4.jar https://repo1.maven.org/maven2/org/apache/hadoop/hadoop-aws/3.3.4/hadoop-aws-3.3.4.jar;
            curl -L -o /data/aws-java-sdk-bundle-1.12.696.jar https://repo1.maven.org/maven2/com/amazonaws/aws-java-sdk-bundle/1.12.696/aws-java-sdk-bundle-1.12.696.jar;
        volumeMounts:
          - name: jar-volume
            mountPath: /data
    volumeMounts:
      - name: jar-volume
        mountPath: /opt/spark/custom-jars
    env:
      - name: AWS_ACCESS_KEY_ID
        valueFrom:
          secretKeyRef:
            name: kfp-openstack-s3-creds
            key: accesskey
      - name: AWS_SECRET_ACCESS_KEY
        valueFrom:
          secretKeyRef:
            name: kfp-openstack-s3-creds
            key: secretkey

  executor:
    instances: 1
    cores: 1
    memory: "512m"
    deps:
    initContainers:
      - name: download-jars
        image: curlimages/curl
        command: ["/bin/sh", "-c"]
        args:
          - |
            curl -L -o /data/hadoop-aws-3.3.4.jar https://repo1.maven.org/maven2/org/apache/hadoop/hadoop-aws/3.3.4/hadoop-aws-3.3.4.jar;
            curl -L -o /data/aws-java-sdk-bundle-1.12.696.jar https://repo1.maven.org/maven2/com/amazonaws/aws-java-sdk-bundle/1.12.696/aws-java-sdk-bundle-1.12.696.jar;
        volumeMounts:
          - name: jar-volume
            mountPath: /data
    volumeMounts:
      - name: jar-volume
        mountPath: /opt/spark/custom-jars
    env:
      - name: AWS_ACCESS_KEY_ID
        valueFrom:
          secretKeyRef:
            name: kfp-openstack-s3-creds
            key: accesskey
      - name: AWS_SECRET_ACCESS_KEY
        valueFrom:
          secretKeyRef:
            name: kfp-openstack-s3-creds
            key: secretkey
  1. In a new notebook cell, apply the manifest:

kubectl apply -f s3_app.yaml
  1. Because the YAML sets the namespace to kubeflow-user-example-com, check the application in that namespace:

kubectl get sparkapplications -n kubeflow-user-example-com
  1. Retrieve the list of pods and identify the driver pod:

kubectl get pods -n kubeflow-user-example-com
  1. Once the application finishes, retrieve the driver logs:

kubectl logs <driver-pod-name> -n <namespace-name>

Expected result

The expected result is:

  • kubectl get sparkapplications s3-spark-job shows the state as COMPLETED.

  • The driver pod has Completed status.

  • The driver logs show SparkPi output similar to:

Pi is roughly 3.14

Scenario 2. Resource constraints prevent Spark job execution

This scenario verifies the behavior when the cluster does not have enough CPU resources to schedule the Spark driver pod.

Prerequisites

Before starting, make sure that:

  • SparkOperator is running in the cluster,

  • the kfp-openstack-s3-creds secret exists,

  • the cluster currently lacks sufficient CPU resources,

  • the cluster is not scaled up and no resources are expected to be freed during the test.

  1. Open a terminal or notebook in the same cluster context.

  2. Create an s3_app.yaml file using the same SparkApplication manifest as in the successful scenario.

  3. Apply the manifest:

kubectl apply -f s3_app.yaml
  1. Check the SparkApplication status:

kubectl get sparkapplication s3-spark-job
  1. Verify that the application remains in SUBMITTED state for an extended time.

  2. Check the driver pod:

kubectl get pod s3-spark-job-driver -n default
  1. Describe the driver pod:

kubectl describe pod s3-spark-job-driver -n default
  1. Inspect the Events section for a scheduling error such as:

Warning  FailedScheduling   59s (x577 over 47h)  default-scheduler  0/11 nodes are available: 1 node(s) had untolerated taint {node-role.kubernetes.io/control-plane: }, 10 Insufficient cpu. preemption: 0/11 nodes are available: 1 Preemption is not helpful for scheduling, 10 No preemption victims found for incoming pod.
  1. Optionally delete the SparkApplication after the test:

kubectl delete sparkapplication s3-spark-job -n default

Expected result

The expected result is:

  • kubectl get sparkapplication s3-spark-job shows SUBMITTED.

  • The driver pod remains in Pending state.

  • kubectl describe pod shows a FailedScheduling event.

  • The event indicates that the control-plane node is tainted and the remaining nodes have insufficient CPU.

Scenario 3. Spark works correctly when launched from a notebook

This scenario verifies Spark execution from a notebook by using the Spark Operator (Python) kernel.

Prerequisites

Before starting, make sure that you have a .ipynb file containing the required S3 access credentials.

  1. Create a new notebook and select the Jupyter Enterprise Gateway option.

  2. Open the notebook and upload the .ipynb file.

  3. Set the kernel to Spark Operator (Python).

  4. Execute the notebook code.

Expected result

The expected result is:

  • the notebook code finishes successfully,

  • the part files and the _SUCCESS file are written to S3,

  • the S3 bucket contains the _SUCCESS file and two part-XXX files.

Scenario 4. Missing example.jar on S3 prevents Spark job execution

This scenario verifies that the Spark job fails clearly when the configured JAR file is missing from S3.

Prerequisites

Before starting, make sure that:

  • a MLOps Studio notebook is running in the correct namespace,

  • the kfp-openstack-s3-creds secret exists,

  • the kfp-s3 bucket exists,

  • but the object spark-jobs/example.jar is missing.

  1. Open the MLOps Studio notebook in the correct namespace.

  2. Create an s3_app.yaml file using the same manifest as in the successful scenario.

  3. Apply the file:

kubectl apply -f s3_app.yaml
  1. Check the SparkApplication status:

kubectl get sparkapplications s3-spark-job -n kubeflow-user-example-com
  1. Observe the state transition, for example SUBMITTED to FAILED.

  2. List the pods:

kubectl get pods -n kubeflow-user-example-com
  1. Retrieve the driver logs after the application reaches a terminal state:

kubectl logs <driver-pod-name> -n kubeflow-user-example-com
  1. Verify in S3 that no output files were created for the job.

Expected result

The expected result is:

  • the SparkApplication ends in FAILED state,

  • the driver pod shows Error or exits with a non-zero code,

  • the driver logs contain an error indicating that s3a://kfp-s3/spark-jobs/example.jar could not be found,

  • the logs may show FileNotFoundException, NoSuchKey, 404, or a similar message,

  • no _SUCCESS or part-… files appear in S3.

Scenario 5. Missing or incorrect S3 secret prevents job execution

This scenario verifies that a missing or misspelled secret name prevents the Spark job from starting.

Prerequisites

Before starting, make sure that:

  • SparkOperator is running,

  • the secret kfp-openstack-s3-creds-broken does not exist.

  1. Create a file named s3_app_bad_secret.yaml based on the successful scenario, but modify the executor secret name so that it points to a non-existent secret:

apiVersion: "sparkoperator.k8s.io/v1beta2"
kind: SparkApplication
metadata:
  name: s3-spark-job
  namespace: kubeflow-user-example-com
spec:
  type: Java
  mode: cluster
  image: "spark:3.5.7"
  mainApplicationFile: "s3a://kfp-s3/spark-jobs/example.jar"
  mainClass: "org.apache.spark.examples.SparkPi"
  hadoopConf:
    "fs.s3a.impl": "org.apache.hadoop.fs.s3a.S3AFileSystem"
    "fs.s3a.endpoint": "https://s3.waw4-1.cloudferro.com"
  sparkConf:
    "spark.driver.extraClassPath": "/opt/spark/custom-jars/*"
    "spark.executor.extraClassPath": "/opt/spark/custom-jars/*"
    "spark.hadoop.fs.s3a.impl": "org.apache.hadoop.fs.s3a.S3AFileSystem"
    "spark.driver.recoveryMode": "FILESYSTEM"
    "spark.driver.recoveryDirectory": "s3a://kfp-s3/spark-recovery"
  sparkUIOptions:
    serviceType: ClusterIP
    ingressAnnotations:
      kubernetes.io/ingress.class: istio
  volumes:
    - name: jar-volume
      emptyDir: {}
  restartPolicy:
    type: OnFailure
    onFailureRetries: 3
    onFailureRetryInterval: 15
  driver:
    cores: 1
    serviceAccount: default-editor
    memory: "512m"
    initContainers:
      - name: download-jars
        image: curlimages/curl
        command: ["/bin/sh", "-c"]
        args:
          - |
            curl -L -o /data/hadoop-aws-3.3.4.jar https://repo1.maven.org/maven2/org/apache/hadoop/hadoop-aws/3.3.4/hadoop-aws-3.3.4.jar;
            curl -L -o /data/aws-java-sdk-bundle-1.12.696.jar https://repo1.maven.org/maven2/com/amazonaws/aws-java-sdk-bundle/1.12.696/aws-java-sdk-bundle-1.12.696.jar;
        volumeMounts:
          - name: jar-volume
            mountPath: /data
    volumeMounts:
      - name: jar-volume
        mountPath: /opt/spark/custom-jars
    env:
      - name: AWS_ACCESS_KEY_ID
        valueFrom:
          secretKeyRef:
            name: kfp-openstack-s3-creds
            key: accesskey
      - name: AWS_SECRET_ACCESS_KEY
        valueFrom:
          secretKeyRef:
            name: kfp-openstack-s3-creds
            key: secretkey

  executor:
    instances: 1
    cores: 1
    memory: "512m"
    deps:
    initContainers:
      - name: download-jars
        image: curlimages/curl
        command: ["/bin/sh", "-c"]
        args:
          - |
            curl -L -o /data/hadoop-aws-3.3.4.jar https://repo1.maven.org/maven2/org/apache/hadoop/hadoop-aws/3.3.4/hadoop-aws-3.3.4.jar;
            curl -L -o /data/aws-java-sdk-bundle-1.12.696.jar https://repo1.maven.org/maven2/com/amazonaws/aws-java-sdk-bundle/1.12.696/aws-java-sdk-bundle-1.12.696.jar;
        volumeMounts:
          - name: jar-volume
            mountPath: /data
    volumeMounts:
      - name: jar-volume
        mountPath: /opt/spark/custom-jars
    env:
      - name: AWS_ACCESS_KEY_ID
        valueFrom:
          secretKeyRef:
            name: kfp-openstack-s3-creds-broken
            key: accesskey
      - name: AWS_SECRET_ACCESS_KEY
        valueFrom:
          secretKeyRef:
            name: kfp-openstack-s3-creds-broken
            key: secretkey
  1. Apply the manifest:

kubectl apply -f s3_app_bad_secret.yaml
  1. Check the SparkApplication status:

kubectl get sparkapplications s3-spark-job -n kubeflow-user-example-com
  1. Check the driver pod and describe it:

kubectl get pods -n kubeflow-user-example-com
kubectl describe pod <driver-pod-name> -n kubeflow-user-example-com

Expected result

The expected result is:

  • kubectl describe pod shows CreateContainerConfigError or another startup error,

  • the SparkApplication transitions to FAILED,

  • the job does not start,

  • the error clearly points to a missing or incorrect secret reference.

Scenario 6. Spark job error caused by a non-existent main class

This scenario verifies that a Spark job failure caused by an incorrect mainClass setting is reported clearly.

Prerequisites

Before starting, make sure that:

  • SparkOperator is functioning correctly,

  • the kfp-openstack-s3-creds secret is valid,

  • example.jar exists at s3a://kfp-s3/spark-jobs/example.jar,

  • but you intentionally set an invalid main class.

  1. Create an s3_app_bad_main.yaml file based on the successful scenario, but change only:

mainClass: "org.apache.spark.examples.SparkPiXXX"
  1. Apply the manifest:

kubectl apply -f s3_app_bad_main.yaml
  1. Check the application status:

kubectl get sparkapplications s3-spark-job -n kubeflow-user-example-com
  1. Once the application reaches a terminal state, retrieve the driver logs:

kubectl logs <driver-pod-name> -n kubeflow-user-example-com

Expected result

The expected result is:

  • the SparkApplication transitions to FAILED,

  • the driver pod shows Error,

  • the driver logs contain a clear message such as:

Error: Failed to load class org.apache.spark.examples.SparkPiXXX.
  • no _SUCCESS or part-… output files appear on S3.

What to do next

After running these Spark scenarios, the next useful topics are:

  • validating namespace placement for SparkApplication resources,

  • checking whether the correct secret name is used in all driver and executor sections,

  • verifying Driver Web UI access,

  • documenting successful and failing runs with screenshots and log excerpts,

  • building reusable Spark manifests for both notebook-based and SparkApplication-based workflows.