crd2pulumi icon indicating copy to clipboard operation
crd2pulumi copied to clipboard

Missing import and attribute in .NET generated code

Open alexeyzimarev opened this issue 4 years ago • 4 comments

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 avatar Jul 02 '21 08:07 alexeyzimarev

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.

nwrox avatar Jul 06 '21 11:07 nwrox

Possibly related to https://github.com/pulumi/crd2pulumi/issues/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?

lukehoban avatar Jul 07 '21 19:07 lukehoban

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.

nwrox avatar Jul 09 '21 02:07 nwrox

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)
    {
    }
}

madsbacha avatar Sep 15 '21 09:09 madsbacha

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

cleverguy25 avatar Aug 09 '24 23:08 cleverguy25