kubernetes python watch stream

6/15/2018

I'm trying to start watch events:

if __name__ == "__main__":
    if 'CLUSTER' in os.environ:
        config.load_incluster_config()
    else:
        config.load_kube_config()
    api_client = client.CertificatesV1beta1Api()
    print("INFO:    Waiting for event to come up...")
    w = watch.Watch()
    for event in w.stream(api_client.list_certificate_signing_request, pretty=api_pretty):
        certificate = event["object"]
        spec_name = event["object"].metadata.name
        spec_groups = event["object"].spec.groups
        spec_username = event["object"].spec.username
        print("INFO:    Handling %s on %s" % (event["type"], spec_name))
        ...someOtherStuffs

Locally everything is going well, but when I'm trying run this code inside a cluster - it doesn't watch to a new event.

Can somebody put me in to the right direction?

P.S I tried to use watch=True into stream. Timeout just stop the pod. Timeout with while True: working, but I think it's not a good way

-- CrusaderX
api
kubernetes
python
watch

0 Answers