kcl-lang / kcl

KCL Programming Language (CNCF Sandbox Project). https://kcl-lang.io
https://kcl-lang.io
Apache License 2.0
1.64k stars 118 forks source link

Generated names are extremely long, as opposed to some organization that would be easier to use #1543

Open wmcnamee-coreweave opened 2 months ago

wmcnamee-coreweave commented 2 months ago

Bug Report

Shorter schema names from generated code.

1. Minimal reproduce step (Required)

git@github.com:argoproj/argo-workflows.git
kcl import -m crd -o lib -s ./argo-workflows/manifests/base/crds/full/argoproj.io_clusterworkflowtemplates.yaml

2. What did you expect to see? (Required)

shorter schema names, organized

3. What did you see instead (Required)

schema ArgoprojIoV1alpha1ClusterWorkflowTemplateSpecAffinityNodeAffinityPreferredDuringSchedulingIgnoredDuringExecutionItems0PreferenceMatchFieldsItems0

4. What is your KCL components version? (Required)

kcl --version
kcl version 0.9.6
wmcnamee-coreweave commented 2 months ago

if there was a KCL generator for Go types, instead of OpenAPI or CRDs, then the same organization in the Go code could be ported over. Leaving shorter names.

Peefy commented 2 months ago

Yes, we can organize names by package names instead of long schema names. In fact, KCL import OpenAPI has been organized by package name, just like the k8s package https://github.com/kcl-lang/modules/tree/main/k8s/1.31, through the swagger file https://github.com/kcl-lang/modules/blob/main/scripts/k8s/processed-swagger.json

wmcnamee-coreweave commented 2 months ago

I looked at the argo-workflow module (which I think is also misnamed, should be argo-workflows), and I went through a time-boxed 30m exercise to clean it up. I found that a lot of the fields used are actually types coming straight from k8s but are instead inlined in that module. In that 30m, I was able to reduce this file (https://github.com/kcl-lang/modules/blob/main/argo-workflow/v1alpha1/argoproj_io_v1alpha1_workflow.k) from 3.37MB to 2.7MB just by fixing references to schemas upstream, but there was a lot more that I could do. I used this as my primary source of information: https://github.com/argoproj/argo-workflows/blob/main/pkg/apis/workflow/v1alpha1/workflow_types.go

This leads me to believe that a potentially better way to generate schemas is by looking at/parsing Go. Anyways, just some shower thoughts.

Peefy commented 2 months ago

Thank you! @wmcnamee-coreweave PRs welcome!

For Go struct to KCL module, track issue is here. https://github.com/kcl-lang/kcl-go/issues/332

Actually, this work is underway and I have successfully converted some of the argoworkflows go code. There are still some errors that need to be fixed.