Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't Import Two Generated Typescript Class that Belong to the Same "Resource Module" #111

Closed
blaise-bradley opened this issue Apr 20, 2023 · 4 comments · Fixed by #143
Closed
Assignees
Labels
kind/bug Some behavior is incorrect or out of spec resolution/fixed This issue was fixed

Comments

@blaise-bradley
Copy link

What happened?

I’m trying to generate code for the IngressRoute and Middleware CRDs from the Traefik Helm Chart. Based on the usage described in the README, it seems like you can only point crd2pulumi to a single file. My approach has been to generate code for each CRD yml file and then move the generated code into separate directories. If I import just one of the generated classes, my program works as expected. When I import both of the generated classes into the same Pulumi program, the planning step fails with the following error:

    TypeError: Invalid Version:
        at new SemVer (/Users/blaisebradley/Code/rollout-embedded-poc/node_modules/@pulumi/pulumi/node_modules/semver/semver.js:332:11)
        at compare (/Users/blaisebradley/Code/rollout-embedded-poc/node_modules/@pulumi/pulumi/node_modules/semver/semver.js:647:10)
        at Object.eq (/Users/blaisebradley/Code/rollout-embedded-poc/node_modules/@pulumi/pulumi/node_modules/semver/semver.js:693:10)
        at sameVersion (/Users/blaisebradley/Code/rollout-embedded-poc/node_modules/@pulumi/runtime/rpc.ts:701:57)
        at register (/Users/blaisebradley/Code/rollout-embedded-poc/node_modules/@pulumi/runtime/rpc.ts:716:17)
        at Object.registerResourceModule (/Users/blaisebradley/Code/rollout-embedded-poc/node_modules/@pulumi/runtime/rpc.ts:810:5)
        at Object.<anonymous> (/Users/blaisebradley/Code/rollout-embedded-poc/pulumi-crd/helm/middlewares/traefik/v1alpha1/index.ts:25:16)
        at Module._compile (node:internal/modules/cjs/loader:1159:14)
        at Module.m._compile (/Users/blaisebradley/Code/rollout-embedded-poc/node_modules/@pulumi/pulumi/node_modules/ts-node/src/index.ts:439:23)
        at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)

My best guess is that there is some kind of conflict since we are trying to register the "resource module" traefik.containo.us/v1alpha1 twice with the same version number.

Expected Behavior

It's possible to import and use both classes in the same program.

Steps to reproduce

  1. Run crd2pulumi against two Traefik CRD files such as ingressroute.yaml and middlewares.yaml.

  2. Put the generated code in sibling directories. A screenshot of my directory structure is below:
    Screen Shot 2023-04-19 at 4 38 43 PM

  3. Import both classes in the same Pulumi program:

import { IngressRoute as TraefikIngressRoute } from "../pulumi-crd/traefik/ingress-route/traefik/v1alpha1";
import { Middleware as TraefikMiddleware } from "../pulumi-crd/traefik/middlewares/traefik/v1alpha1";
  1. Attempt to create an instance of each resource:
  const traefikMiddleware = new TraefikMiddleware(
      "traefik-dashboard-auth",
      {
        apiVersion: "traefik.containo.us/v1alpha1",
        kind: "Middleware",
        metadata: {
          name: "basic-auth",
          namespace: traefikNamespace.metadata.name,
        },
        spec: {
          basicAuth: { secret: traefikDashboardCreds.metadata.name },
        },
      },
      { provider: k8sProvider }
    );
    
  
    new TraefikIngressRoute(
      "traefik-dashboard-route",
      {
        metadata: {
          name: "dashboard",
          namespace: traefikNamespace.metadata.name,
        },
        spec: {
          entryPoints: ["web"],
          routes: [
            {
              match:
                "PathPrefix(`/dashboard`, `/dashboard/`) || PathPrefix(`/api`, `/api/`)",
              kind: "Rule",
              services: [{ name: "api@internal", kind: "TraefikService" }],
              middlewares: [
                {
                  name: traefikMiddleware.metadata.name as Output<string>,
                  namespace: traefikNamespace.metadata.name,
                },
              ],
            },
          ],
        },
      },
      { provider: k8sProvider }
  );

Output of pulumi about

CLI          
Version      3.60.1
Go Version   go1.20.2
Go Compiler  gc

Plugins
NAME    VERSION
nodejs  unknown
random  4.12.1

Host     
OS       darwin
Version  12.4
Arch     arm64

This project is written in nodejs: executable='/Users/blaisebradley/.nvm/versions/node/v18.12.1/bin/node' version='v18.12.1'

Backend        
Name           pulumi.com
URL            https://app.pulumi.com/blaiseb
User           blaiseb
Organizations  blaiseb, rollout

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

@blaise-bradley blaise-bradley added kind/bug Some behavior is incorrect or out of spec needs-triage Needs attention from the triage team labels Apr 20, 2023
@iwahbe
Copy link
Member

iwahbe commented Apr 24, 2023

Hi @blaise-bradley. Thanks for raising the issue.

As a work-around, I think you can change one of the generated packages to have a different name. This way Pulumi can distinguish between them and won't error because two modules with the same name and version were registered at the same time.

crd2pulumi wasn't design to generate side-by-side compatible packages. We will consider that for the future.

@iwahbe iwahbe removed the needs-triage Needs attention from the triage team label Apr 24, 2023
@cleverguy25
Copy link

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

@rquitales
Copy link
Member

crd2pulumi allows you to generate a single package from multiple input files. Usage example: crd2pulumi --go file1.yaml file2.yaml.

@pulumi-bot
Copy link

This issue has been addressed in PR #143 and shipped in release v1.5.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Some behavior is incorrect or out of spec resolution/fixed This issue was fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants