shahar1 commented on code in PR #39329:
URL: https://github.com/apache/airflow/pull/39329#discussion_r1607151894


##########
airflow/providers/cncf/kubernetes/operators/pod.py:
##########
@@ -533,24 +539,31 @@ def find_pod(self, namespace: str, context: Context, *, 
exclude_checked: bool =
 
         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:
+
+        if 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"])
+            self.log_matching_pod(pod=pod, context=context)
+        elif num_pods > 1 and not self.reattach_on_restart:
+            self.log.warning("Found more than one pod running with labels %s, 
resolving ...", label_selector)
+            pod = self.process_duplicate_label_pods(pod_list)
+            self.log_matching_pod(pod=pod, context=context)
+        elif num_pods > 1:
+            raise IdenticalLabelPodError(f"More than one pod running with 
labels {label_selector}")
+

Review Comment:
   For a slightly better readability, maybe you could rephrase the `elif` as:
   
   ```python
   
           elif num_pods > 1:
                  if not self.reattach_on_restart:
                      self.log.warning("Found more than one pod running with 
labels %s, resolving ...", label_selector)
                      pod = self.process_duplicate_label_pods(pod_list)
                      self.log_matching_pod(pod=pod, context=context)
                   else:
                      raise IdenticalLabelPodError(f"More than one pod running 
with labels {label_selector}")
   ```



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