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

Missing import and attribute in .NET generated code #49

Closed
alexeyzimarev opened this issue Jul 2, 2021 · 6 comments · Fixed by #143
Closed

Missing import and attribute in .NET generated code #49

alexeyzimarev opened this issue Jul 2, 2021 · 6 comments · Fixed by #143
Assignees
Labels
area/codegen Affects quality or correctness of generated code kind/bug Some behavior is incorrect or out of spec resolution/fixed This issue was fixed

Comments

@alexeyzimarev
Copy link

When generating CRDs code for .NET the generated code has no import for the correct KubernetesResource base class, as well as using the CrdsResourceType attribute, which is nowhere to be found.

Steps to reproduce

  1. run ./crd2pulumi -d cert-manager.crds.yaml
  2. open the Pulumi.Crds.csproj project
  3. the project has errors in all the generated CDR code files

Expected: the generated project compiles
Actual: the generated project doesn't compile

Example:

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Threading.Tasks;
using Pulumi.Serialization;

namespace Pulumi.Crds.Certmanager.V1
{
    /// <summary>
    /// A Certificate resource should be created to ensure an up to date and signed x509 certificate is stored in the Kubernetes Secret resource named in `spec.secretName`.
    ///  The stored certificate will be renewed before it expires (as configured by `spec.renewBefore`).
    /// </summary>
    [CrdsResourceType("kubernetes:cert-manager.io/v1:Certificate")]
    public partial class Certificate : KubernetesResource
    {

In this file, the KubernetesResource is not resolved in any using namespace. Adding this:

using Pulumi.crds;

solves the issue, but it must be done in all the files.

Also, the CrdsResourceType attribute is not resolved, and I cannot find it anywhere.

@alexeyzimarev alexeyzimarev added the kind/bug Some behavior is incorrect or out of spec label Jul 2, 2021
@nwrox
Copy link

nwrox commented Jul 6, 2021

Same issue here, the code generated with the latest release in both linux and windows is missing the correct imports, CrdsResourceType and the Utilities class, even after importing the generated namespace, is conflicting with the namespace Pulumi.Utilities.

@lukehoban
Copy link

lukehoban commented Jul 7, 2021

Possibly related to #48?

the code generated with the latest release in both linux and windows is missing the correct imports

@nwrox Was this working previously for you and started not working with the latest release?

@nwrox
Copy link

nwrox commented Jul 9, 2021

Possibly related to #48?

the code generated with the latest release in both linux and windows is missing the correct imports

@nwrox Was this working previously for you and started not working with the latest release?

First time using the tool. I'm trying to convert the traefik crds (https://github.com/traefik/traefik/tree/master/docs/content/reference/dynamic-configuration/traefik.containo.us_*.yaml) and i got the following errors:

Missing import (^1.0.5)

missing_import

Namespace conflict (^1.0.5)

namespace_conflict

Stop the conflict if edited manually:
namespace_conflict_fix

Missing reference (^1.0.6)

missing_ref_intro_v1-0-6

This last one i couldn't find a reference anywhere in pulumi's organization.

@madsbacha
Copy link
Contributor

I had the same problem. I fixed it by adding the flag --dotnetName Crds to the command ./crd2pulumi -d --dotnetName Crds cert-manager.crds.yaml. This changes the namespace from Pulumi.crds to Pulumi.Crds in both KubernetesResource.cs and Utilities.cs. This fixes all namespace errors regarding KubernetesResource and the Version from the Utilities class.

The missing CrdsResourceType is because of a temporary fix here.
I added the following class after the Utilities class in the file Utilities.cs to fix the issue. The following class is a snippet from the template from the main pulumi repository which is missing from the temporary fix in this repository.

internal sealed class CrdsResourceTypeAttribute : Pulumi.ResourceTypeAttribute
{
    public CrdsResourceTypeAttribute(string type) : base(type, Utilities.Version)
    {
    }
}

@mattolenik mattolenik added the area/codegen Affects quality or correctness of generated code label Jun 2, 2022
@cleverguy25
Copy link

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

@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
area/codegen Affects quality or correctness of generated code 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.

8 participants