#3178 Install the dependencies in the default venv in the spark base image
Pull request opened by
pingsutw
## Tracking issue
NA
## Why are the changes needed?
The default builder creates another Python venv in the image. The driver is using the venv (python3.11) that was created from the default builder, and the worker is using the default venv (python3.9) in the base image
## What changes were proposed in this pull request?
Always install the dependencies in the default venv in the spark base image.
## How was this patch tested?
from operator import add
import flytekit
from flytekit import ImageSpec, Resources, task, workflow, dynamic
from flytekitplugins.spark import Spark
from utils import f
container_image = ImageSpec(
# name="inrix_onboarding",
registry="pingsutw",
packages=["flytekitplugins-spark==1.15.1b0", "numpy"],
builder="default",
)
@task(
task_config=Spark(
# This configuration is applied to the Spark cluster
spark_conf={
"spark.driver.memory": "1000M",
"spark.executor.memory": "2000M",
"spark.executor.cores": "1",
"spark.executor.instances": "5",
"spark.driver.cores": "2",
},
executor_path="/usr/bin/python3",
applications_path="local:///usr/local/bin/entrypoint.py",
),
# requests=Resources(cpu="2", mem="3000Mi"),
# limits=Resources(cpu="3", mem="5000Mi"),
container_image=container_image,
)
def hello_spark(partitions: int) -> float:
print("Starting Spark with Partitions:! {}".format(partitions))
n = 1 * partitions
sess = flytekit.current_context().spark_session
count = (
sess.sparkContext.parallelize(range(1, n + 1), partitions).map(f).reduce(add)
)
print("Im done")
pi_val = 4.0 * count / n
return pi_val
@task(container_image=container_image)
def print_every_time(value_to_print: float):
print("My printed value: {}".format(value_to_print))
@workflow
def wf(partitions: int = 10000) -> float:
pi = hello_spark(partitions=partitions)
print_every_time(value_to_print=pi)
return pi
### Summary by Bito
This PR refactors the image builder implementation across the codebase, introducing a builder_type attribute and registry method. It updates the Spark task module by fixing deprecated logging methods and ensuring proper container image references. The changes align with broader refactoring efforts and improve code clarity through enhanced comments about builder priority, while installing dependencies in the default virtual environment within the spark base image.
Unit tests added: True
Estimated effort to review (1-5, lower is better): 1
flyteorg/flytekit