Skip to content

[nodejs] Type for generated metadata field incorrect #30

@ringods

Description

@ringods

Expected behavior

Every Kubernetes object has a metadata field. When generating the NodeJS code for a CRD, I expect the type of the metadata field to be similar to the type of the core Kubernetes classes. E.g. I copied this from kubernetes.core.v1.Service:

    public readonly metadata!: pulumi.Output<outputs.meta.v1.ObjectMeta>;

Current behavior

The metadata field in my generated is this:

    public readonly metadata!: pulumi.Output<ObjectMeta | undefined>;

Since the metadata field always exists on a Kubernetes object, the | undefined part is not correct.

Steps to reproduce

  1. Take a GKE cluster.
  2. kubectl get crd backendconfigs.cloud.google.com -o yaml > backendconfigs.yaml
  3. crd2pulumi --nodejsName backendconfig --nodejsPath ./backendconfig backendconfigs.yaml
  4. Create an instance: const cfg = new backendconfig.cloud.v1.BackendConfig(...)
  5. Try to retrieve the name: cfg.metadata.name
  6. You get an error: Property 'name' does not exist on type 'Output<ObjectMeta | undefined>'.

Context (Environment)

I had to remove the | undefined part manually from the generated field. A lot more of the generated fields have the same | undefined section in the type definition, so there might be problems there as well.

When following the code path, I ended up here in the core Pulumi codegen packages:

https://github.com/pulumi/pulumi/blob/1f16423ede4c9b6266f2df5aa4ef2aa8c79ae54f/pkg/codegen/nodejs/gen.go#L263-L265

Affected feature

Metadata

Metadata

Assignees

Labels

area/codegenAffects quality or correctness of generated codeimpact/usabilitySomething that impacts users' ability to use the product easily and intuitivelykind/bugSome behavior is incorrect or out of speclanguage/javascriptresolution/fixedThis issue was fixed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions