-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Kubernetes Async API Calls with Callbacks Support #2231
Comments
I would like to submit the PR if we align on this. |
Upstream Kubernetes API doesn't support such callback mechanism AFAICT. Could you check with the upstream on this feature request? |
@roycaihw Check api_client.py for the same
|
CC @tomplus Could you take a look? |
I can suggest using sync api calls but from a dedicated thread pool where you can add callbacks as you need. What do you think? |
@tomplus |
Correct me if I'm wrong but you want to have something like this: create_namespaced_pod("pod-1", "ns-1", cb_success, cb_error)
create_namespaced_pod("pod-2", "ns-2", cb_success, cb_error) so instead of using def cb_helper(func_name, cb_success, cb_error, *args, **kwargs):
try:
result = func_name(*args, **kwargs)
except Exception as ex:
cb_error(ex)
cb_success(result)
pool = with ThreadPool()
pool.apply_async(cb_helper, create_namespaced_pod, "pod-1", "ns-1", cb_success, cb_error)
pool.apply_async(cb_helper, create_namespaced_pod, "pod-2", "ns-2", cb_success, cb_error)
....
.... so it uses synchronous requests but from threads so main thread is not blocked... |
Kubernetes API calls do support async operations. As of now, we don't a have to provide the callbacks for async calls. It would be good idea to provide success and failure callbacks to avoid polling for the result.
Example: create_namespaced_pod(namespace, body, async_req=True, async_callback, async_error_callback)
The text was updated successfully, but these errors were encountered: