crd2pulumi icon indicating copy to clipboard operation
crd2pulumi copied to clipboard

Generated setup.py is broken

Open sebbegg opened this issue 2 years ago • 2 comments

What happened?

I was trying to generate traefik CRD resources:

> crd2pulumi version
v1.2.2

> crd2pulumi -p --pythonName traefik --pythonPath traefik -v 0.1.0 https://raw.githubusercontent.com/traefik/traefik/v2.9/docs/content/reference/dynamic-configuration/kubernetes-crd-definition-v1.yml

this produces the following setup.py

# coding=utf-8
# *** WARNING: this file was generated by crd2pulumi. ***
# *** Do not edit by hand unless you're certain you know what you are doing! ***

import errno
from setuptools import setup, find_packages
from setuptools.command.install import install
from subprocess import check_call


VERSION = "0.0.0"
PLUGIN_VERSION = "0.0.0"

class InstallPluginCommand(install):
    def run(self):
        install.run(self)
        try:
            check_call(['pulumi', 'plugin', 'install', 'resource', 'traefik', PLUGIN_VERSION])
        except OSError as error:
            if error.errno == errno.ENOENT:
                print(f"""
                There was an error installing the traefik resource provider plugin.
                It looks like `pulumi` is not installed on your system.
                Please visit https://pulumi.com/ to install the Pulumi CLI.
                You may try manually installing the plugin by running
                `pulumi plugin install resource traefik {PLUGIN_VERSION}`
                """)
            else:
                raise


def readme():
    try:
        with open('README.md', encoding='utf-8') as f:
            return f.read()
    except FileNotFoundError:
        return "traefik Pulumi Package - Development Version"


setup(name='pulumi_traefik',
      version=VERSION,
      long_description=readme(),
      long_description_content_type='text/markdown',
      cmdclass={
          'install': InstallPluginCommand,
      },
      packages=find_packages(),
      package_data={
          'pulumi_traefik': [
              'py.typed',
              'pulumi-plugin.json',
          ]
      },
      install_requires=[
          'parver>=0.2.1',
          'pulumi>=3.0.0,<4.0.0',
          'pyyaml>=5.3',
          'requests>=2.21.0,<2.22.0',
          'semver>=2.8.1'
      ],
      zip_safe=False)

There's several things apparently broken:

  • VERSION and PLUGIN_VERSION seem to be 0.0.0, irrespective of the version supplied on the command-line
  • The custom install command tries to install the traefik plugin resource provider. That seems wrong? Shouldn't this rather include an install command for the kubernetes plugin?
  • The install_requires contains requests (with a very narrow version constraint) and pyaml. Both don't seem to be used by the generated code

I would have liked to build a pip-installable package for traefik crds on our internal pip repo. This seems possible only by handcrafting the setup.py after generation. Is this an expected use-case or is the generated code expected to be used as "source" part of an existing project (effectively ignoring the setup.py) ?

Steps to reproduce

See above

Expected Behavior

A well-formed setup.py should be generated that can be used to build and install the package.

Actual Behavior

Packages build from setup.py will most probably fail during installation.

Output of pulumi about

No pulum involved

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).

sebbegg avatar Oct 01 '22 08:10 sebbegg

Same issue. I think the problem in these lines of setup.py:

class InstallPluginCommand(install):
    def run(self):
        install.run(self)
        try:
            check_call(['pulumi', 'plugin', 'install', 'resource', 'crd', PLUGIN_VERSION])

so it is trying to installl plugin which does not exists. But I'm not sure how to fix it

goolzerg avatar Oct 27 '22 18:10 goolzerg

During installation I get this error image For some reason it goes to https://get.pulumi.com/releases/plugins/ and trying to download a plugin which does not exists obviously

goolzerg avatar Oct 28 '22 08:10 goolzerg

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

cleverguy25 avatar Aug 09 '24 23:08 cleverguy25