pulumi / crd2pulumi

Generate typed CustomResources from a Kubernetes CustomResourceDefinition
Apache License 2.0
99 stars 17 forks source link

Invalid typescript code produced when generating for strimzi crds #103

Open maxemann96 opened 2 years ago

maxemann96 commented 2 years ago

What happened?

The following invalid typescript code is produced (Stripped the other invalid generated code as the error is always the same).

export interface KafkaConnectSpecJvmoptions {
      /**
       * A map of -XX options to the JVM.
       */
      -XX?: { [key: string]: any };
      /**
       * -Xms option to to the JVM.
       */
      -Xms?: string;
      /**
       * -Xmx option to to the JVM.
       */
      -Xmx?: string;
      /**
       * Specifies whether the Garbage Collection logging is enabled. The default is false.
       */
      gcLoggingEnabled?: boolean;
      /**
       * A map of additional system properties which will be passed using the `-D` option to the JVM.
       */
      javaSystemProperties?: outputs.kafka.v1beta2.KafkaConnectSpecJvmoptionsJavasystemproperties[];
    }

Steps to reproduce

Get the strimzi crds and generate the typescript code for example with crd2pulumi --nodejs --nodejsPath=crds/nodejs/ crds/k8s/*.yaml. The following excerpt automatically downloads the crds:

mkdir -p crds/k8s/
pushd crds/k8s/
curl --fail --remote-name -sSL https://raw.githubusercontent.com/strimzi/strimzi-kafka-operator/main/helm-charts/helm3/strimzi-kafka-operator/crds/\{040-Crd-kafka,041-Crd-kafkaconnect,042-Crd-strimzipodset,043-Crd-kafkatopic,044-Crd-kafkauser,045-Crd-kafkamirrormaker,046-Crd-kafkabridge,047-Crd-kafkaconnector,048-Crd-kafkamirrormaker2,048-Crd-kafkamirrormaker2,049-Crd-kafkarebalance\}.yaml
popd

Expected Behavior

Valid typescript code

Actual Behavior

Invalid typescript code

Output of pulumi about

CLI          
Version      3.43.1
Go Version   go1.19.2
Go Compiler  gc

Plugins
NAME    VERSION
nodejs  unknown

Host     
OS       darwin
Version  11.7
Arch     x86_64

This project is written in nodejs: executable='/usr/local/bin/node' version='v18.11.0'

Current Stack: [REDACTED]

TYPE                                                         URN
[STRIPPED]

Found no pending operations associated with [REDACTED]

Backend        
Name           pulumi.com
URL            https://app.pulumi.com/maxemann96
User           maxemann96
Organizations  maxemann96, [REDACTED]

Pulumi locates its logs in /var/folders/3p/6t2fzpvj3g7gj3jtgqm4yt080000gn/T/ by default
warning: Failed to get information about the Pulumi program's dependencies: Could not find either /[REDACTED]/yarn.lock or /[REDACTED]/package-lock.json

The warning can be ignored since it is a npm workspace setup.

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 @maxemann96, thanks for the issue. Am I correct in thinking here that the issue you are having is the names still having hyphens in front of their names? Or is there another problem with the generated typescript code? Thanks!

maxemann96 commented 2 years ago

Thanks for your answer. Typescript doesn't like the hyphens in front of the names. Removing the hyphens from my code fixed the issue for me, but I'm not using these flags in my environment to define some Java heap space constraints. I think removing the hyphens made the code possible unusable for people which are relying on specifying the heap space constraints, but I don't know if this can be fixed.

samox73 commented 2 years ago

Should be an "easy" fix by checking if the key name is a valid JS/TS variable name, and if not wrapping it in quotes?

cleverguy25 commented 3 months ago

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

rquitales commented 1 month ago

Re-opening as incorrectly identified as a fix for the v1.5.0 release.

pulumi-bot commented 1 month ago

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