is there any way to more friendly way to use in cs...
# kubernetes
b
is there any way to more friendly way to use in csharp CustomResource? crd2pulumi not helping with simple ENIConfig
at first I fought that it is enought just to implement public class ENIConfigArgs : CustomResourceArgs
but it looks like I should implement CustomResource and it looks terrible
so I started with
Copy code
public class ENIConfigArgs : CustomResourceArgs
    {
        internal string Type { get => "kubernetes:<http://crd.k8s.amazonaws.com/v1:ENIConfig%22;|crd.k8s.amazonaws.com/v1:ENIConfig";> }
        
        [Input("spec")]
        public Input<ENIConfigSpecArgs> Spec { get; set; }

        public ENIConfigArgs(string apiVersion, string kind, Input<ENIConfigSpecArgs> spec) : base(apiVersion, kind)
        {
            Spec = spec;
        }

        
    }

    public class ENIConfigSpecArgs : ResourceArgs
    {
        [Input("securityGroups")]
        public InputList<string> SecurityGroups { get; set; }
        [Input("subnet")]
        public Input<string> Subnet { get; set; }

        public ENIConfigSpecArgs(InputList<string> securityGroups, Input<string> subnet)
        : base()
        {
            SecurityGroups = securityGroups;
            Subnet = subnet;
        }

        
    }
but I found to late what Kind and ApiVersion is immutable in CustomResourceArgs
I made it...
Copy code
public class ENIConfigArgs : CustomResourceArgs
    {
        
        [Input("spec")]
        public required Input<ENIConfigSpecArgs> Spec { get; init; }

        public ENIConfigArgs(string apiVersion, string kind) : base(apiVersion, kind)
        {
            
        }

        
    }

    public class ENIConfigSpecArgs : ResourceArgs
    {
        [Input("securityGroups")]
        public required InputList<string> SecurityGroups { get; set; }
        [Input("subnet")]
        public required Input<string> Subnet { get; set; }

        public ENIConfigSpecArgs()
        : base()
        {

        }
        
    }
Copy code
var eniConfig1 = new Kubernetes.ApiExtensions.CustomResource($"{settings.ClusterName}-zone-1",
                new ENIConfigArgs (
                    apiVersion: "<http://crd.k8s.amazonaws.com/v1alpha1|crd.k8s.amazonaws.com/v1alpha1>",
                    kind: "ENIConfig"
                ) {
                    Metadata = new Kubernetes.Types.Inputs.Meta.V1.ObjectMetaArgs {
                        Name = vpcIntance.Zone_1_name,
                    },
                    Spec = new ENIConfigSpecArgs {
                        SecurityGroups = new [] {
                            secgrEksPod.Id
                        },
                        Subnet = vpcIntance.Subnet_pod_1.Id
                    }
                },
                new CustomResourceOptions {
                    Provider = eksProvider,
                    Parent = eksComponent
                }
            );
🫠
m
Glad you figured it out, but sorry it was a bit of a journey to figure it out. If there are specific docs missing that would have helped, please file an issue for us to improve them!
h
crd2pulumi not helping with simple ENIConfig
i’m especially curious what went wrong here, did it not generate valid code for you? how did you invoke the tool?
b
@hallowed-photographer-31251 so I took crd from kube
Copy code
crd2pulumi --dotnetPath ./Pulumi.Eni --dotnetName Eni eniconfigs.yaml

cd aws-csharp
dotnet add reference ../Pulumi.Eni/Pulumi.Eni.csproj

cd ../Pulumi.Eni
dotnet build
Copy code
Pulumi.Eni/Crd/V1Alpha1/ENIConfigList.cs(28,70): error CS0234: The type or namespace name 'Crd' does not exist in the namespace 'Pulumi.Kubernetes.Types.Outputs' (are you missing an assembly reference?) [Pulumi.Eni/Pulumi.Eni.csproj]
Pulumi.Eni/Crd/V1Alpha1/ENIConfigList.cs(114,70): error CS0234: The type or namespace name 'ENIConfig' does not exist in the namespace 'Pulumi.Kubernetes.Types.Inputs.Crd.V1Alpha1' (are you missing an assembly reference?) [/home/admin_sav0/aws-cpweb-pulumi/Pulumi.Eni/Pulumi.Eni.csproj]
so probably most important it did not generate ENIConfig type only ENIConfigList