cuddly-jelly-27016
03/13/2025, 9:51 PMtest_spark_driver_executor_podSpec
2. Modified the @task for hello_spark function in my_spark example here as follow to set the driver_pod and executor_pod.
custom_image = ImageSpec(
python_version="3.9",
registry="ghcr.io/machichima",
packages=["flytekitplugins-spark"],
)
driver_pod = PodTemplate(
labels={"lKeyA_d": "lValA", "lKeyB_d": "lValB"},
annotations={"aKeyA_d": "aValA", "aKeyB_d": "aValB"},
primary_container_name="driver-primary",
pod_spec=V1PodSpec(
containers=[
V1Container(
name="driver-primary",
image="ghcr.io/machichima",
command=["echo"],
args=["wow"],
env=[V1EnvVar(name="x/custom-driver", value="driver")],
),
V1Container(
name="driver-primary",
image="ghcr.io/machichima",
command=["echo"],
args=["wow"],
# resources=V1ResourceRequirements(requests={"memory": "1000M"}),
env=[V1EnvVar(name="x/custom-driver-1", value="driver-1")],
),
V1Container(
name="not-primary",
command=["echo"],
args=["not_primary"],
),
],
tolerations=[
V1Toleration(
key="x/custom-driver",
operator="Equal",
value="foo-driver",
effect="NoSchedule",
),
],
),
)
executor_pod = PodTemplate(
labels={"lKeyA_e": "lValA", "lKeyB_e": "lValB"},
annotations={"aKeyA_e": "aValA", "aKeyB_e": "aValB"},
primary_container_name="executor-primary",
pod_spec=V1PodSpec(
containers=[
V1Container(
name="executor-primary",
image="ghcr.io/machichima",
command=["echo"],
args=["wow"],
env=[V1EnvVar(name="x/custom-executor", value="executor")],
),
V1Container(
name="not-primary",
command=["echo"],
args=["not_primary"],
),
],
tolerations=[
V1Toleration(
key="x/custom-executor",
operator="Equal",
value="foo-executor",
effect="NoSchedule",
),
],
),
)
@task(
cache_version="0.1.0",
task_config=Spark(
# This configuration is applied to the Spark cluster
spark_conf={
"spark.executor.cores": "1",
"spark.executor.instances": "2",
"spark.driver.cores": "1",
"spark.jars": "https://storage.googleapis.com/hadoop-lib/gcs/gcs-connector-hadoop3-latest.jar",
},
driver_pod=driver_pod,
executor_pod=executor_pod,
),
# limits=Resources(cpu="50m", mem="2000M"),
container_image=custom_image,
pod_template=PodTemplate(
labels={"lKeyA": "lValA", "lKeyB": "lValB"},
annotations={"aKeyA": "aValA", "aKeyB": "aValB"},
pod_spec=V1PodSpec(
containers=[
V1Container(
name="primary",
image=custom_image,
command="echo",
args=["wow"],
),
],
tolerations=[
V1Toleration(
key="x/custom",
operator="Equal",
value="foo",
effect="NoSchedule",
),
],
),
),
)
Verify the pods have Tolerations and EnvVar set.
❯ kubectl describe sparkapplications.sparkoperator.k8s.io -n flytesnacks-development acjqns8twhn6sg5l6dnj-n0-0 | grep "Tolerations:" -A 8
Tolerations:
Effect: NoSchedule
Key: x/custom
Operator: Equal
Value: foo
Effect: NoSchedule
Key: x/custom-driver
Operator: Equal
Value: foo-driver
--
Tolerations:
Effect: NoSchedule
Key: x/custom
Operator: Equal
Value: foo
Effect: NoSchedule
Key: x/custom-executor
Operator: Equal
Value: foo-executor
❯ kubectl describe sparkapplications.sparkoperator.k8s.io -n flytesnacks-development acjqns8twhn6sg5l6dnj-n0-0 | grep "Name: x/custom-driver" -A 1
Name: x/custom-driver
Value: driver
❯ kubectl describe sparkapplications.sparkoperator.k8s.io -n flytesnacks-development acjqns8twhn6sg5l6dnj-n0-0 | grep "Name: x/custom-executor" -A 1
Name: x/custom-executor
Value: executor
### Setup process
### Screenshots
## Check all the applicable boxes
• I updated the documentation accordingly.
• All new and existing tests passed.
• All commits are signed-off.
## Related PRs
flyteorg/flyte#6085
## Docs link
### Summary by Bito
Enhanced flytekit-spark package by implementing configurable driver and executor pod support through PodTemplate. Added driver_pod and executor_pod fields to SparkJob model with primary_only flag for pod spec serialization. The implementation includes type hint updates from K8sPod to PodTemplate, parameter order modifications, and improved SparkSession cleanup in tests. This enables granular control and customization of labels, annotations, containers, and tolerations for both driver and executor pods.
Unit tests added: True
Estimated effort to review (1-5, lower is better): 2
flyteorg/flytekitcuddly-jelly-27016
03/13/2025, 9:51 PM