pulumi / crd2pulumi

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

Failure to parse nested default values #32

Closed headconnect closed 6 months ago

headconnect commented 3 years ago

When attempting to parse the CRD referenced to nodejs in https://www.rabbitmq.com/kubernetes/operator/install-operator.html (i.e. https://github.com/rabbitmq/cluster-operator/releases/latest/download/cluster-operator.yml) crd2pulumi fails with an "error binding default value for property storage".

Expected behavior

Should compile CRD correctly

Current behavior

Fails with following error:

λ c:\dev\localApps\crd2pulumi\crd2pulumi.exe -n components\cluster-operator-trimmed.yml
panic: fatal: error An assertion has failed: could not parse Pulumi package. source error: could not import spec: binding types: failed to bind type kubernetes:rabbitmq.com/v1beta1:RabbitmqClusterSpecPersistence: error binding default value for property storage: default values may only be provided for boolean, integer, number, and string properties

goroutine 1 [running]:
github.com/pulumi/pulumi/sdk/v2/go/common/util/contract.failfast(...)
        /home/runner/go/pkg/mod/github.com/pulumi/pulumi/sdk/v2@v2.9.2/go/common/util/contract/failfast.go:23
github.com/pulumi/pulumi/sdk/v2/go/common/util/contract.AssertNoErrorf(0x12c1060, 0xc0012d60a0, 0x111c62a, 0x1e, 0x0, 0x0, 0x0)
        /home/runner/go/pkg/mod/github.com/pulumi/pulumi/sdk/v2@v2.9.2/go/common/util/contract/assert.go:47 +0x1ca
github.com/pulumi/crd2pulumi/gen.(*PackageGenerator).SchemaPackage(0xc000517ba8, 0x3)
        /home/runner/work/crd2pulumi/crd2pulumi/gen/generate.go:181 +0xbc
github.com/pulumi/crd2pulumi/gen.(*PackageGenerator).genNodeJSFiles(0xc000517ba8, 0x10fcb88, 0x4, 0xc00093d100, 0x1, 0x1)
        /home/runner/work/crd2pulumi/crd2pulumi/gen/nodejs.go:39 +0x4a
github.com/pulumi/crd2pulumi/gen.(*PackageGenerator).genNodeJS(0xc000517ba8, 0xc00008f600, 0xb, 0x10fcb88, 0x4, 0x1, 0xc00093d140)
        /home/runner/work/crd2pulumi/crd2pulumi/gen/nodejs.go:30 +0x4a
github.com/pulumi/crd2pulumi/gen.Generate(0xc00068b770, 0x0, 0x0, 0x0, 0x10fcb88, 0x4, 0x10fcb88, 0x4, 0x10fcb88, 0x4, ...)
        /home/runner/work/crd2pulumi/crd2pulumi/gen/generate.go:63 +0x287
github.com/pulumi/crd2pulumi/cmd.glob..func2(0x1ac8640, 0xc0002d88a0, 0x1, 0x2)
        /home/runner/work/crd2pulumi/crd2pulumi/cmd/root.go:153 +0x218
github.com/spf13/cobra.(*Command).execute(0x1ac8640, 0xc00003e090, 0x2, 0x3, 0x1ac8640, 0xc00003e090)
        /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:846 +0x2a4
github.com/spf13/cobra.(*Command).ExecuteC(0x1ac8640, 0x4455a1, 0x1a51280, 0xc00005bf78)
        /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:950 +0x350
github.com/spf13/cobra.(*Command).Execute(...)
        /home/runner/go/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:887
github.com/pulumi/crd2pulumi/cmd.Execute(...)
        /home/runner/work/crd2pulumi/crd2pulumi/cmd/root.go:165
main.main()
        /home/runner/work/crd2pulumi/crd2pulumi/main.go:25 +0x39

Steps to reproduce

  1. Retrieve operator from https://github.com/rabbitmq/cluster-operator/releases/latest/download/cluster-operator.yml (tested with 1.5.0)
  2. Trim away non-CRD elements from yaml
  3. Run crd2pulumi -n cluster-operator-trimmed.yml
  4. See error above.

Context (Environment)

It's likely the following section is responsible for the error:

              persistence:
                default:
                  storage: 10Gi
                description: The desired persistent storage configuration for each Pod in the cluster.
                properties:
                  storage:
                    anyOf:
                    - type: integer
                    - type: string
                    default: 10Gi
                    description: The requested size of the persistent volume attached to each Pod in the RabbitmqCluster. The format of this field matches that defined by kubernetes/apimachinery. See https://pkg.go.dev/k8s.io/apimachinery/pkg/api/resource#Quantity for more info on the format of this field.
                    pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
                    x-kubernetes-int-or-string: true

Affected feature

mikhailshilkov commented 3 years ago

Looks similar to https://github.com/pulumi/crd2pulumi/issues/22

blampe commented 6 months ago

Fixed in https://github.com/pulumi/crd2pulumi/pull/136.