cdk8s-team / cdk8s-cli

Apache License 2.0
37 stars 23 forks source link

Cannot to import litmuschaos.io CRDs #1475

Open shinebayar-g opened 11 months ago

shinebayar-g commented 11 months ago

Description of the bug:

Cannot import litmuschaos.io CRDs, more specifically these 2

https://github.com/litmuschaos/chaos-operator/blob/master/deploy/crds/chaosengine_crd.yaml https://github.com/litmuschaos/chaos-scheduler/blob/master/deploy/crds/chaosschedule_crd.yaml

Reproduction Steps:

yarn run cdk8s import --no-save --output imports https://raw.githubusercontent.com/litmuschaos/chaos-operator/master/deploy/crds/chaosengine_crd.yaml

yarn run cdk8s import --no-save --output imports https://raw.githubusercontent.com/litmuschaos/chaos-scheduler/master/deploy/crds/chaosschedule_crd.yaml

Error Log:

❯ yarn run cdk8s import --no-save --output imports https://raw.githubusercontent.com/litmuschaos/chaos-scheduler/master/deploy/crds/chaosschedule_crd.yaml
Importing resources, this may take a few moments...
litmuschaos.io
  litmuschaos.io/chaosschedule
Error: for "properties", if "type" is specified it has to be an "object"
    at TypeGenerator.emitTypeInternal (/Users/User/work/cdk8s/node_modules/json2jsii/lib/type-generator.js:164:23)
    at TypeGenerator.typeForProperty (/Users/User/work/cdk8s/node_modules/json2jsii/lib/type-generator.js:385:21)
    at TypeGenerator.emitTypeInternal (/Users/User/work/cdk8s/node_modules/json2jsii/lib/type-generator.js:173:29)
    at TypeGenerator.typeForProperty (/Users/User/work/cdk8s/node_modules/json2jsii/lib/type-generator.js:385:21)
    at TypeGenerator.emitProperty (/Users/User/work/cdk8s/node_modules/json2jsii/lib/type-generator.js:324:35)
    at /Users/User/work/cdk8s/node_modules/json2jsii/lib/type-generator.js:304:22
    at typesToEmit.<computed> (/Users/User/work/cdk8s/node_modules/json2jsii/lib/type-generator.js:204:28)
    at TypeGenerator.renderToCode (/Users/User/work/cdk8s/node_modules/json2jsii/lib/type-generator.js:238:33)
    at TypeGenerator.render (/Users/User/work/cdk8s/node_modules/json2jsii/lib/type-generator.js:226:14)
    at CustomResourceDefinition.generateTypeScript (/Users/User/work/cdk8s/node_modules/cdk8s-cli/lib/import/crd.js:100:29)
❯ yarn run cdk8s import --no-save --output imports https://raw.githubusercontent.com/litmuschaos/chaos-operator/master/deploy/crds/chaosengine_crd.yaml
Importing resources, this may take a few moments...
litmuschaos.io
  litmuschaos.io/chaosengine
Error: for "properties", if "type" is specified it has to be an "object"
    at TypeGenerator.emitTypeInternal (/Users/User/work/cdk8s/node_modules/json2jsii/lib/type-generator.js:164:23)
    at TypeGenerator.typeForProperty (/Users/User/work/cdk8s/node_modules/json2jsii/lib/type-generator.js:385:21)
    at TypeGenerator.emitTypeInternal (/Users/User/work/cdk8s/node_modules/json2jsii/lib/type-generator.js:173:29)
    at TypeGenerator.typeForProperty (/Users/User/work/cdk8s/node_modules/json2jsii/lib/type-generator.js:385:21)
    at TypeGenerator.emitProperty (/Users/User/work/cdk8s/node_modules/json2jsii/lib/type-generator.js:324:35)
    at /Users/User/work/cdk8s/node_modules/json2jsii/lib/type-generator.js:304:22
    at typesToEmit.<computed> (/Users/User/work/cdk8s/node_modules/json2jsii/lib/type-generator.js:204:28)
    at TypeGenerator.renderToCode (/Users/User/work/cdk8s/node_modules/json2jsii/lib/type-generator.js:238:33)
    at TypeGenerator.render (/Users/User/work/cdk8s/node_modules/json2jsii/lib/type-generator.js:226:14)
    at CustomResourceDefinition.generateTypeScript (/Users/User/work/cdk8s/node_modules/cdk8s-cli/lib/import/crd.js:100:29)

Environment:

Other:


This is :bug: Bug Report

rassie commented 10 months ago

For the record: it seems that the problem lies within this definition:

                            nodeSelector:
                              type: object
                              additionalProperties:
                                type: string
                                properties:
                                  key:
                                    type: string
                                    minLength: 1
                                    allowEmptyValue: false
                                  value:
                                    type: string
                                    minLength: 1
                                    allowEmptyValue: false

It seems to be a valid syntax from JSON Schema point of view, but ultimately useless since the validation does not actually validate keys and values. Still the question is how to handle this case