Source:
public void watchEvents(PodEventHandler handler) throws InfrastructureException { if (containerWatch == null) { final Watcher<Event> watcher = new Watcher<Event>() { @Override public void eventReceived(Action action, Event event) { ObjectReference involvedObject = event.getInvolvedObject(); if (POD_OBJECT_KIND.equals(involvedObject.getKind()) || REPLICASET_OBJECT_KIND.equals(involvedObject.getKind()) || DEPLOYMENT_OBJECT_KIND.equals(involvedObject.getKind())) { String podName = involvedObject.getName(); PodEvent podEvent = new PodEvent( podName, getContainerName(involvedObject.getFieldPath()), event.getReason(), event.getMessage(), event.getMetadata().getCreationTimestamp(), event.getLastTimestamp()); try { if (happenedAfterWatcherInitialization(podEvent)) { containerEventsHandlers.forEach(h -> h.handle(podEvent)); } } catch (ParseException e) { LOG.error( String.format( "Failed to parse last timestamp of the event. Cause: %s. Event: %s", e.getMessage(), podEvent), e); } } } @Override public void onClose(KubernetesClientException ignored) private String getContainerName(String fieldPath) { String containerName = null; if (fieldPath != null) { Matcher containerFieldMatcher = CONTAINER_FIELD_PATH_PATTERN.matcher(fieldPath); if (containerFieldMatcher.matches()) { containerName = containerFieldMatcher.group(CONTAINER_NAME_GROUP); } } return containerName; } private boolean happenedAfterWatcherInitialization(PodEvent event) throws ParseException { String eventLastTimestamp = event.getLastTimestamp(); Date eventLastTimestampDate = PodEvents.convertEventTimestampToDate(eventLastTimestamp); return eventLastTimestampDate.after(watcherInitializationDate); } }; try { watcherInitializationDate = new Date(); containerWatch = clientFactory.create(workspaceId).events().inNamespace(namespace).watch(watcher); } catch (KubernetesClientException ex) { throw new KubernetesInfrastructureException(ex); } } containerEventsHandlers.add(handler); }

Target:
public void watchEvents(PodEventHandler handler) throws InfrastructureException { if (containerWatch == null) { final Watcher<Event> watcher = new Watcher<Event>() { @Override public void eventReceived(Action action, Event event) { ObjectReference involvedObject = event.getInvolvedObject(); if (POD_OBJECT_KIND.equals(involvedObject.getKind()) || REPLICASET_OBJECT_KIND.equals(involvedObject.getKind()) || DEPLOYMENT_OBJECT_KIND.equals(involvedObject.getKind())) { String podName = involvedObject.getName(); PodEvent podEvent = new PodEvent( podName, getContainerName(involvedObject.getFieldPath()), event.getReason(), event.getMessage(), event.getMetadata().getCreationTimestamp(), event.getLastTimestamp()); try { if (happenedAfterWatcherInitialization(podEvent)) { containerEventsHandlers.forEach(h -> h.handle(podEvent)); } } catch (ParseException e) { LOG.error( "Failed to parse last timestamp of the event. Cause: {}. Event: {}", e.getMessage(), podEvent, e); } } } @Override public void onClose(KubernetesClientException ignored) private String getContainerName(String fieldPath) { String containerName = null; if (fieldPath != null) { Matcher containerFieldMatcher = CONTAINER_FIELD_PATH_PATTERN.matcher(fieldPath); if (containerFieldMatcher.matches()) { containerName = containerFieldMatcher.group(CONTAINER_NAME_GROUP); } } return containerName; } private boolean happenedAfterWatcherInitialization(PodEvent event) throws ParseException { String eventLastTimestamp = event.getLastTimestamp(); Date eventLastTimestampDate = PodEvents.convertEventTimestampToDate(eventLastTimestamp); return eventLastTimestampDate.after(watcherInitializationDate); } }; try { watcherInitializationDate = new Date(); containerWatch = clientFactory.create(workspaceId).events().inNamespace(namespace).watch(watcher); } catch (KubernetesClientException ex) { throw new KubernetesInfrastructureException(ex); } } containerEventsHandlers.add(handler); }