from kubernetes import client, config, watch

"""
Explanation: How to watch changes to an object
In this notebook, we learn how kubernetes API resource Watch endpoint is used to observe resource changes. It can be used to get information about changes to any kubernetes object.
End of explanation
"""


config.load_kube_config()

"""
Explanation: Load config from default location.
End of explanation
"""


api_instance = client.CoreV1Api()

"""
Explanation: Create API instance
End of explanation
"""


w = watch.Watch()
for event in w.stream(api_instance.list_pod_for_all_namespaces):
    print("Event: %s %s %s" % (event['type'],event['object'].kind, event['object'].metadata.name))

"""
Explanation: Run a Watch on the Pods endpoint.
Watch would be executed and produce output about changes to any Pod. After running the cell below, You can test this by running the Pod notebook create_pod.ipynb and observing the additional output here. You can stop the cell from running by restarting the kernel.
End of explanation
"""


