uranusjr commented on code in PR #31663:
URL: https://github.com/apache/airflow/pull/31663#discussion_r1212808328
##########
airflow/providers/cncf/kubernetes/utils/pod_manager.py:
##########
@@ -398,15 +419,80 @@ def consume_logs(
)
time.sleep(1)
- def await_container_completion(self, pod: V1Pod, container_name: str) ->
None:
+ def fetch_requested_container_logs(
+ self, pod: V1Pod, container_logs: list[str] | str | bool,
follow_logs=False
+ ) -> list[PodLoggingStatus]:
+ """
+ Follow the logs of containers in the pod specified by input parameter
and publish
+ it to airflow logging. Returns when all the containers exit.
+ """
+ pod_logging_statuses = []
+ all_containers = self.get_container_names(pod)
+ if len(all_containers) == 0:
+ self.log.error("Could not retrieve containers for the pod: %s",
pod.metadata.name)
+ else:
+ # if a list of containers are provided, iterate for every
container in the pod
+ if type(container_logs) == list:
Review Comment:
I would do it like this instead:
```python
if isinstance(container_logs, str):
# The str case...
elif not isinstance(container_logs, collections.abc.Iterable):
container_logs = bool(container_logs)
# The bool case...
else:
# The list case...
```
This allows more kinds of containers to be passed into this function (such
as set and tuple). Note that `str` needs to go first because it is an iterable
as well.
--
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]