Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

timeout_seconds seems to be ineffective #308

Open
wei1793786487 opened this issue Apr 7, 2024 · 2 comments
Open

timeout_seconds seems to be ineffective #308

wei1793786487 opened this issue Apr 7, 2024 · 2 comments

Comments

@wei1793786487
Copy link

wei1793786487 commented Apr 7, 2024

I set timeout_seconds to 600 seconds, but he still completes the watch event every 60 seconds. Can anyone provide assistance

image

 async def watch_pods(self):
            logger.info("Watching pods...")
            await self.config_loaded
            while True:  
                try:
                    async with client.ApiClient() as api:
                        v1 = client.CoreV1Api(api)
                        w = watch.Watch()
                        async for event in w.stream(v1.list_pod_for_all_namespaces, watch=True, timeout_seconds=600,):
                            pod = event['object']
                            pod_name = pod.metadata.name
                            self.resource_version = pod.metadata.resource_version
                            pod_namespace = pod.metadata.namespace
                            event_type = event['type']
                            if pod_namespace not in CHECK_NAMESPACES:
                                continue
                            if event_type in ['ADDED', 'MODIFIED']:
                                if pod.status.phase in ['Running', 'Pending']:
                                    self.pod_cache[f'{pod_namespace}/{pod_name}'] = pod
                                    logger.info(f"Pod {pod_name} in namespace {pod_namespace} {event_type.lower()}.")
                            elif event_type == 'DELETED':
                                self.pod_cache.pop(f'{pod_namespace}/{pod_name}', None)
                                logger.info(f"Pod {pod_name} in namespace {pod_namespace} deleted.")
                            logger.info("Pod watch stream ended.")
                except Exception as e:
                    logger.exception(e)
                    logger.error(f"Error watching pods: {e}")
                    logger.info("Reconnecting after error...")
                    await asyncio.sleep(1)
@tomplus
Copy link
Owner

tomplus commented Apr 7, 2024

Thank for reporting the issue. Could you check if you example is correct - it looks like this line "Pod watch stream ended." is printed when you get delete events...

Which version of K8s do you use? Is it self-hosted or managed by a cloud provider like Google, AWS, Alibaba Cloud,... ?

@wei1793786487
Copy link
Author

Sorry, I had an indentation issue, but I've fixed my code. I am using a self-hosted Kubernetes version v1.21.5, and I am new to Kubernetes. I want to know if the problem is with my code logic or with my Kubernetes setup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants