okayhooni opened a new pull request, #33057:
URL: https://github.com/apache/airflow/pull/33057

   We currently deploy lots of Airflow clusters with different branches like 
below
   - `prod` Airflow (synced with `develop` branch
   - `beta` Airflow (synced also with `develop` branch, but use another 
configuration on same connection name and [AirflowClusterPolicySkipDag 
exeception](https://github.com/apache/airflow/pull/32013))
   - lots of individual Airflow cluster with small resources (synced with 
different feature branches, deployed on k8s with our custom `Airflow` CRD and 
controller. Every developer making DAG can create his/her own Airflow from web 
UI plugin of `prod`/`beta` Airflow)
   
   When we used KubernetesPodOperator with lots of Airflow deployments like 
above, we often encountered the exceptions raised from the code below, due to 
multiple Airflow can submit pod creation request with same labels and spec in 
same namespace.
   ```
       def find_pod(self, namespace: str, context: Context, *, exclude_checked: 
bool = True) -> k8s.V1Pod | None:
           """Returns an already-running pod for this task instance if one 
exists."""
           label_selector = self._build_find_pod_label_selector(context, 
exclude_checked=exclude_checked)
           pod_list = self.client.list_namespaced_pod(
               namespace=namespace,
               label_selector=label_selector,
           ).items
   
           pod = None
           num_pods = len(pod_list)
           if num_pods > 1:
               raise AirflowException(f"More than one pod running with labels 
{label_selector}")
           elif num_pods == 1:
               pod = pod_list[0]
               self.log.info("Found matching pod %s with labels %s", 
pod.metadata.name, pod.metadata.labels)
               self.log.info("`try_number` of task_instance: %s", 
context["ti"].try_number)
               self.log.info("`try_number` of pod: %s", 
pod.metadata.labels["try_number"])
           return pod
   ```
   
   So, I decided to use `labels` argument to differentiate multiple pods 
requested from different Airflow cluster
   ```
   :param labels: labels to apply to the Pod. (templated)
   ```
   But, I noticed this `labels` argument only handled on pod creation logic, 
and not on pod finding logic.
   
   I think it is more consistent to handle this `labels` argument, also on the 
pod finding logic.


-- 
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]

Reply via email to