pulumi / crd2pulumi

Generate typed CustomResources from a Kubernetes CustomResourceDefinition
Apache License 2.0
98 stars 16 forks source link

goPath not worked #89

Closed howieyuen closed 1 month ago

howieyuen commented 2 years ago

What happened?

crd2pulumi --goPath ./crontabs crontab.yaml generate code under package kubernetes not under crontabs

Steps to reproduce

Just like README says, prepare crontab.yaml first, then run crd2pulumi --goPath ./crontabs crontab.yaml

Expected Behavior

generated code under new package crontabs

Actual Behavior

generated code under new package kubernetes

Versions used

v1.2.0

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

roothorp commented 2 years ago

Hi @howieyuen , we have reproduced this issue and can confirm this is a bug. This bug only seems present for Go, and the equivalent flags for other languages are functional. This portion of the codebase seems to have undergone quite a lot of changes since the last release, so the issue might have already been addressed. @mattolenik would be good to confirm whether this has been addressed?

howieyuen commented 2 years ago

Hi @howieyuen , we have reproduced this issue and can confirm this is a bug. This bug only seems present for Go, and the equivalent flags for other languages are functional. This portion of the codebase seems to have undergone quite a lot of changes since the last release, so the issue might have already been addressed. @mattolenik would be good to confirm whether this has been addressed?

I try to fix locally, but failed 😭 I puase here pkg/codegen/golang.go:75:

func GenerateGo(pg *PackageGenerator, name string) (buffers map[string]*bytes.Buffer, err error) {
        ...
    for path, code := range files {
        newPath, _ := filepath.Rel(name, path)

and see newPath is ../kubernetes/xxx, I don't know the intension of filepath.Rel(), but after that, back to parent func at pkg/codegen/codegen.go:86:

func writeFiles(files map[string]*bytes.Buffer, outputDir string) error {
    for path, code := range files {
        outputFilePath := filepath.Join(outputDir, path)

        ...

the outputFilePath comes from filepath.Join("crontabs","../kubernetes"), and it turns out kubernetes.

cleverguy25 commented 2 months ago

Added to epic https://github.com/pulumi/home/issues/3431

pulumi-bot commented 2 weeks ago

This issue has been addressed in PR #143 and shipped in release v1.5.0.