crd2pulumi icon indicating copy to clipboard operation
crd2pulumi copied to clipboard

crontabs default example not working on python "pkg_resources.DistributionNotFound"

Open notdodo opened this issue 2 years ago • 6 comments

What happened?

Following the python example to create CRDs inside pulumi during the pulumi up command the following error is returned:

pulumi:pulumi:Stack (pulumi-k8s-pulumi-k8s):
error: Program failed with an unhandled exception:
Traceback (most recent call last):
File "/path/path/pulumi-k8s/./__main__.py", line 42, in <module>
import crontabs.pulumi_crds as crontabs
File "/path/path/pulumi-k8s/./crontabs/pulumi_crds/__init__.py", line 5, in <module>
from . import _utilities
File "/path/path/pulumi-k8s/./crontabs/pulumi_crds/_utilities.py", line 94, in <module>
_version = _get_semver_version()
File "/path/path/pulumi-k8s/./crontabs/pulumi_crds/_utilities.py", line 73, in _get_semver_version
pep440_version_string = pkg_resources.require(root_package)[0].version
File "/path/path/pulumi-k8s/.venv/lib/python3.10/site-packages/pkg_resources/__init__.py", line 909, in require
needed = self.resolve(parse_requirements(requirements))
File "/path/path/pulumi-k8s/.venv/lib/python3.10/site-packages/pkg_resources/__init__.py", line 795, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'crontabs' distribution was not found and is required by the application

Changing the import from import crontabs.pulumi_crds as crontabs to import crontabs as crontabs solve the pkg_resources error but the usage of the module is impacted.

import crontabs as crontabs

# Register the CronTab CRD.
crontab_definition = k8s.yaml.ConfigFile(
    "my-crontab-definition", file="customresources.yaml"
)

# Instantiate a CronTab resource.
crontab_instance = crontabs.stable.v1.CronTab(
    "my-new-cron-object",
    metadata=k8s.meta.v1.ObjectMetaArgs(name="my-new-cron-object"),
    spec=crontabs.stable.v1.CronTabSpecArgs(
        cron_spec="* * * */5",
        image="my-awesome-cron-image",
    ),
)

the error returned is now:

error: Program failed with an unhandled exception:
Traceback (most recent call last):
File "/path/path/pulumi-k8s/./__main__.py", line 50, in <module>
crontab_instance = crontabs.stable.v1.CronTab(
AttributeError: module 'crontabs' has no attribute 'stable'

Expected Behavior

import of the module works and it's usable to create CRDs from python

Steps to reproduce

1- download the yaml for the CRDs for crontabs from the example 2- crd2pulumi --pythonPath ./crontabs customresources.yaml 3- use the module

Output of pulumi about

CLI          
Version      3.53.1
Go Version   go1.19.5
Go Compiler  gc

Plugins
NAME                     VERSION
command                  0.7.1-alpha.1674088865
crds                     0.0.0
kubernetes               3.24.0-alpha.1675102241
kubernetes-cert-manager  0.0.5
python                   unknown

Host     
OS       ubuntu
Version  22.04
Arch     x86_64

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

notdodo avatar Jan 31 '23 23:01 notdodo

Hey @notdodo, thanks for the bug report. We're currently determining how to integrate crd2pulumi into our other migration tools. I expect crd2pulumi to be in maintenance mode until we've decided how to do that.

Could you tell me a little more about your use case for crd2pulumi?

In the mean time we'll keep this issue open as it's a valid bug report.

AaronFriel avatar Feb 01 '23 22:02 AaronFriel

Hi @AaronFriel, the use case is simply to use it to have pulumi CRDs for ECK (https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-deploy-eck.html) instead of manually writing pulumi resources or using yaml files.

notdodo avatar Feb 01 '23 22:02 notdodo

That makes sense, thanks.

AaronFriel avatar Feb 01 '23 23:02 AaronFriel

@AaronFriel Hi any update on this please? I'm seeing the same issue, the use case is the same, integrating CRD in the pulumi code using python.

lingxiankong avatar Jun 05 '23 06:06 lingxiankong

I'm also running into this issue with python and crd2pulumi

after-ephemera avatar Sep 18 '23 23:09 after-ephemera

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

cleverguy25 avatar Aug 09 '24 23:08 cleverguy25