cdk8s-team / cdk8s

Define Kubernetes native apps and abstractions using object-oriented programming
https://cdk8s.io
Apache License 2.0
4.29k stars 290 forks source link

Import generated directory structure invalid for python import with dashes #274

Closed gabe-l-hart closed 4 years ago

gabe-l-hart commented 4 years ago

Description of the bug:

When running cdk8s import against a CRD whose custom resource group name contains dash characters (-), the resulting directory structure also contains dashes in the directory names. For a python app, this is invalid for import, making the resulting package unreachable from within the python code.

Reproduction Steps:

  1. In the crd example, update the version.yaml file so that the group is sample-controller instead of samplecontroller
  2. Run cdk8s import version.yaml
  3. tree imports

    imports/
    └── sample-controller
        └── k8s
            └── io
                └── foo
                    ├── __init__.py
                    ├── _jsii
                    │   ├── __init__.py
                    │   └── generated@0.0.0.jsii.tgz
                    └── py.typed
    
    5 directories, 4 files
  4. python -c 'from imports.sample-controller.k8s.io import foo'

Error Log:

  File "<string>", line 1
    from imports.sample-controller.k8s.io import foo
                       ^
SyntaxError: invalid syntax

Environment:

Other:

I'm fairly certain I have a fix, but I haven't gotten the test env set up and have been distracted with other items this morning. I think that this section needs to do a replace of - with _. I'll keep this ticket up to date with anything else I find while testing.


This is :bug: Bug Report

campionfellin commented 4 years ago

@iliapolo I can take this, as it's so closely related to https://github.com/awslabs/cdk8s/issues/273