Add possibility to return the event object as well
import logging
from hestia.tz_utils import now
-
from kubernetes import watch
from ocular.processor import get_pod_state
@@ -9,7 +8,7 @@ from ocular.processor import get_pod_state
logger = logging.getLogger('ocular')
-def monitor(k8s_api, namespace, container_names, label_selector=None):
+def monitor(k8s_api, namespace, container_names, label_selector=None, return_event=False):
w = watch.Watch()
for event in w.stream(k8s_api.list_namespaced_pod,
@@ -18,9 +17,14 @@ def monitor(k8s_api, namespace, container_names, label_selector=None):
created_at = now()
logger.debug("Received event: %s", event['type'])
event_object = event['object'].to_dict()
- logger.debug(event_object)
- yield get_pod_state(
+ logger.debug("Event object: %s", event_object)
+ pod_state = get_pod_state(
event_type=event['type'],
event=event_object,
job_container_names=container_names,
created_at=created_at)
+ logger.debug("Pod state: %s", pod_state)
+ if return_event:
+ yield (event_object, pod_state)
+ else:
+ yield pod_state
