jedcunningham commented on code in PR #28546:
URL: https://github.com/apache/airflow/pull/28546#discussion_r1055936849
##########
airflow/kubernetes/pod_generator.py:
##########
@@ -430,6 +419,70 @@ def construct_pod(
except Exception as e:
raise PodReconciliationError from e
+ @classmethod
+ def build_selector_for_k8s_executor_pod(
+ cls,
+ *,
+ dag_id,
+ task_id,
+ try_number,
+ map_index=None,
+ date=None,
+ run_id=None,
+ ):
+ """
+ Generate selector for kubernetes executor pod
+
+ :meta private:
+ """
+ labels = cls.build_labels_for_k8s_executor_pod(
+ dag_id=dag_id,
+ task_id=task_id,
+ try_number=try_number,
+ map_index=map_index,
+ date=date,
+ run_id=run_id,
+ )
+ label_strings = [f"{label_id}={label}" for label_id, label in
sorted(labels.items())]
+ selector = ",".join(label_strings)
+ selector += ",airflow-worker"
+ return selector
+
+ @classmethod
+ def build_labels_for_k8s_executor_pod(
+ cls,
+ *,
+ dag_id,
+ task_id,
+ try_number,
+ airflow_worker=None,
+ map_index=None,
+ date=None,
+ run_id=None,
+ ):
+ """
+ Generate labels for kubernetes executor pod
+
+ :meta private:
+ """
+ labels = {
+ "dag_id": make_safe_label_value(dag_id),
+ "task_id": make_safe_label_value(task_id),
+ "try_number": str(try_number),
+ "kubernetes_executor": "True",
+ }
+ if airflow_worker is not None:
Review Comment:
I should have air quoted, "public". Where I'm going is that it feels weird
to me having `build` even work without all of the labels we'd set on the pod
being required, moving the "what's really required" outside of PodGenerator.
I'm coming at it from the PodGenerator "public internal" interface perspective.
e.g.
```
def _get_labels_dict(
*,
dag_id,
task_id,
try_number,
airflow_worker=None,
map_index=None,
date=None,
run_id=None,
):
...
def build(
*,
dag_id,
task_id,
try_number,
airflow_worker,
map_index,
date,
run_id,
):
return _get_labels_dict(...)
def selector(*, dag_id, task_id, try_number):
return _get_labels_dict(...)
```
This seems to more easily mesh with what you should to do for build vs get
the selector (e.g. code completion/typing - ":meta private:" is for sphinx
after all).
However, enough bikeshedding on my part :)
--
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]