-
Notifications
You must be signed in to change notification settings - Fork 16
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
Improvements in the codebase- Backend converted to typescript #37
base: main
Are you sure you want to change the base?
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/assign @kevin-wangzefeng |
c4b87bd
to
70e36f1
Compare
Hi @Monokaix , I have added two new things
Its the extension of #65, the part which u mentioned |
@@ -0,0 +1,131 @@ | |||
/** |
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.
Are these files just an API description or sdk? Can we import to use them?
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.
It is a typescript declaration file and not a API description or sdk and yes we can import them to use them like I did in backend/src/types/index.ts
I WILL TRY MY BEST TO EXPLAIN WHY WE NEED THEM
Unlike statically typed languages like golang where the structure of data is always defined, javascript is a dynamically typed langauge (like python). This behavior introduces a lot of errors which can only be resolved on runtime. Typescript tries to make javascript a statically typed language.
Now when we fetch standard Kubernetes resources like pods,namespaces the type(structure of data) definition of the resource is already defined by the "@kubernetes/client-node" but when we fetch a custom resource, its type is not defined in the "@kubernetes/client-node" library. So we need to manually define it which is done in that files
backend/src/types/queue.d.ts
backend/src/types/job.d.ts
This approach of automated generation of types from standard resource definition is also followed in the "@kubernetes/client-node" (they are using some other library) thus for custom resources definition I tried to do the same.
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.
So can we directly refer to the fields of custom resources after this generation?
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.
Yes, we are just extracting the types out of yaml of the CRD
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.
It is a typescript declaration file and not a API description or sdk and yes we can import them to use them like I did in backend/src/types/index.ts
I WILL TRY MY BEST TO EXPLAIN WHY WE NEED THEM Unlike statically typed languages like golang where the structure of data is always defined, javascript is a dynamically typed langauge (like python). This behavior introduces a lot of errors which can only be resolved on runtime. Typescript tries to make javascript a statically typed language.
Now when we fetch standard Kubernetes resources like pods,namespaces the type(structure of data) definition of the resource is already defined by the "@kubernetes/client-node" but when we fetch a custom resource, its type is not defined in the "@kubernetes/client-node" library. So we need to manually define it which is done in that files backend/src/types/queue.d.ts backend/src/types/job.d.ts
This approach of automated generation of types from standard resource definition is also followed in the "@kubernetes/client-node" (they are using some other library) thus for custom resources definition I tried to do the same.
Hello @Sayan4444,
sorry to say, it could be perceived as overly defensive or aggressive in tone—especially with parts like "I WILL TRY MY BEST TO EXPLAIN WHY WE NEED THEM" in all caps, which can come off as shouting.
check_command jq | ||
check_command openapi-typescript | ||
|
||
kubectl get crd jobs.batch.volcano.sh -o json | jq '{ |
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 another way to generate instead of kubectl? Becasue this need user create a real cluster.
How about just generate through yaml or some static files?
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.
Yes we can generate it throught static yaml
https://github.com/volcano-sh/volcano/tree/master/config/crd/volcano/bases
But what I have understood is to have this application started or to make the api calls, its mandatory to have volcano deployed in the kubernetes cluster. So thats why I thought why not to use something which is most readily available.
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.
There is also an API repo https://github.com/volcano-sh/apis
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.
Hi sir, the types only need to be generated when there are changes in the CRD which is rare i.e. we dont need to always use "generate.sh" while setting up the project and only use it if the types are invalid
To generate the types of a resource, we need openapi-spec file of that resource. In libraries like https://github.com/kubernetes-client/javascript
the openapi-spec file of the native resources are already cached making the type generation faster. In our case we are fetching the openapi-spec it from the cluster and getting the types from it.
WHY FETCHING FROM CLUSTER INSTEAD OF CACHING?
We only generate the types (i.e. use generate.sh) when the CRD changes. A updated CRD means a modified openapi-spec file making the old one invalid.
So now since the old types are invalid we need to generate the new types thus we need new openapi spec file. This exact step is automated via this script.
I hope am able to convey my point 😊
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 think we'd better add a doc to let users know how to use this script.
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.
Hi @Monokaix, I added the docs under
docs/generateScript.md
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.
.github/workflows/build.yml
Outdated
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 think we should add this workflow after adding tests. #53
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.
Yep
backend/tsconfig.json
Outdated
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 think we should remove unnecessary commented code.
Also, it would be great to add import alias @
so that we do not have to do ../../path/to/file
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.
Removed the commented code
@karanBRAVO: changing LGTM is restricted to collaborators In response to this: Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
docs/generateScript.md
Outdated
## Prerequisites | ||
Before running the script, ensure the following tools are installed and properly configured on your system: | ||
- **kubectl**: Required to interact with the Kubernetes cluster and fetch the OpenAPI specification. | ||
- **pq**: A utility used for processing the fetched data. |
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.
jq?
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.
Maybe we should also add note that a ready cluster with volcano installed?
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.
jq?
corrected it, it was a typo
docs/generateScript.md
Outdated
@@ -0,0 +1,34 @@ | |||
# Script Explanation: `generate.sh` |
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.
Maybe we can give an absolute path.
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.
Changed it. Actually, since the same types are used for the frontend also, so in future it will a general script. For now it only affects the backend, if approved will generalise it "types" of both frontend and backend
docs/generateScript.md
Outdated
npm run generate:types | ||
``` | ||
This will fetch the latest OpenAPI specification and generate the TypeScript types for the custom resources. | ||
## Purpose |
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.
Maybe we should emphasize that here we just generate volcano related resources to develop codes.
@Sayan4444 is your backend conversation to typescript complete, since I started working on backend now so it might create conflicts with my existing changes. |
Yes my PR has no conflicts with the current base branch |
Please squash to one commit and make ci happy. |
Hi @Monokaix, I have updated the readme. If this gets approved I will squash |
Hi @Sayan4444 as of now ,readme can be updated afterwards, u complete this work first 🙃, because it is pausing work of other contributers on backend |
Signed-off-by: Sayan Banerjee <[email protected]>
74e28e2
to
6f064fe
Compare
@Shrutim1505 Sorry for that and my work is completed. |
I have squashed it into a single commit. The ci still fails cause the frontend is broken. |
Once more after squashing can u please run Ci check |
@Shrutim1505 For every new push the ci runs again only |
This is a part of the issue #13 and split version of PR #29.