-
Notifications
You must be signed in to change notification settings - Fork 544
chore: update examples node fetch #1074
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
chore: update examples node fetch #1074
Conversation
.then((res) => { | ||
console.log(res.body); | ||
console.log(res); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason you've switched that to the complete res
object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't. That is what this function is now returning. This example now reflects that.
src/cache.ts
Outdated
@@ -25,7 +25,7 @@ export class ListWatch<T extends KubernetesObject> implements ObjectCache<T>, In | |||
private objects: T[] = []; | |||
private resourceVersion: string; | |||
private readonly indexCache: { [key: string]: T[] } = {}; | |||
private readonly callbackCache: { [key: string]: (ObjectCallback<T> | ErrorCallback)[] } = {}; | |||
private readonly callbackCache: { [key: string]: Array<ObjectCallback<T> | ErrorCallback> } = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain why you need to make these changes in this file and the corresponding test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functions like k8sApi.listPodForAllNamespaces()
no longer return the HTTP status and body. They return just the KubernetesObjects. I updated ListPromise to reflect this and updated the tests. Let me know if this is out of line, but the example and tests do not work otherwise.
- [ ] yaml-example | ||
|
||
- [ ] Fix TypeScript examples and validate their param signatures (due to new api) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We didn't account for the TypeScript examples before.
@@ -8,7 +8,7 @@ const k8sApi = kc.makeApiClient(k8s.CoreV1Api); | |||
const path = '/api/v1/pods'; | |||
const watch = new k8s.Watch(kc); | |||
|
|||
const listFn = () => k8sApi.listPodForAllNamespaces() | |||
const listFn = () => k8sApi.listPodForAllNamespaces(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of these examples got formatted with prettier.
export type ObjectCallback<T extends KubernetesObject> = (obj: T) => void; | ||
export type ErrorCallback = (err?: any) => void; | ||
export type ListCallback<T extends KubernetesObject> = (list: T[], ResourceVersion: string) => void; | ||
export type ListPromise<T extends KubernetesObject> = () => Promise<{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When running the example I noticed k8sApi.listPodForAllNamespaces()
no longer returns a response and body, just the objects. I updated this accordingly.
86fd68c
to
1fbfc18
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 LGTM
examples/top_pods.js
Outdated
@@ -1,39 +1,35 @@ | |||
const k8s = require('../dist/index'); | |||
const k8s = require('@kubernetes/client-node'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needs to be removed b/c otherwise we are testing against the published package vs HEAD
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of the examples use this. I will updated the others to use HEAD
to match your comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I'm actually conflicted :) Perhaps it is better to have a working example? The trouble with not using HEAD
is that if we change the API then we don't have continuous validation that the examples are working...
Maybe we can add a comment to each of these that says:
// in a real program use require('@kubernetes/client-node')
or something like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, the rest of these seem to use require('@kubernetes/client-node');
. I will make them use require('../dist/index');
but maybe it would be helpful to have a comment on how to import the package? Or maybe the readme does that already. Thinking out loud here. For now I will just import them.
Ok I just reloaded this page and saw your comment 😂. Sounds like we are on the same page. I will add a comment and make it clear.
One minor comment. |
1fbfc18
to
88f31f2
Compare
Also fixed a bug with ListPromise still returning body and response.
88f31f2
to
34c6010
Compare
/lgtm Thanks! |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: brendandburns, clintonmedbery, mstruebing The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
This fixes a few of the examples in the
FETCH_MIGRATION
markdown file. The ones I have checked off I have tested. I have also updated a few more I will include in another PR that I have not been able to successfully test because of this issue:#893
I also added the typescript examples to the document, as they will need to be upgraded as well.