Skip to content
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

clintonmedbery
Copy link
Contributor

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.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 4, 2023
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label May 4, 2023
examples/example.js Outdated Show resolved Hide resolved
.then((res) => {
console.log(res.body);
console.log(res);
Copy link
Member

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?

Copy link
Contributor Author

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.

examples/ingress.js Outdated Show resolved Hide resolved
examples/ingress.js Outdated Show resolved Hide resolved
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> } = {};
Copy link
Member

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?

Copy link
Contributor Author

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)
Copy link
Contributor Author

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();
Copy link
Contributor Author

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<{
Copy link
Contributor Author

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.

@clintonmedbery clintonmedbery force-pushed the clintonmedbery/chore/update-examples-node-fetch branch 3 times, most recently from 86fd68c to 1fbfc18 Compare May 4, 2023 20:16
Copy link
Member

@mstruebing mstruebing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 LGTM

@@ -1,39 +1,35 @@
const k8s = require('../dist/index');
const k8s = require('@kubernetes/client-node');
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@brendandburns
Copy link
Contributor

One minor comment.

@clintonmedbery clintonmedbery force-pushed the clintonmedbery/chore/update-examples-node-fetch branch from 1fbfc18 to 88f31f2 Compare May 8, 2023 00:43
Also fixed a bug with ListPromise still returning body and response.
@clintonmedbery clintonmedbery force-pushed the clintonmedbery/chore/update-examples-node-fetch branch from 88f31f2 to 34c6010 Compare May 8, 2023 00:47
@brendandburns
Copy link
Contributor

/lgtm
/approve

Thanks!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 9, 2023
@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 9, 2023
@k8s-ci-robot k8s-ci-robot merged commit 15a3345 into kubernetes-client:release-1.x May 9, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants