kcl-lang / kcl

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

Crossplane CRD composition import generates errors in k file #1127

Closed markphillips100 closed 8 months ago

markphillips100 commented 8 months ago

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

  1. Install VSCode, KCL, KCL language server and KCL VSCode extension.
  2. Download crossplane composition crd from here, or clone repo whichever is preferred to obtain this file.
  3. Create a new KCL module: kcl mod init mymod and cd mymod.
  4. Type kcl import -m crd -s -o . <location of yaml from step 1>
  5. Open module folder in VSCode and open the file models\apiextensions_crossplane_io_v1_composition.k at line 1171.
  6. Observe errors in the generated code.
  7. Replace main.k contents with the following code:
    import models as models
    comp: models.Composition {}
  8. Type kcl run from module folder.
  9. Observe errors related to generated code from line 1171.
  10. Comment generated code at line 1171 and execute step 8 again. Observe no error.

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

No errors.

3. What did you see instead (Required)

1171 |     readinessChecks?: [ApiextensionsCrossplaneIoV1CompositionSpecResourcesItems0ReadinessChecksItems0] = [{matchCondition
: map[status:True type:Ready], type: MatchCondition}]
     |
                       ^ name 'Ready' is not defined
     |

error[E2L23]: CompileError
    --> D:\Dev\EziEvent\ezievent-identityservice\devops\dev-cluster\crossplane-kcl\tuckerbox-core-composition\models\apiextensio
ns_crossplane_io_v1_composition.k:1171:159
     |
1171 |     readinessChecks?: [ApiextensionsCrossplaneIoV1CompositionSpecResourcesItems0ReadinessChecksItems0] = [{matchCondition
: map[status:True type:Ready], type: MatchCondition}]
     |
                                     ^ name 'MatchCondition' is not defined, did you mean '["matchCondition"]'?
     |

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

KCL: 0.8.0-windows-amd64 KCL vscode extension: v0.1.5 OS: Windows11

Peefy commented 8 months ago

Hello @markphillips100

Thank you for your feedback. This may be a bug in the kcl-openapi tool https://github.com/kcl-lang/kcl-openapi, which changes the default value to go map string instead of KCL dict string. The correct code at line 1171 may be

    readinessChecks?: [ApiextensionsCrossplaneIoV1CompositionSpecResourcesItems0ReadinessChecksItems0] =[{matchCondition: {status: True, type: "Ready"}, type: "MatchCondition"}]
markphillips100 commented 8 months ago

Yes that gives no errors. I'm assuming then that kcl import is just a wrapper over kcl-openapi?

markphillips100 commented 8 months ago

I'll raise the issue there then. Feel free to close.

markphillips100 commented 8 months ago

May I ask what version of kcl-openapi the kcl 0.8.0 version uses? If there is a later version I may try that direct just to see if the issue remains in latest code from that repo.

Peefy commented 8 months ago

I think this issue still exists in the latest version.