crd2pulumi icon indicating copy to clipboard operation
crd2pulumi copied to clipboard

Python code imports do not work

Open drzero42 opened this issue 4 years ago • 1 comments

Pulumi v3.6.1 Pulumi-kubernetes v3.5.0 crd2pulumi v1.0.8

I am trying to generate a Pulumi Python module for Cert-manager CRDs:

$ wget https://github.com/jetstack/cert-manager/releases/download/v1.4.0/cert-manager.crds.yaml
$ crd2pulumi --pythonPath certmanager cert-manager.crds.yaml
$ cat __main__.py
"""A Kubernetes Python Pulumi program"""

from certmanager.pulumi_crds import certmanager

$ pulumi preview

Previewing update (dev)

View Live: https://app.pulumi.com/drzero/pulumi-learn/dev/previews/da0b527b-a91f-46fc-b483-457e9e71877c

     Type                 Name              Plan       Info
 +   pulumi:pulumi:Stack  pulumi-learn-dev  create     3 errors
 
Diagnostics:
  pulumi:pulumi:Stack (pulumi-learn-dev):
    error: Program failed with an unhandled exception:
    error: Traceback (most recent call last):
      File "/home/abo/.pulumi/bin/pulumi-language-python-exec", line 92, in <module>
        loop.run_until_complete(coro)
      File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
        return future.result()
      File "/home/abo/sandbox/pulumi-learn/venv/lib/python3.8/site-packages/pulumi/runtime/stack.py", line 110, in run_in_stack
        await run_pulumi_func(lambda: Stack(func))
      File "/home/abo/sandbox/pulumi-learn/venv/lib/python3.8/site-packages/pulumi/runtime/stack.py", line 43, in run_pulumi_func
        func()
      File "/home/abo/sandbox/pulumi-learn/venv/lib/python3.8/site-packages/pulumi/runtime/stack.py", line 110, in <lambda>
        await run_pulumi_func(lambda: Stack(func))
      File "/home/abo/sandbox/pulumi-learn/venv/lib/python3.8/site-packages/pulumi/runtime/stack.py", line 133, in __init__
        func()
      File "/home/abo/.pulumi/bin/pulumi-language-python-exec", line 91, in <lambda>
        coro = pulumi.runtime.run_in_stack(lambda: runpy.run_path(args.PROGRAM, run_name='__main__'))
      File "/usr/lib/python3.8/runpy.py", line 282, in run_path
        return _run_code(code, mod_globals, init_globals,
      File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
        exec(code, run_globals)
      File "/home/abo/sandbox/pulumi-learn/./__main__.py", line 8, in <module>
        from certmanager.pulumi_crds import certmanager
      File "/home/abo/sandbox/pulumi-learn/./certmanager/pulumi_crds/__init__.py", line 9, in <module>
        from . import (
      File "/home/abo/sandbox/pulumi-learn/./certmanager/pulumi_crds/acme/__init__.py", line 7, in <module>
        from . import (
      File "/home/abo/sandbox/pulumi-learn/./certmanager/pulumi_crds/acme/v1/__init__.py", line 6, in <module>
        from .Challenge import *
      File "/home/abo/sandbox/pulumi-learn/./certmanager/pulumi_crds/acme/v1/Challenge.py", line 12, in <module>
        from pulumi_kubernetes import meta_v1 as _meta_v1
    ImportError: cannot import name 'meta_v1' from 'pulumi_kubernetes' (/home/abo/sandbox/pulumi-learn/venv/lib/python3.8/site-packages/pulumi_kubernetes/__init__.py)
    error: an unhandled error occurred: Program exited with non-zero exit code: 1

As far as I can see, there is no meta_v1 module in pulumi_kubernetes, it needs to do something like from pulumi_kubernetes.meta impart v1 as _meta_v1 instead.

drzero42 avatar Jul 12 '21 11:07 drzero42

Additional info:

Ubuntu 20.04 Python v3.8.10

drzero42 avatar Jul 12 '21 19:07 drzero42

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

cleverguy25 avatar Aug 09 '24 23:08 cleverguy25