-
Notifications
You must be signed in to change notification settings - Fork 873
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
Feat: SDK generating framework #5431
Conversation
395c91f
to
6536a50
Compare
Codecov ReportBase: 61.34% // Head: 61.52% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## master #5431 +/- ##
==========================================
+ Coverage 61.34% 61.52% +0.18%
==========================================
Files 310 311 +1
Lines 47274 47919 +645
==========================================
+ Hits 29001 29483 +482
- Misses 15271 15383 +112
- Partials 3002 3053 +51
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
fda83d9
to
e9e4d1f
Compare
charts/vela-core/templates/defwithtemplate/apply-terraform-provider.yaml
Outdated
Show resolved
Hide resolved
design/vela-cli/sdk_generating.md
Outdated
|
||
When platform team users assembling Application, filling in components, traits and workflow steps, they are actually assemble Application YAML. Unfortunately, due to the extensibility of KubeVela X-Definition system, the property structure of different component (also for traits, workflow steps, policies) varies. In the source code, we use a `map[string]interface{}` to accept all kinds of properties. The unstructured code make it hard examine, modify, insert values of nested properties. | ||
|
||
Before KubeVela provide the SDK, the problem is mainly solved by providing OpenAPI schema to frontend and generate the form dynamically. There is also an enhancement scheme: ui-schema. After filling the form, the JSON returned by frontend is already satisfied the specification of X-Definition properties. This is how VelaUX works when assembling Application. |
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.
End user assemble application, they can assemble through YAML or using VelaUX, when using YAML, the issue occurs.
Actually, the SDK is provided for end users.
design/vela-cli/sdk_generating.md
Outdated
Basically there are two ways for end user to use Application: | ||
|
||
1. Through dashboard provided by platform team like VelaUX. The data is kept by the internal platform. In this pattern user's behavior can be better guided with typed form and UI indications. | ||
2. Storing Application as part of the codebase. Then through some way (e.g. GitOps) the application is applied to cluster. |
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 should be the sdk ways, the sdk can generate yamls out for GitOps or directly apply to cluster.
1. Provide SDK in other languages. This is a LFX mentorship: #5365 | ||
2. Allow user to customize the templates in Step2. | ||
|
||
### For Golang SDK |
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 need a section called "Language Caution" to describe the difference and notable points inside.
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.
That would be great. And I think it should be part of kubevela.io
@@ -0,0 +1,114 @@ | |||
# SDK 生成 |
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.
The zh doc is not necessary if time limits
96a08d1
to
7d6bd6a
Compare
3d5c73a
to
31c088e
Compare
ada9885
to
8aaeab1
Compare
Add OAS generated code remove hask/sdk Add modifier Refactor files fix occasional schema loss add workflowstep/policy builder fix api gen add name type func Signed-off-by: qiaozp <qiaozhongpei.qzp@alibaba-inc.com>
Signed-off-by: Qiaozp <qiaozhongpei.qzp@alibaba-inc.com>
Signed-off-by: Qiaozp <qiaozhongpei.qzp@alibaba-inc.com>
Signed-off-by: Qiaozp <qiaozhongpei.qzp@alibaba-inc.com>
Add sdk scaffold module tidy Signed-off-by: Qiaozp <qiaozhongpei.qzp@alibaba-inc.com>
Signed-off-by: Qiaozp <qiaozhongpei.qzp@alibaba-inc.com>
Signed-off-by: Qiaozp <qiaozhongpei.qzp@alibaba-inc.com>
Signed-off-by: Qiaozp <qiaozhongpei.qzp@alibaba-inc.com>
Signed-off-by: Qiaozp <qiaozhongpei.qzp@alibaba-inc.com>
Signed-off-by: Qiaozp <qiaozhongpei.qzp@alibaba-inc.com>
Signed-off-by: Qiaozp <qiaozhongpei.qzp@alibaba-inc.com>
Signed-off-by: Qiaozp <qiaozhongpei.qzp@alibaba-inc.com>
Signed-off-by: Qiaozp <qiaozhongpei.qzp@alibaba-inc.com>
Signed-off-by: Qiaozp <qiaozhongpei.qzp@alibaba-inc.com>
57d20ca
to
2542692
Compare
Signed-off-by: zhanghw0354 <zhanghaiwen_yewu@cmss.chinamobile.com>
* correct the doc of recycle application env api Signed-off-by: zhanghw0354 <zhanghaiwen_yewu@cmss.chinamobile.com> * Feat: SDK generating framework (#5431) Signed-off-by: zhanghw0354 <zhanghaiwen_yewu@cmss.chinamobile.com> --------- Signed-off-by: zhanghw0354 <zhanghaiwen_yewu@cmss.chinamobile.com> Co-authored-by: qiaozp <47812250+chivalryq@users.noreply.github.com>
Signed-off-by: Qiaozp qiaozhongpei.qzp@alibaba-inc.com
TL;DR
This PR introduce a framework which can generate KubeVela SDK from scaffolds, templates and X-Definitions.
Background
As KubeVela designs for separation of concerns, there are two roles of user: platform team and end user. They are dealing with Application in different ways.
For platform team
When platform team users assembling Application, filling in components, traits and workflow steps, they are actually assemble Application YAML. Unfortunately, due to the extensibility of KubeVela X-Definition system, the property structure of different component (also for traits, workflow steps, policies) varies. In the source code, we use a
map[string]interface{}
to accept all kinds of properties. The unstructured code make it hard examine, modify, insert values of nested properties.Before KubeVela provide the SDK, the problem is mainly solved by providing OpenAPI schema to frontend and generate the form dynamically. There is also an enhancement scheme: ui-schema. After filling the schema, the JSON returned by frontend is already satisfied the specification of X-Definition properties. This is how VelaUX works when assembling Application.
For end user
Basically there are two ways for end user to use Application:
Benefits
In the aforementioned ways of using Application, there are some issues for both roles.
For platform team
There are some scenarios which use JOSN data passed from frontend is not enough:
In these scenarios, it's painful to develop with
map[string]interface{}
. With SDK, platform team can benefits from the typed X-Definition properties and builds, examines, modifies application more easily.For end user
If user is writing Application YAML, they have to refer to the doc. Although we have done some toolchain on this topic like
vela show
, a typed SDK also provide a possibility for end user to code Application in different languages.Design and tools
Thanks to the OpenAPI schema and related tool openapi-generator in ecosystem, we can re-use the almost ready templates to generate code. The whole generation process is shown below.
Step0: The scaffold is written to destination if
--init
is specified. (omitted in pic)Step1: Generate OpenAPI schema from CUE. The generated schema may not fully prepared as input of openapi-generator and it will be correct and adjust.
Step2: Call openapi-generator to generate SDK. After that some modification will be applied to make SDK API suited for KubeVela user.
Usage
This command requires
java
andmvn
in PATH as we are leveraging openapi-generator which is a Java progarm.Future work
This PR only provide a framework on generating SDK and there are lots of jobs to do to provide
user-friendly SDKs in multiple languages.
Preview
The generated SDK can work like below to build applications. This is a example written in
Build Application
Link
![image](https://user-images.githubusercontent.com/47812250/218058344-79dfe094-440f-41fc-9416-4d556156405d.png)
Modify Application
Link
Known Issues
There are some problems when generating:
apply-terraform-provider
workflow step. Parameter are like below will cause the problem. Related issue: Error generating openapi: unsupported node string (*ast.Ident) cue-lang/cue#2259label
andannotation
trait. openapi-generator doesn't support top-level schema to be a map. The two traits' properties is actually justmap[string]string
so it's easy to build it without using SDK.I have:
make reviewable
to ensure this PR is ready for review.backport release-x.y
labels to auto-backport this PR if necessary.How has this code been tested
Special notes for your reviewer