godaddy / kubernetes-client

Simplified Kubernetes API client for Node.js.
MIT License
962 stars 192 forks source link

getStream() on CRD resources #637

Open fvedad opened 4 years ago

fvedad commented 4 years ago

Hi guys,

we realised that using: client.apis['some.api'].watch.some_plural.getStream() is no longer supported in 9.0.0.

We tried to do:

const stream = await client.apis["dtk.io"].v1alpha1.some_plural.getStream();
const jsonStream = new JSONStream();
stream.pipe(jsonStream);
jsonStream.on("data", async (event: any) => {
   ...
}

We realise getStream() is deprecated, but getObjectStream() is undefined for this path. If the custom resource is v1alpha1 not sure if there is a better way to watch changes on it?

Using the deprecated getStream(), the event is triggered only the first time. When editing the resource again, this event does not get triggered at all from that point on.

Not sure if there is a new way to approach this problem of doing a watch event on custom resources that may have different versions (v1, v1beta1, v1alpha1, etc)?

Edit: The way the client is loaded is:

let Client = require('kubernetes-client').Client;
let Request = require('kubernetes-client/backends/request');

backend = new Request(Request.config.getInCluster());
client = new Client({ backend: backend });
await client.loadSpec();

Thanks

fvedad commented 4 years ago

Update:

realised it is necessary to addCustomResourceDefinition in order for path to .watch be available. Is there a way to do this without explicitly loading each custom resource definition to the client?