nevcohen commented on code in PR #42427:
URL: https://github.com/apache/airflow/pull/42427#discussion_r1773685956
##########
tests/providers/cncf/kubernetes/operators/test_spark_kubernetes.py:
##########
@@ -273,6 +273,100 @@ def test_create_application_from_yaml_json(
version="v1beta2",
)
+ def test_create_application_from_yaml_json_and_use_name_from_metadata(
+ self,
+ mock_create_namespaced_crd,
+ mock_get_namespaced_custom_object_status,
+ mock_cleanup,
+ mock_create_job_name,
+ mock_get_kube_client,
+ mock_create_pod,
+ mock_await_pod_start,
+ mock_await_pod_completion,
+ mock_fetch_requested_container_logs,
+ data_file,
+ ):
+ op = SparkKubernetesOperator(
+
application_file=data_file("spark/application_test.yaml").as_posix(),
+ kubernetes_conn_id="kubernetes_default_kube_config",
+ task_id="default_yaml",
+ )
+ context = create_context(op)
+ op.execute(context)
+ TEST_APPLICATION_DICT["metadata"]["name"] = op.name
Review Comment:
Needs to add
``` python
assert op.name.startswith("default_yaml")
```
And the `task_id` should be equal to something else (not `default_yaml`)
##########
airflow/providers/cncf/kubernetes/operators/spark_kubernetes.py:
##########
@@ -161,8 +160,25 @@ def manage_template_specs(self):
return template_body
def create_job_name(self):
- initial_name = add_unique_suffix(name=self.task_id,
max_len=MAX_LABEL_LEN)
- return re.sub(r"[^a-z0-9-]+", "-", initial_name.lower())
+ """
+ Spark name is created based on the following order of precedence.
+
+ Check the name argument in the operator parameters.
+ Check the name specified in the YAML file.
+ If neither is available, use the task ID as the name.
+
+ It adds default random id characters for the name provided suffix.
+ """
Review Comment:
I don't think you need all that, the code speaks for itself.
##########
airflow/providers/cncf/kubernetes/operators/spark_kubernetes.py:
##########
@@ -161,8 +160,25 @@ def manage_template_specs(self):
return template_body
def create_job_name(self):
- initial_name = add_unique_suffix(name=self.task_id,
max_len=MAX_LABEL_LEN)
- return re.sub(r"[^a-z0-9-]+", "-", initial_name.lower())
+ """
+ Spark name is created based on the following order of precedence.
+
+ Check the name argument in the operator parameters.
+ Check the name specified in the YAML file.
+ If neither is available, use the task ID as the name.
+
+ It adds default random id characters for the name provided suffix.
+ """
+ name = self.template_body.get("spark", {}).get("metadata",
{}).get("name")
Review Comment:
Naming, maybe change "name" to "name_from_template" or something like that
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]