-
Notifications
You must be signed in to change notification settings - Fork 192
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
Promises based API #37
Comments
Sorry for the delay @kjvalencik -- this is something we'd consider implementing, but it hasn't been high on our priority list because we usually eschew promises. I think the first step would be rejiggering kubernetes-client a little bit to facilitate adding promise support. If you have some concrete thoughts here, we'd love to hear them. Second step would then be actually adding the promise support. Either as an option to kubernetes-client, or as a separate |
There are a few things that I think could be helpful to allow integrating promises externally:
Open questions:
|
@kjvalencik helpful list -- if we could rejigger things so that switching to promise mode was as easy as passing in the re: |
…e to `{}` This fixes stream calls without an `options` argument. E.g.,: ``` // This used to TypeError. // Now it returns a stream. const stream = core.ns.po.get(); ``` #37 (comment)
We should consider adding a promise-based API to kubernetes-client: const api = require('kubernetes-client/async');
const core = new api.Core(api.config.fromKubeconfig());
async function main() {
const pods = await core.ns.po.get();
console.log(`Watching: ${ JSON.stringify(pods, null, 2) }`);
const stream = core.ns.po.getStream({ qs: { watch: true }});
stream.on('data', data => { console.log(data.toString()); });
stream.on('error', err => { throw err; });
stream.on('end', () => { console.log('end'); });
}
main(); Any feedback on the following:
or something else? |
…e to `{}` This fixes stream calls without an `options` argument. E.g.,: ``` // This used to TypeError. // Now it returns a stream. const stream = core.ns.po.get(); ``` #37 (comment)
…e to `{}` (#115) This fixes stream calls without an `options` argument. E.g.,: ``` // This used to TypeError. // Now it returns a stream. const stream = core.ns.po.get(); ``` #37 (comment)
|
This change facilitates a Promised-based API (see [1] for discussion). The original `request`-like behavior is unchanged: return a stream if the caller omits a callback. [1]: #37
This change facilitates a Promised-based API (see [1] for discussion). The original `request`-like behavior is unchanged: return a stream if the caller omits a callback. [1]: #37
This preserves the original callback-based "core" implementation and layers the promised-based API on top of that core implementation. The goal is start using and iterating on the promised-based API even if we expect the underlying implementation to evolve (e.g., we could consider replacing the core callback-based implementation with a promise one). See #37 for discussion. Example usage: ```js async function main() { try { const pods = await core.ns('kube-system').po.get(); console.log(`Watching: ${ JSON.stringify(pods, null, 2) }`); const stream = core.ns('kube-system').po.getStream({ qs: { watch: true }}); stream.on('data', data => { console.log(data.toString()); }); stream.on('error', err => { throw err; }); stream.on('end', () => { console.log('end'); }); } catch (error) { console.log(error); } } main(); ```
This preserves the original callback-based "core" implementation and layers the promised-based API on top of that core implementation. The goal is start using and iterating on the promised-based API even if we expect the underlying implementation to evolve (e.g., we could consider replacing the core callback-based implementation with a promise one). See #37 for discussion. Example usage: ```js const core = new api.Core({ url: 'http://my-k8s-api-server.com', promises: true }); async function main() { try { const pods = await core.ns('kube-system').po.get(); console.log(`Watching: ${ JSON.stringify(pods, null, 2) }`); const stream = core.ns('kube-system').po.getStream({ qs: { watch: true }}); stream.on('data', data => { console.log(data.toString()); }); stream.on('error', err => { throw err; }); stream.on('end', () => { console.log('end'); }); } catch (error) { console.log(error); } } main(); ```
This preserves the original callback-based "core" implementation and layers the promised-based API on top of that core implementation. The goal is start using and iterating on the promised-based API even if we expect the underlying implementation to evolve (e.g., we could consider replacing the core callback-based implementation with a promise one). See #37 for discussion. Example usage: ```js const core = new api.Core({ url: 'http://my-k8s-api-server.com', promises: true }); async function main() { try { const pods = await core.ns('kube-system').po.get(); console.log(`Watching: ${ JSON.stringify(pods, null, 2) }`); const stream = core.ns('kube-system').po.getStream({ qs: { watch: true }}); stream.on('data', data => { console.log(data.toString()); }); stream.on('error', err => { throw err; }); stream.on('end', () => { console.log('end'); }); } catch (error) { console.log(error); } } main(); ```
This preserves the original callback-based "core" implementation and layers the promised-based API on top of that core implementation. The goal is start using and iterating on the promised-based API even if we expect the underlying implementation to evolve (e.g., we could consider replacing the core callback-based implementation with a promise one). See #37 for discussion. Example usage: ```js const core = new api.Core({ url: 'http://my-k8s-api-server.com', promises: true }); async function main() { try { const pods = await core.ns('kube-system').po.get(); console.log(`Watching: ${ JSON.stringify(pods, null, 2) }`); const stream = core.ns('kube-system').po.getStream({ qs: { watch: true }}); stream.on('data', data => { console.log(data.toString()); }); stream.on('error', err => { throw err; }); stream.on('end', () => { console.log('end'); }); } catch (error) { console.log(error); } } main(); ```
This preserves the original callback-based "core" implementation and layers the promised-based API on top of that core implementation. The goal is start using and iterating on the promised-based API even if we expect the underlying implementation to evolve (e.g., we could consider replacing the core callback-based implementation with a promise one). See #37 for discussion. Example usage: ```js const core = new api.Core({ url: 'http://my-k8s-api-server.com', promises: true }); async function main() { try { const pods = await core.ns('kube-system').po.get(); console.log(`Watching: ${ JSON.stringify(pods, null, 2) }`); const stream = core.ns('kube-system').po.getStream({ qs: { watch: true }}); stream.on('data', data => { console.log(data.toString()); }); stream.on('error', err => { throw err; }); stream.on('end', () => { console.log('end'); }); } catch (error) { console.log(error); } } main(); ```
This preserves the original callback-based "core" implementation and layers the promised-based API on top of that core implementation. The goal is start using and iterating on the promised-based API even if we expect the underlying implementation to evolve (e.g., we could consider replacing the core callback-based implementation with a promise one). See #37 for discussion. Example usage: ```js const core = new api.Core({ url: 'http://my-k8s-api-server.com', promises: true }); async function main() { try { const pods = await core.ns('kube-system').po.get(); console.log(`Watching: ${ JSON.stringify(pods, null, 2) }`); const stream = core.ns('kube-system').po.getStream({ qs: { watch: true }}); stream.on('data', data => { console.log(data.toString()); }); stream.on('error', err => { throw err; }); stream.on('end', () => { console.log('end'); }); } catch (error) { console.log(error); } } main(); ```
This preserves the original callback-based "core" implementation and layers the promised-based API on top of that core implementation. The goal is start using and iterating on the promised-based API even if we expect the underlying implementation to evolve (e.g., we could consider replacing the core callback-based implementation with a promise one). See #37 for discussion. Example usage: ```js const core = new api.Core({ url: 'http://my-k8s-api-server.com', promises: true }); async function main() { try { const pods = await core.ns('kube-system').po.get(); console.log(`Watching: ${ JSON.stringify(pods, null, 2) }`); const stream = core.ns('kube-system').po.getStream({ qs: { watch: true }}); stream.on('data', data => { console.log(data.toString()); }); stream.on('error', err => { throw err; }); stream.on('end', () => { console.log('end'); }); } catch (error) { console.log(error); } } main(); ```
Added experimental support with 3.16.0. |
…e to `{}` (#115) This fixes stream calls without an `options` argument. E.g.,: ``` // This used to TypeError. // Now it returns a stream. const stream = core.ns.po.get(); ``` godaddy/kubernetes-client#37 (comment)
This change facilitates a Promised-based API (see [1] for discussion). The original `request`-like behavior is unchanged: return a stream if the caller omits a callback. [1]: godaddy/kubernetes-client#37
This preserves the original callback-based "core" implementation and layers the promised-based API on top of that core implementation. The goal is start using and iterating on the promised-based API even if we expect the underlying implementation to evolve (e.g., we could consider replacing the core callback-based implementation with a promise one). See godaddy/kubernetes-client#37 for discussion. Example usage: ```js const core = new api.Core({ url: 'http://my-k8s-api-server.com', promises: true }); async function main() { try { const pods = await core.ns('kube-system').po.get(); console.log(`Watching: ${ JSON.stringify(pods, null, 2) }`); const stream = core.ns('kube-system').po.getStream({ qs: { watch: true }}); stream.on('data', data => { console.log(data.toString()); }); stream.on('error', err => { throw err; }); stream.on('end', () => { console.log('end'); }); } catch (error) { console.log(error); } } main(); ```
It would be nice if this library also supported promises. Unfortunately, wrapping the
request
library for promises is fairly non-trivial. This makes it a bit unwieldy to promisify at runtime.The request-promise library also supports a
nodeify
method for callbacks, allowing simulataneous support for callbacks and promises. However, this may make streaming more cumbersome.Perhaps a provide your own
request
library approach?The text was updated successfully, but these errors were encountered: