()
| 43 | |
| 44 | |
| 45 | def main(): |
| 46 | config.load_kube_config() |
| 47 | |
| 48 | v1 = CoreV1Api() |
| 49 | informer = SharedInformer( |
| 50 | list_func=v1.list_namespaced_pod, |
| 51 | namespace="default", |
| 52 | resync_period=60, |
| 53 | ) |
| 54 | |
| 55 | informer.add_event_handler(ADDED, on_pod_added) |
| 56 | informer.add_event_handler(MODIFIED, on_pod_modified) |
| 57 | informer.add_event_handler(DELETED, on_pod_deleted) |
| 58 | |
| 59 | informer.start() |
| 60 | print('Informer started. Watching pods in "default" namespace ...') |
| 61 | |
| 62 | try: |
| 63 | while True: |
| 64 | cached = informer.cache.list() |
| 65 | print("Cached pods: {}".format(len(cached))) |
| 66 | time.sleep(10) |
| 67 | except KeyboardInterrupt: |
| 68 | pass |
| 69 | finally: |
| 70 | informer.stop() |
| 71 | print("Informer stopped.") |
| 72 | |
| 73 | |
| 74 | if __name__ == "__main__": |
no test coverage detected