jscheffl commented on code in PR #59080:
URL: https://github.com/apache/airflow/pull/59080#discussion_r2596474021
##########
providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/utils/pod_manager.py:
##########
@@ -94,34 +95,23 @@ def check_exception_is_kubernetes_api_unauthorized(exc:
BaseException):
return isinstance(exc, ApiException) and exc.status and str(exc.status) ==
"401"
-async def watch_pod_events(
- pod_manager: PodManager | AsyncPodManager,
- pod: V1Pod,
- check_interval: float = 1,
+def log_pod_event(
+ pod_manager: PodManager | AsyncPodManager, event: CoreV1Event,
seen_events: set[str]
) -> None:
"""
- Read pod events and write them to the log.
+ Log a pod event if not already seen.
- This function supports both asynchronous and synchronous pod managers.
-
- :param pod_manager: The pod manager instance (PodManager or
AsyncPodManager).
- :param pod: The pod object to monitor.
- :param check_interval: Interval (in seconds) between checks.
+ :param pod_manager: The pod manager instance for logging
+ :param event: Kubernetes event
+ :param seen_events: Set of event UIDs already logged to avoid duplicates
"""
- num_events = 0
- is_async = isinstance(pod_manager, AsyncPodManager)
- while not pod_manager.stop_watching_events:
- if is_async:
- events = await pod_manager.read_pod_events(pod)
- else:
- events = pod_manager.read_pod_events(pod)
- for new_event in events.items[num_events:]:
- involved_object: V1ObjectReference = new_event.involved_object
- pod_manager.log.info(
- "The Pod has an Event: %s from %s", new_event.message,
involved_object.field_path
- )
- num_events = len(events.items)
- await asyncio.sleep(check_interval)
+ event_uid = event.metadata.uid
+ if event_uid in seen_events:
+ return None # Skip duplicate events
+
+ seen_events.add(event_uid)
+ involved_object: V1ObjectReference = event.involved_object
+ pod_manager.log.info("The Pod has an Event: %s from %s", event.message,
involved_object.field_path)
Review Comment:
Mini nit on code-reading: as the method does not return anything, `None`
also does not need to be returned. Can be a bit shorter if you negate the
condition, e.g.
```suggestion
if event_uid not in seen_events:
seen_events.add(event_uid)
involved_object: V1ObjectReference = event.involved_object
pod_manager.log.info("The Pod has an Event: %s from %s",
event.message, involved_object.field_path)
```
--
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]