-
Notifications
You must be signed in to change notification settings - Fork 340
[FEAT] add driver/executor pod in Spark #3016
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8cc081d
7793398
b21d1e3
00d0c3a
1b7c1c9
32f6aa9
167a390
9bdae27
8c826c0
d6b752b
900113f
68bef7d
5a12025
30cff7c
e17ee57
7f4e00b
2541e26
110febe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,9 +10,11 @@ | |
| from flytekit import FlyteContextManager, PythonFunctionTask, lazy_module, logger | ||
| from flytekit.configuration import DefaultImages, SerializationSettings | ||
| from flytekit.core.context_manager import ExecutionParameters | ||
| from flytekit.core.pod_template import PRIMARY_CONTAINER_DEFAULT_NAME, PodTemplate | ||
| from flytekit.extend import ExecutionState, TaskPlugins | ||
| from flytekit.extend.backend.base_agent import AsyncAgentExecutorMixin | ||
| from flytekit.image_spec import DefaultImageBuilder, ImageSpec | ||
| from flytekit.models.task import K8sPod | ||
|
|
||
| from .models import SparkJob, SparkType | ||
|
|
||
|
|
@@ -26,17 +28,21 @@ class Spark(object): | |
| Use this to configure a SparkContext for a your task. Task's marked with this will automatically execute | ||
| natively onto K8s as a distributed execution of spark | ||
|
|
||
| Args: | ||
| spark_conf: Dictionary of spark config. The variables should match what spark expects | ||
| hadoop_conf: Dictionary of hadoop conf. The variables should match a typical hadoop configuration for spark | ||
| executor_path: Python binary executable to use for PySpark in driver and executor. | ||
| applications_path: MainFile is the path to a bundled JAR, Python, or R file of the application to execute. | ||
| Attributes: | ||
| spark_conf (Optional[Dict[str, str]]): Spark configuration dictionary. | ||
| hadoop_conf (Optional[Dict[str, str]]): Hadoop configuration dictionary. | ||
| executor_path (Optional[str]): Path to the Python binary for PySpark execution. | ||
| applications_path (Optional[str]): Path to the main application file. | ||
| driver_pod (Optional[PodTemplate]): The pod template for the Spark driver pod. | ||
| executor_pod (Optional[PodTemplate]): The pod template for the Spark executor pod. | ||
| """ | ||
|
|
||
| spark_conf: Optional[Dict[str, str]] = None | ||
| hadoop_conf: Optional[Dict[str, str]] = None | ||
| executor_path: Optional[str] = None | ||
| applications_path: Optional[str] = None | ||
| driver_pod: Optional[PodTemplate] = None | ||
| executor_pod: Optional[PodTemplate] = None | ||
|
|
||
| def __post_init__(self): | ||
| if self.spark_conf is None: | ||
|
|
@@ -172,6 +178,8 @@ def get_custom(self, settings: SerializationSettings) -> Dict[str, Any]: | |
| executor_path=self._default_executor_path or settings.python_interpreter, | ||
| main_class="", | ||
| spark_type=SparkType.PYTHON, | ||
| driver_pod=self.to_k8s_pod(self.task_config.driver_pod), | ||
| executor_pod=self.to_k8s_pod(self.task_config.executor_pod), | ||
| ) | ||
| if isinstance(self.task_config, (Databricks, DatabricksV2)): | ||
| cfg = cast(DatabricksV2, self.task_config) | ||
|
|
@@ -180,6 +188,27 @@ def get_custom(self, settings: SerializationSettings) -> Dict[str, Any]: | |
|
|
||
| return MessageToDict(job.to_flyte_idl()) | ||
|
|
||
| def to_k8s_pod(self, pod_template: Optional[PodTemplate] = None) -> Optional[K8sPod]: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can use this function instead?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I use this function because we need to also check if the primary container name set in driver/executor is the same as in task, if not, a warning should be raised. This function use |
||
| """ | ||
| Convert the podTemplate to K8sPod | ||
| """ | ||
| if pod_template is None: | ||
| return None | ||
|
|
||
| task_primary_container_name = ( | ||
| self.pod_template.primary_container_name if self.pod_template else PRIMARY_CONTAINER_DEFAULT_NAME | ||
| ) | ||
|
|
||
| if pod_template.primary_container_name != task_primary_container_name: | ||
| logger.warning( | ||
| "Primary container name ('%s') set in spark differs from the one in @task ('%s'). " | ||
| "The primary container name in @task will be overridden.", | ||
| pod_template.primary_container_name, | ||
| task_primary_container_name, | ||
| ) | ||
|
|
||
| return K8sPod.from_pod_template(pod_template) | ||
|
|
||
| def pre_execute(self, user_params: ExecutionParameters) -> ExecutionParameters: | ||
| import pyspark as _pyspark | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.