-
Notifications
You must be signed in to change notification settings - Fork 540
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
Listing/Watching kubernetes Custom Resources #341
Comments
Please see this example here: https://github.com/kubernetes-client/javascript/blob/master/examples/cache-example.js#L13 And the informer example here: Closing this issue as the question is answered. Please re-open if you need more info. |
@brendandburns Thanks for the links but I was actually looking for an example with a custom resource definition listing and not simply listing/watching for pods which could be very similar. Please let me know how can such a use case be implemented in javascript similar to maybe https://github.com/kubernetes/code-generator |
So I just stumbled upon this issue looking for a similar answer to @SachinVarghese So this client is generated with this script which uses the kubernetes-client/gen repo to generate a typescript client. I found a issue that hasn't been updated in 6 months about making that 'kubernetes-client/gen' repo work for CRDs too: kubernetes-client/gen#121 |
Can we re-open it but consider it blocked by kubernetes-client/gen#121? |
Some of the modern Kubernetes clients use clients generated from a swagger.json kubernetes-client/javascript uses kubernetes-client/gen which uses OpenApiTools/openapi-generator and kubernetes/kubernetes/api/openapi-spec/swagger.json There are open/closed/rotten/ignored issues all over the place about making these easier to use with CRDs. Wrongly closed issue on kubernetes-client/javascript: kubernetes-client/javascript#341 Open issue on kubernetes-client/gen: kubernetes-client/gen#121 It seems like kubernetes/kube-openapi is one of the repos working on solving the main part of this problem, generating the Go code to make it easy to generate a swagger.json I found the following Argo code via the following issue: kubernetes/kube-openapi#13 https://github.com/argoproj/argo/blob/master/hack/gen-openapi-spec/main.go https://github.com/argoproj/argo/blob/master/pkg/apis/workflow/v1alpha1/openapi_generated.go#L14:6 https://github.com/kubernetes/kube-openapi/blob/master/cmd/openapi-gen/openapi-gen.go So I'm working on adding similar stuff to Shipper. gen-openapi-spec uses the generated openapi_generated.go module that is generated via the openapi-gen command. The following commit adds the code to generate openapi_generated.go Signed-off-by: William Stewart <[email protected]>
@zoidbergwill I was able to generate a cluster-specific client with CRD apis/models with a couple of simple steps using the existing code:
|
Does this handle updates and deletes, or just creates? |
@brendandburns @SachinVarghese Can you point me to a working example that uses I'm getting this error: [DEBUG] Reconciler - init: Watching group 'mk8.farberg.de', version 'v1', plural 'microkeights'
./node_modules/@kubernetes/client-node/dist/cache.js:77
const list = result.body;
^
TypeError: Cannot read property 'body' of undefined
at ListWatch.<anonymous> (./node_modules/@kubernetes/client-node/dist/cache.js:77:33)
at Generator.next (<anonymous>)
at fulfilled (./node_modules/tslib/tslib.js:112:62)
at processTicksAndRejections (node:internal/process/task_queues:94:5) when using this code: async init() {
//Create K8s Client
this.logger.debug(`init: Creating kubeconfig`)
this.kubeConfig = new k8s.KubeConfig();
this.kubeConfig.loadFromDefault();
this.k8sApi = this.kubeConfig.makeApiClient(k8s.CoreV1Api);
this.customObjectsApi = this.kubeConfig.makeApiClient(k8s.CustomObjectsApi)
// Register custom resource definition
// registerCustomResourceDefinition @ https://github.com/dot-i/k8s-operator-node/blob/master/src/operator.ts
this.logger.debug(`init: Registering CRD from file ${this.options.crdFile}`)
const { group, versions, plural } = await this.registerCustomResourceDefinition(this.options.crdFile);
this.crdGroup = group;
this.crdVersions = versions;
this.crdPlural = plural;
console.log("XXX", await this.customObjectsApi.listClusterCustomObject(this.crdGroup, versions[0].name, this.crdPlural))
this.logger.debug(`init: Watching group '${this.crdGroup}', version '${this.crdVersions[0].name}', plural '${this.crdPlural}'`)
const informer = k8s.makeInformer(this.kubeConfig, `/apis/${this.crdGroup}/${versions[0].name}/${this.crdPlural}`, () => {
console.log("Called")
})
} |
quite the same as @pfisterer, simply listing pods :
seems to break at |
Is it currently possible to list or watch k8s CRDs in javascript and create client code for the same?
The text was updated successfully, but these errors were encountered: