Im trying to catch events in k8s using python. The problem is that when I run the script the watch process show me all the events (current, and new). Is there a possiblitity to get only new events?
My code looks like:
config.load_incluster_config()
v1 = client.CoreV1Api()
w = watch.Watch()
for event in w.stream(v1.list_service_for_all_namespaces, timeout_seconds=0):
service = event['object']
if service.spec.type == 'NodePort':
print(service.metadata.name, service.metadata.namespace, service.spec.type, service.spec.ports[0].node_port, event['type'])
With the above code I receive current events(old events) and new events, but I only want new events. Thanks in advance!!